reduce duplicated code

This commit is contained in:
robcaulk 2023-03-25 13:27:41 +01:00
parent b383654378
commit 630cdcb99f

View File

@ -169,11 +169,7 @@ class FreqaiDataDrawer:
if exists: if exists:
try: try:
for file_path in self.historic_predictions_folder.glob("*.parquet"): self.load_historic_predictions_from_folder()
key = file_path.stem
key.replace("_", "/")
self.historic_predictions[key] = pd.read_parquet(file_path)
logger.info( logger.info(
f"Found existing historic predictions at {self.full_path}, but beware " f"Found existing historic predictions at {self.full_path}, but beware "
"that statistics may be inaccurate if the bot has been offline for " "that statistics may be inaccurate if the bot has been offline for "
@ -182,10 +178,7 @@ class FreqaiDataDrawer:
except EOFError: except EOFError:
logger.warning( logger.warning(
'Historical prediction files were corrupted. Trying to load backup files.') 'Historical prediction files were corrupted. Trying to load backup files.')
for file_path in self.historic_predictions_folder.glob("*.parquet"): self.load_historic_predictions_from_folder()
key = file_path.stem
key.replace("_", "/")
self.historic_predictions[key] = pd.read_parquet(file_path)
logger.warning('FreqAI successfully loaded the backup ' logger.warning('FreqAI successfully loaded the backup '
'historical predictions files.') 'historical predictions files.')
@ -205,6 +198,18 @@ class FreqaiDataDrawer:
return exists return exists
def load_historic_predictions_from_folder(self):
"""
Try to build the historic_predictions dictionary from parquet
files in the historic_predictions_folder
"""
for file_path in self.historic_predictions_folder.glob("*.parquet"):
key = file_path.stem
key.replace("_", "/")
self.historic_predictions[key] = pd.read_parquet(file_path)
return
def save_historic_predictions_to_disk(self): def save_historic_predictions_to_disk(self):
""" """
Save historic predictions pickle to disk Save historic predictions pickle to disk