Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -217,16 +217,19 @@ async def get_historical_data():
|
|
| 217 |
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
| 218 |
df = df.sort_values('timestamp')
|
| 219 |
|
| 220 |
-
#
|
| 221 |
-
|
| 222 |
-
df_filtered = df[df['timestamp'] >= cutoff_time]
|
| 223 |
|
| 224 |
-
logger.info(f"
|
| 225 |
|
| 226 |
-
#
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
# Prepare data for Chart.js line chart
|
| 232 |
historical_data = {}
|
|
@@ -249,11 +252,21 @@ async def get_historical_data():
|
|
| 249 |
|
| 250 |
logger.info(f"Returning {total_data_points} total data points across {len([p for p in historical_data.values() if p])} providers")
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
return {
|
| 253 |
"historical_data": historical_data,
|
| 254 |
"last_updated": datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 255 |
"total_data_points": total_data_points,
|
| 256 |
-
"data_range":
|
|
|
|
|
|
|
| 257 |
}
|
| 258 |
|
| 259 |
except Exception as e:
|
|
|
|
| 217 |
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
| 218 |
df = df.sort_values('timestamp')
|
| 219 |
|
| 220 |
+
# Use all available data to show full historical range
|
| 221 |
+
df_filtered = df.copy()
|
|
|
|
| 222 |
|
| 223 |
+
logger.info(f"Using all {len(df_filtered)} records for full historical view")
|
| 224 |
|
| 225 |
+
# For performance, limit to reasonable number of points per provider
|
| 226 |
+
max_points_per_provider = 500
|
| 227 |
+
if len(df_filtered) > max_points_per_provider * len(PROVIDERS):
|
| 228 |
+
# Sample data to keep it manageable while preserving time range
|
| 229 |
+
df_filtered = df_filtered.groupby('provider').apply(
|
| 230 |
+
lambda x: x.iloc[::max(1, len(x) // max_points_per_provider)]
|
| 231 |
+
).reset_index(drop=True)
|
| 232 |
+
logger.info(f"Sampled down to {len(df_filtered)} records for performance")
|
| 233 |
|
| 234 |
# Prepare data for Chart.js line chart
|
| 235 |
historical_data = {}
|
|
|
|
| 252 |
|
| 253 |
logger.info(f"Returning {total_data_points} total data points across {len([p for p in historical_data.values() if p])} providers")
|
| 254 |
|
| 255 |
+
# Calculate date range for display
|
| 256 |
+
if not df_filtered.empty:
|
| 257 |
+
earliest_date = df_filtered['timestamp'].min().strftime('%Y-%m-%d %H:%M')
|
| 258 |
+
latest_date = df_filtered['timestamp'].max().strftime('%Y-%m-%d %H:%M')
|
| 259 |
+
date_range = f"From {earliest_date} to {latest_date}"
|
| 260 |
+
else:
|
| 261 |
+
date_range = "No data"
|
| 262 |
+
|
| 263 |
return {
|
| 264 |
"historical_data": historical_data,
|
| 265 |
"last_updated": datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 266 |
"total_data_points": total_data_points,
|
| 267 |
+
"data_range": date_range,
|
| 268 |
+
"earliest_date": df_filtered['timestamp'].min().isoformat() if not df_filtered.empty else None,
|
| 269 |
+
"latest_date": df_filtered['timestamp'].max().isoformat() if not df_filtered.empty else None
|
| 270 |
}
|
| 271 |
|
| 272 |
except Exception as e:
|