Skip to content

Commit

Permalink
Merge pull request #65 from gisce/fix_a5d_b5d_empty_fields
Browse files Browse the repository at this point in the history
Correcciones en la generación de ficheros A5D y B5D
  • Loading branch information
davidmunoznovoa authored Mar 27, 2024
2 parents 6eacf4a + 90729ec commit d7458b4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
7 changes: 2 additions & 5 deletions mesures/a5d.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ def total(self):
def ai(self):
return int(self.file['ai'].sum())

@property
def ae(self):
return int(self.file['ae'].sum())

@property
def cups(self):
return list(set(self.file['cups']))
Expand All @@ -89,7 +85,8 @@ def reader(self, filepath):
raise Exception("Filepath must be an str or a list")

df = df.groupby(['cups', 'timestamp', 'season', 'factura']).aggregate(
{'ai': 'sum', 'ae': 'sum'}
{'ai': 'sum', 'ae': 'sum',
'r1': 'sum', 'r2': 'sum', 'r3': 'sum', 'r4': 'sum'}
).reset_index()
df['timestamp'] = df['timestamp'].apply(lambda x: x.strftime('%Y/%m/%d %H:%M'))
for key in ['r1', 'r2', 'r3', 'r4', 'ae', 'method', 'firmeza']:
Expand Down
38 changes: 37 additions & 1 deletion mesures/b5d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from mesures.a5d import A5D
from mesures.dates import *
from mesures.headers import A5D_HEADER as COLUMNS
from mesures.parsers.dummy_data import DummyCurve
import pandas as pd


class B5D(A5D):
Expand All @@ -10,5 +14,37 @@ def __init__(self, data, distributor=None, comer=None, compression='bz2', versio
:param comer: str comer REE code
:param compression: 'bz2', 'gz'... OR False otherwise
"""
super(B5D, self).__init__(data, distributor=distributor, comer=comer, compression=compression, version=version)
if isinstance(data, list):
data = DummyCurve(data).curve_data
self.columns = COLUMNS
self.file = self.reader(data)
self.generation_date = datetime.now()
self.prefix = 'B5D'
self.default_compression = compression
self.version = version
self.distributor = distributor
self.comer = comer

@property
def ae(self):
return int(self.file['ae'].sum())

def reader(self, filepath):
if isinstance(filepath, str):
df = pd.read_csv(
filepath, sep=';', names=self.columns
)
elif isinstance(filepath, list):
df = pd.DataFrame(data=filepath)
else:
raise Exception("Filepath must be an str or a list")

df = df.groupby(['cups', 'timestamp', 'season', 'factura']).aggregate(
{'ai': 'sum', 'ae': 'sum',
'r1': 'sum', 'r2': 'sum', 'r3': 'sum', 'r4': 'sum'}
).reset_index()
df['timestamp'] = df['timestamp'].apply(lambda x: x.strftime('%Y/%m/%d %H:%M'))
for key in ['method', 'firmeza']:
df[key] = ''
df = df[self.columns]
return df
2 changes: 1 addition & 1 deletion spec/generation_files_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def get_sample_cups45_data():
f1 = f.writer()
assert isinstance(f1, str)

with fdescription('A P2D'):
with description('A P2D'):
with it('is instance of P2D Class'):
data = SampleData().get_sample_p2d_data()
f = P2D(data)
Expand Down

0 comments on commit d7458b4

Please sign in to comment.