Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcciones en la generación de ficheros A5D y B5D #65

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading