Skip to content

Commit

Permalink
Force integer P2D magns
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmunoznovoa committed Mar 26, 2024
1 parent b0ce0a5 commit 74e1f1d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
40 changes: 40 additions & 0 deletions mesures/p2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mesures.utils import check_line_terminator_param
from zipfile import ZipFile
import os
import pandas as pd


class P2D(P2):
Expand Down Expand Up @@ -41,6 +42,45 @@ def zip_filename(self):
version=self.version
)

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['tipo_medida'] = 11
df.groupby(
['cups', 'tipo_medida', 'timestamp', 'season', 'method']
).aggregate(
{'ai': 'sum',
'ae': 'sum',
'r1': 'sum',
'r2': 'sum',
'r3': 'sum',
'r4': 'sum'}
)

df['timestamp'] = df['timestamp'].apply(lambda x: x.strftime(DATETIME_MASK))

df['method'] = 1
df['res'] = 0
df['res2'] = 0

df['ai'] = df['ai'].astype('int')
df['ae'] = df['ae'].astype('int')
df['r1'] = df['r1'].astype('int')
df['r2'] = df['r2'].astype('int')
df['r3'] = df['r3'].astype('int')
df['r4'] = df['r4'].astype('int')

for key in self.columns:
if 'quality' in key and key not in df:
df[key] = 0
df = df[self.columns]
return df

def writer(self):
"""
P2D contains all curve measure in one file
Expand Down
15 changes: 8 additions & 7 deletions spec/generation_files_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import numpy as np
import zipfile

DELETE_FILES = 'rm -rf *.bz2 *.zip *.[0123456789]'

class SampleData:
@staticmethod
Expand Down Expand Up @@ -118,10 +119,10 @@ def get_sample_p2d_data():

data_p2d = [basic_p2d.copy()]

ts = "2022-01-01 01:00:00"
for x in range(50):
ts = "2022-01-01 00:15:00"
for x in range(360):
datas = basic_p2d.copy()
ts = (datetime.strptime(ts, '%Y-%m-%d %H:%M:%S') + timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')
ts = (datetime.strptime(ts, '%Y-%m-%d %H:%M:%S') + timedelta(minutes=15)).strftime('%Y-%m-%d %H:%M:%S')
ai = randint(0, 5000)
ae = randint(0, 2)
r1 = randint(0, 30)
Expand All @@ -132,10 +133,10 @@ def get_sample_p2d_data():
data_p2d.append(datas)

cups = "ES0012345678923456780F"
ts = "2022-01-01 00:00:00"
for x in range(70):
ts = "2022-01-01 00:15:00"
for x in range(360):
datas = basic_p2d.copy()
ts = (datetime.strptime(ts, '%Y-%m-%d %H:%M:%S') + timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')
ts = (datetime.strptime(ts, '%Y-%m-%d %H:%M:%S') + timedelta(minutes=15)).strftime('%Y-%m-%d %H:%M:%S')
ai = randint(0, 5000)
ae = randint(0, 2)
r1 = randint(0, 30)
Expand Down Expand Up @@ -903,7 +904,7 @@ def get_sample_cups45_data():
f1 = f.writer()
assert isinstance(f1, str)

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

0 comments on commit 74e1f1d

Please sign in to comment.