diff --git a/mesures/a5d.py b/mesures/a5d.py index a909997..74bdf85 100644 --- a/mesures/a5d.py +++ b/mesures/a5d.py @@ -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'])) @@ -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']: diff --git a/mesures/b5d.py b/mesures/b5d.py index 2b9eb2a..2bd95d2 100644 --- a/mesures/b5d.py +++ b/mesures/b5d.py @@ -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): @@ -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 diff --git a/spec/generation_files_spec.py b/spec/generation_files_spec.py index ce69bfd..5a71de2 100644 --- a/spec/generation_files_spec.py +++ b/spec/generation_files_spec.py @@ -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)