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

Modificar ficheros REOBJEX #68

Merged
merged 1 commit into from
Jun 12, 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
7 changes: 6 additions & 1 deletion mesures/reobjeagrecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ def reader(self, filepath):
raise Exception("Filepath must be an str or a list")

df['comentari_receptor'] = df.apply(lambda row: row['comentari_receptor'] or '', axis=1)
df['comentari_emissor'] = df.apply(lambda row: row['comentari_emissor'] or '', axis=1)
df['energia_publicada'] = df.apply(lambda row: row['energia_publicada'] or '', axis=1)
df['energia_proposada'] = df.apply(lambda row: row['energia_proposada'] or '', axis=1)

return df

def writer(self):
"""
REOBJEAGRECL contains hourly generation curves
REOBJEAGRECL TMP file generattion
:return: file path
"""
# Check and change value version of file
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f]
if versions:
self.version = max(versions) + 1

# Generate file path
file_path = os.path.join('/tmp', self.filename)

kwargs = {'sep': ';',
Expand All @@ -86,6 +89,8 @@ def writer(self):
if self.default_compression:
kwargs.update({'compression': self.default_compression})

# Convert dict data to csv file and save it to the file path generated
self.file.to_csv(file_path, **kwargs)

# Return location tmp file
return file_path
1 change: 1 addition & 0 deletions mesures/reobjeincl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def reader(self, 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['energia_entrant_publicada'] = df.apply(lambda row: row['energia_entrant_publicada'] or '', axis=1)
df['energia_entrant_proposada'] = df.apply(lambda row: row['energia_entrant_proposada'] or '', axis=1)
Expand Down
3 changes: 1 addition & 2 deletions spec/generation_files_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ def get_sample_reobjeagrecl_data():
'magnitud': 'AE',
'energia_publicada': '100',
'energia_proposada': '110',
'comentari_emissor': 'Paga la energia, primer aviso.',
'auto_obj': 'N',
'acceptacio': 'N',
'motiu_receptor': '2',
Expand Down Expand Up @@ -1343,7 +1342,7 @@ def get_sample_reobjeincl_data():
data = SampleData().get_sample_reobjeagrecl_data()
f = REOBJEAGRECL(data)
res = f.writer()
expected = "4444;5555;E0;2T;E3;05;HU;41;2024/01/01 01;2024/02/01 00;100;AE;100;110;Paga la energia, primer aviso.;N;N;2;La energia está correcta. A llorar a la llorería.\n" \
expected = "4444;5555;E0;2T;E3;05;HU;41;2024/01/01 01;2024/02/01 00;100;AE;100;110;;N;N;2;La energia está correcta. A llorar a la llorería.\n" \
"4444;6666;E0;2T;E3;05;HU;00;2024/01/01 01;2024/02/01 00;100;AE;40;50;Paga la energia, primer aviso.;N;S;1;\n"
assert f.file[f.columns].to_csv(sep=';', header=None, index=False) == expected

Expand Down
Loading