Skip to content

Commit

Permalink
Merge pull request #72 from gisce/gen_reobjecil
Browse files Browse the repository at this point in the history
Añadir soporte para REOBJECIL
  • Loading branch information
davidmunoznovoa authored Aug 1, 2024
2 parents 87eb1e9 + ba3c413 commit 0fd2be6
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
- `PMEST`
- `POTELECTRO`
- `REOBJE2`
- `REOBJECIL`
- `REOBJEAGRECL`
- `REOBJEINCL`
18 changes: 18 additions & 0 deletions mesures/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,21 @@
'comentari_receptor', # str(255)
'magnitud' # str(2) AS/AE
]

REOBJECIL_HEADER = [
'cil', # str(22)
'data_inici', # str aaaammdd hh
'data_fi', # str aaaammdd hh
'motiu_emissor', # str(3)
'as_publicada', # str(10) kWh
'as_proposada', # str(10) kWh
'r2_publicada', # str(10) kVArh
'r2_proposada', # str(10) kVArh
'r3_publicada', # str(10) kVArh
'r3_proposada', # str(10) kVArh
'comentari_emissor', # str(255)
'auto_obj', # str(1) S/N
'acceptacio', # str(1) S/N
'motiu_receptor', # str(2)
'comentari_receptor' # str(255)
]
36 changes: 36 additions & 0 deletions mesures/reobjecil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from mesures.headers import REOBJECIL_HEADER as COLUMNS
from mesures.reobjeagrecl import REOBJEAGRECL

import pandas as pd


class REOBJECIL(REOBJEAGRECL):
def __init__(self, data, distributor=None, comer=None, periode=None, compression='bz2', columns=COLUMNS, version=0):
"""
:param data: list of dicts or absolute file_path
:param distributor: str distributor REE code
:param compression: 'bz2', 'gz'... OR False otherwise
"""
super(REOBJECIL, self).__init__(data, distributor=distributor, comer=comer, periode=periode,
compression=compression, columns=COLUMNS, version=version)
self.prefix = 'REOBJECIL'

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

df['comentari_emissor'] = df.apply(lambda row: row['comentari_emissor'] or '', axis=1)
df['comentari_receptor'] = df.apply(lambda row: row['comentari_receptor'] or '', axis=1)
df['as_publicada'] = df.apply(lambda row: row['as_publicada'] or '', axis=1)
df['as_proposada'] = df.apply(lambda row: row['as_proposada'] or '', axis=1)
df['r2_publicada'] = df.apply(lambda row: row['r2_publicada'] or '', axis=1)
df['r2_proposada'] = df.apply(lambda row: row['r2_proposada'] or '', axis=1)
df['r3_publicada'] = df.apply(lambda row: row['r3_publicada'] or '', axis=1)
df['r3_proposada'] = df.apply(lambda row: row['r3_proposada'] or '', axis=1)

return df
44 changes: 44 additions & 0 deletions spec/generation_files_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from mesures.p5d import P5D
from mesures.potelectro import POTELECTRO
from mesures.reobje2 import REOBJE2
from mesures.reobjecil import REOBJECIL
from mesures.reobjeagrecl import REOBJEAGRECL
from mesures.reobjeincl import REOBJEINCL
from random import randint
Expand Down Expand Up @@ -794,6 +795,34 @@ def get_sample_reobje2_data():
'magnitud': 'AE'
}]

@staticmethod
def get_sample_reobjecil_data():
return [{
'cil': 'ES0291000000004444QR1F',
'data_inici': '2024/01/01 01',
'data_fi': '2024/02/01 00',
'motiu_emissor': '100',
'as_publicada': '100',
'as_proposada': '110',
'r2_publicada': '100',
'r2_proposada': '110',
'r3_publicada': '100',
'r3_proposada': '110',
'comentari_emissor': 'Paga la energia, primer aviso.',
'auto_obj': 'N',
'acceptacio': 'N',
'motiu_receptor': '99',
'comentari_receptor': 'La energia está correcta. A llorar a la llorería.',
},
{
'cil': 'ES0291000000004444QR1F',
'data_inici': '2024/01/01 01',
'data_fi': '2024/02/01 00',
'motiu_emissor': '100',
'auto_obj': 'N',
'acceptacio': 'N',
}]


with description('A P5D'):
with it('is instance of P5D Class'):
Expand Down Expand Up @@ -1407,3 +1436,18 @@ def get_sample_reobje2_data():
"primer aviso.;N;N;2;La energia está correcta. A llorar a la llorería.;AE\n"
)
assert f.file[f.columns].to_csv(sep=';', header=None, index=False) == expected

with description('A REOBJECIL'):
with it('is instance of REOBJECIL Class'):
data = SampleData().get_sample_reobjecil_data()
f = REOBJECIL(data)
assert isinstance(f, REOBJECIL)

with it('gets expected content'):
data = SampleData().get_sample_reobjecil_data()
f = REOBJECIL(data)
res = f.writer()
expected = ("ES0291000000004444QR1F;2024/01/01 01;2024/02/01 00;100;100;110;100;110;100;110;"
"Paga la energia, primer aviso.;N;N;99;La energia está correcta. A llorar a la llorería.\n"
"ES0291000000004444QR1F;2024/01/01 01;2024/02/01 00;100;;;;;;;;N;N;;\n")
assert f.file[f.columns].to_csv(sep=';', header=None, index=False) == expected

0 comments on commit 0fd2be6

Please sign in to comment.