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

Ajustes en la generación de ficheros CUPSDAT (ISP Noviembre 2024) #76

Merged
merged 2 commits into from
Oct 2, 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
15 changes: 13 additions & 2 deletions mesures/cupsdat.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# -*- coding: utf-8 -*-
from mesures.dates import *
from mesures.headers import CUPSDAT_HEADER as COLUMNS
from mesures.headers import CUPSDAT_HEADER as COLUMNS, CUPSDAT_HEADER_2024 as COLUMNS_2024
from mesures.parsers.dummy_data import DummyKeys
from mesures.utils import check_line_terminator_param
import os
import pandas as pd


class CUPSDAT(object):
def __init__(self, data, distributor=None, compression='bz2', columns=COLUMNS, version=0):
def __init__(self, data, distributor=None, compression='bz2', columns=COLUMNS, include_measure_type_indicator=False,
version=0):
"""
:param data: list of dicts or absolute file_path
:param distributor: str distributor REE code
:param compression: 'bz2', 'gz'... OR False otherwise
:param include_measure_type_indicator: boolean (indicates if new columns is included)
"""
data = DummyKeys(data).data
self.columns = columns
if include_measure_type_indicator:
self.columns = COLUMNS_2024
self.file = self.reader(data)
self.generation_date = datetime.now()
self.prefix = 'CUPSDAT'
Expand Down Expand Up @@ -70,6 +74,13 @@ def reader(self, file_path):
if row['fecha_hora_final_vigencia'] == ''
else datetime.strptime(row['fecha_hora_final_vigencia'], '%Y-%m-%d %H').strftime(DATE_MASK), axis=1)

# Patch indicador_tipo_medida if needed
if 'indicador_envio_medida' in self.columns:
df['indicador_envio_medida'] = df.apply(
lambda row: 'Q'
if row['tipo'] in ('1', '2') or not row.get('indicador_envio_medida', False)
else row['indicador_envio_medida'], axis=1)

return df[self.columns]

def writer(self):
Expand Down
4 changes: 4 additions & 0 deletions mesures/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
'tension' # str(2)
]

CUPSDAT_HEADER_2024 = CUPSDAT_HEADER + [
'indicador_envio_medida' # str(1) in ('Q', 'H')
]

CUPSELECTRO_HEADER = [
'cups', # str(22)
'cif_empresa', # str(9)
Expand Down
21 changes: 21 additions & 0 deletions spec/generation_files_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ def get_sample_cupsdat_data():
'tension': '27'
}]

@staticmethod
def get_sample_cupsdat_data_isp_2024():
res = SampleData().get_sample_cupsdat_data()
res[0].update({'indicador_envio_medida': 'Q'})
return res

@staticmethod
def get_sample_cups45_data():
return [{
Expand Down Expand Up @@ -1294,6 +1300,21 @@ def get_sample_reobjecil_data():
'E2;6A;G0;A;GI;400;400;400;400;400;500;1091;2022/10/17 01;3000/01/01 00;17005;S;27\n'
assert f.file[f.columns].to_csv(sep=';', header=None, index=False) == expected

with it('has new field indicador_envio_medida if it is specified in function call'):
data = SampleData().get_sample_cupsdat_data_isp_2024()
f = CUPSDAT(data, include_measure_type_indicator=True)
assert 'indicador_envio_medida' in f.columns

with it('has its expected content when indicador_envio_medida is included'):
data = SampleData().get_sample_cupsdat_data_isp_2024()
f = CUPSDAT(data, include_measure_type_indicator=True)
res = f.writer()
expected = 'ES0291000000004444QR1F;CUPS de Demo 01;X0004444;4444;5555;2;' \
'E2;6A;G0;A;GI;400;400;400;400;400;500;1091;2022/10/01 01;2022/10/17 00;17005;S;27;Q\n' \
'ES0291000000005555QR1F;CUPS de Demo 02;X0005555;4444;5555;2;' \
'E2;6A;G0;A;GI;400;400;400;400;400;500;1091;2022/10/17 01;3000/01/01 00;17005;S;27;Q\n'
assert f.file[f.columns].to_csv(sep=';', header=None, index=False) == expected

with description('A CUPS45'):
with it('is instance of CUPS45 Class'):
data = SampleData().get_sample_cups45_data()
Expand Down
Loading