improve code
Browse files
data.py
CHANGED
|
@@ -170,11 +170,17 @@ def get_available_dates() -> List[str]:
|
|
| 170 |
common_dates = sorted(amd_dates.intersection(nvidia_dates), reverse=True)
|
| 171 |
logger.info(f"Common dates: {len(common_dates)} dates where both AMD and NVIDIA have data")
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
except Exception as e:
|
| 176 |
logger.error(f"Error getting available dates: {e}")
|
| 177 |
-
return
|
| 178 |
|
| 179 |
|
| 180 |
def get_data_for_date(target_date: str) -> tuple[pd.DataFrame, str]:
|
|
@@ -507,7 +513,8 @@ class CIResults:
|
|
| 507 |
self.sample_data = True
|
| 508 |
new_df, latest_update_msg = get_sample_data()
|
| 509 |
self.latest_update_msg = latest_update_msg
|
| 510 |
-
|
|
|
|
| 511 |
|
| 512 |
# Update attributes
|
| 513 |
self.df = new_df
|
|
@@ -537,8 +544,9 @@ class CIResults:
|
|
| 537 |
"""Load all available historical data at startup."""
|
| 538 |
try:
|
| 539 |
if not self.available_dates:
|
| 540 |
-
|
| 541 |
-
|
|
|
|
| 542 |
|
| 543 |
logger.info(f"Loading all historical data for {len(self.available_dates)} dates...")
|
| 544 |
start_date, end_date = self.available_dates[-1], self.available_dates[0]
|
|
|
|
| 170 |
common_dates = sorted(amd_dates.intersection(nvidia_dates), reverse=True)
|
| 171 |
logger.info(f"Common dates: {len(common_dates)} dates where both AMD and NVIDIA have data")
|
| 172 |
|
| 173 |
+
if common_dates:
|
| 174 |
+
return common_dates[:30] # Limit to last 30 days
|
| 175 |
+
|
| 176 |
+
# No real dates available - log warning and return empty list
|
| 177 |
+
# This will allow the system to fall back to sample data properly
|
| 178 |
+
logger.warning("No common dates found between AMD and NVIDIA datasets")
|
| 179 |
+
return []
|
| 180 |
|
| 181 |
except Exception as e:
|
| 182 |
logger.error(f"Error getting available dates: {e}")
|
| 183 |
+
return []
|
| 184 |
|
| 185 |
|
| 186 |
def get_data_for_date(target_date: str) -> tuple[pd.DataFrame, str]:
|
|
|
|
| 513 |
self.sample_data = True
|
| 514 |
new_df, latest_update_msg = get_sample_data()
|
| 515 |
self.latest_update_msg = latest_update_msg
|
| 516 |
+
# Generate fake dates for sample data historical functionality
|
| 517 |
+
self.available_dates = generate_fake_dates()
|
| 518 |
|
| 519 |
# Update attributes
|
| 520 |
self.df = new_df
|
|
|
|
| 544 |
"""Load all available historical data at startup."""
|
| 545 |
try:
|
| 546 |
if not self.available_dates:
|
| 547 |
+
logger.warning("No available dates found, skipping historical data load")
|
| 548 |
+
self.all_historical_data = pd.DataFrame()
|
| 549 |
+
return
|
| 550 |
|
| 551 |
logger.info(f"Loading all historical data for {len(self.available_dates)} dates...")
|
| 552 |
start_date, end_date = self.available_dates[-1], self.available_dates[0]
|