From 065510b400aacb5b9e462c1c58231d80581959fd Mon Sep 17 00:00:00 2001 From: davidmunoznovoa Date: Wed, 27 Mar 2024 12:32:46 +0100 Subject: [PATCH 1/2] Fixes in AB5D --- mesures/a5d.py | 7 ++----- mesures/b5d.py | 39 ++++++++++++++++++++++++++++++++++- spec/generation_files_spec.py | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) 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..7f2de5c 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,38 @@ 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): + import pudb; pu.db + 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) From 90729ec687ad3003b4711e1e0e60714dd4f37090 Mon Sep 17 00:00:00 2001 From: davidmunoznovoa Date: Wed, 27 Mar 2024 12:37:49 +0100 Subject: [PATCH 2/2] Remove pudb --- mesures/b5d.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mesures/b5d.py b/mesures/b5d.py index 7f2de5c..2bd95d2 100644 --- a/mesures/b5d.py +++ b/mesures/b5d.py @@ -30,7 +30,6 @@ def ae(self): return int(self.file['ae'].sum()) def reader(self, filepath): - import pudb; pu.db if isinstance(filepath, str): df = pd.read_csv( filepath, sep=';', names=self.columns