ror HF Staff badaoui HF Staff commited on
Commit
83692d8
·
verified ·
1 Parent(s): 463324d

Fix historical data not updating after automatic reloads (#9)

Browse files

- fix historical data updates (30401c0a62ad4d0ca69e642f4ab5c0faf2c23e27)


Co-authored-by: Abdennacer Badaoui <badaoui@users.noreply.huggingface.co>

Files changed (1) hide show
  1. data.py +13 -1
data.py CHANGED
@@ -560,6 +560,13 @@ class CIResults:
560
  # Load all historical data at startup
561
  self.load_all_historical_data()
562
 
 
 
 
 
 
 
 
563
  # Log and return distant load status
564
  logger.info(f"Data loaded successfully: {len(self.available_models)} models")
565
  logger.info(f"Models: {self.available_models[:5]}{'...' if len(self.available_models) > 5 else ''}")
@@ -578,7 +585,7 @@ class CIResults:
578
  logger.info(json.dumps(msg, indent=4))
579
 
580
  def load_all_historical_data(self) -> None:
581
- """Load all available historical data at startup."""
582
  try:
583
  if not self.available_dates:
584
  logger.warning("No available dates found, skipping historical data load")
@@ -587,8 +594,12 @@ class CIResults:
587
 
588
  logger.info(f"Loading all historical data for {len(self.available_dates)} dates...")
589
  start_date, end_date = self.available_dates[-1], self.available_dates[0]
 
590
  self.all_historical_data = get_historical_data(start_date, end_date, self.sample_data)
591
  logger.info(f"All historical data loaded: {len(self.all_historical_data)} records")
 
 
 
592
  except Exception as e:
593
  logger.error(f"Error loading all historical data: {e}")
594
  self.all_historical_data = pd.DataFrame()
@@ -639,3 +650,4 @@ class CIResults:
639
  timer.daemon = True
640
  timer.start()
641
  logger.info("Data auto-reload scheduled every 15 minutes")
 
 
560
  # Load all historical data at startup
561
  self.load_all_historical_data()
562
 
563
+ # Update historical_df with latest available dates after reload
564
+ if self.available_dates:
565
+ start_date_val = self.available_dates[-1] # Last date (oldest)
566
+ end_date_val = self.available_dates[0] # First date (newest)
567
+ self.load_historical_data(start_date_val, end_date_val)
568
+ logger.info(f"Updated historical_df with {len(self.historical_df)} records")
569
+
570
  # Log and return distant load status
571
  logger.info(f"Data loaded successfully: {len(self.available_models)} models")
572
  logger.info(f"Models: {self.available_models[:5]}{'...' if len(self.available_models) > 5 else ''}")
 
585
  logger.info(json.dumps(msg, indent=4))
586
 
587
  def load_all_historical_data(self) -> None:
588
+ """Load all available historical data. Replaces existing data to ensure latest dates are included."""
589
  try:
590
  if not self.available_dates:
591
  logger.warning("No available dates found, skipping historical data load")
 
594
 
595
  logger.info(f"Loading all historical data for {len(self.available_dates)} dates...")
596
  start_date, end_date = self.available_dates[-1], self.available_dates[0]
597
+ logger.info(f"Date range: {start_date} to {end_date}")
598
  self.all_historical_data = get_historical_data(start_date, end_date, self.sample_data)
599
  logger.info(f"All historical data loaded: {len(self.all_historical_data)} records")
600
+ if not self.all_historical_data.empty:
601
+ unique_dates = sorted(self.all_historical_data['date'].unique())
602
+ logger.info(f"Loaded dates: {unique_dates[0]} to {unique_dates[-1]} ({len(unique_dates)} unique dates)")
603
  except Exception as e:
604
  logger.error(f"Error loading all historical data: {e}")
605
  self.all_historical_data = pd.DataFrame()
 
650
  timer.daemon = True
651
  timer.start()
652
  logger.info("Data auto-reload scheduled every 15 minutes")
653
+