From 630cdcb99fe9f678a136fa60acd2c4432c8879df Mon Sep 17 00:00:00 2001 From: robcaulk Date: Sat, 25 Mar 2023 13:27:41 +0100 Subject: [PATCH] reduce duplicated code --- freqtrade/freqai/data_drawer.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/freqtrade/freqai/data_drawer.py b/freqtrade/freqai/data_drawer.py index 397e8912f..cfed65771 100644 --- a/freqtrade/freqai/data_drawer.py +++ b/freqtrade/freqai/data_drawer.py @@ -169,11 +169,7 @@ class FreqaiDataDrawer: if exists: try: - 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) - + self.load_historic_predictions_from_folder() logger.info( f"Found existing historic predictions at {self.full_path}, but beware " "that statistics may be inaccurate if the bot has been offline for " @@ -182,10 +178,7 @@ class FreqaiDataDrawer: except EOFError: logger.warning( 'Historical prediction files were corrupted. Trying to load backup files.') - 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) + self.load_historic_predictions_from_folder() logger.warning('FreqAI successfully loaded the backup ' 'historical predictions files.') @@ -205,6 +198,18 @@ class FreqaiDataDrawer: 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): """ Save historic predictions pickle to disk