Skip to content
Open
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
9 changes: 6 additions & 3 deletions OMIEData/DataImport/omie_data_importer_from_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ def __init__(self,
self.date_end = date_end

def read_to_dataframe(self, verbose=False) -> pd.DataFrame:

df = pd.DataFrame(columns=self.fileReader.get_keys())
df = None
for response in self.fileDownloader.url_responses(date_ini=self.date_ini,
date_end=self.date_end,
verbose=verbose):
try:
df = pd.concat([df, self.fileReader.get_data_from_response(response=response)], ignore_index=True)
response_df = self.fileReader.get_data_from_response(response=response)
if df is not None:
df = pd.concat([df, response_df], ignore_index=True)
else:
df = response_df

except Exception as exc:
print('There was error processing file: ' + response.url)
Expand Down
22 changes: 15 additions & 7 deletions OMIEData/FileReaders/marginal_price_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MarginalPriceFileReader(OMIEFileReader):
__key_list_retrieve__ = ['DATE', 'CONCEPT',
'H1', 'H2', 'H3', 'H4','H5', 'H6','H7', 'H8','H9','H10',
'H11', 'H12','H13', 'H14','H15', 'H16','H17', 'H18','H19','H20',
'H21', 'H22','H23', 'H24', "H25"]
'H21', 'H22','H23', 'H24']

__dateFormatInFile__ = '%d/%m/%Y'
__localeInFile__ = "en_DK.UTF-8"
Expand All @@ -50,7 +50,7 @@ def get_keys(self):

def get_data_from_response(self, response: Response) -> pd.DataFrame:

res = pd.DataFrame(columns=self.get_keys())
res = None

# from first line we get the units and the price date. We just look at the date
lines = response.text.split("\n")
Expand All @@ -76,15 +76,19 @@ def get_data_from_response(self, response: Response) -> pd.DataFrame:
if concept_type in self.conceptsToLoad:
units = MarginalPriceFileReader.__dic_static_concepts__[first_col][1]

dico = self._process_line(date=date, concept=concept_type, values=splits[1:], multiplier=units)
res = pd.concat([res, pd.DataFrame([dico])], ignore_index=True)
dico = self._process_line(date=date, concept=concept_type, values=splits[1:-1], multiplier=units)
dico_df = pd.DataFrame([dico])
if res is not None:
res = pd.concat([res, dico_df], ignore_index=True)
else:
res = dico_df

return res

def get_data_from_file(self, filename: str) -> pd.DataFrame:

# Method yield each dictionary one by one
res = pd.DataFrame(columns=self.get_keys())
res = None
file = open(filename, 'r', encoding='latin-1')

# from first line we get the units and the price date. We just look at the date
Expand All @@ -108,8 +112,12 @@ def get_data_from_file(self, filename: str) -> pd.DataFrame:

if concept_type in self.conceptsToLoad:
units = MarginalPriceFileReader.__dic_static_concepts__[first_col][1]
dico = self._process_line(date=date, concept=concept_type, values=splits[1:], multiplier=units)
res = pd.concat([res, pd.DataFrame([dico])], ignore_index=True)
dico = self._process_line(date=date, concept=concept_type, values=splits[1:-1], multiplier=units)
dico_df = pd.DataFrame([dico])
if res is not None:
res = pd.concat([res, dico_df], ignore_index=True)
else:
res = dico_df

return res

Expand Down
2 changes: 1 addition & 1 deletion tests/filereaders_tests/marginal_pricer_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def run_all_tests():
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)
for test_func in [test_functions]:
for test_func in test_functions:
try:
test_func()
except (AssertionError, UnicodeDecodeError, TypeError, IndexError) as e:
Expand Down