Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -790,28 +790,38 @@ with tab4:
|
|
| 790 |
st.info(f"The model runs based on data up to the latest known hour: **{latest_time_for_day.strftime('%Y-%m-%d %H:%M:%S')}**")
|
| 791 |
st.divider()
|
| 792 |
|
| 793 |
-
#
|
| 794 |
predictions_24h = predict_next_24_hours(input_features_hourly, hourly_models_24h)
|
| 795 |
|
| 796 |
-
# --- TÍNH TOÁN METRIC T+24H CHÍNH XÁC ---
|
| 797 |
t_plus_24h_metric = None
|
| 798 |
-
|
| 799 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 800 |
try:
|
| 801 |
-
|
| 802 |
-
t_plus_24h_metric = hourly_agg_model.predict(input_features_hourly)[0]
|
| 803 |
except Exception as e:
|
| 804 |
-
#
|
| 805 |
-
st.error(f"Error predicting T+24h
|
| 806 |
-
|
| 807 |
-
|
|
|
|
| 808 |
st.subheader(f"Summary Forecast for Next Day (Starting {latest_time_for_day.strftime('%H:%M')})")
|
| 809 |
|
| 810 |
forecast_start_ts = latest_time_for_day + pd.Timedelta(hours=1)
|
| 811 |
|
| 812 |
col_daily_pred = st.columns(4)
|
| 813 |
with col_daily_pred[0]:
|
| 814 |
-
# Hiển thị T+24h (sử dụng model Aggregated thật
|
| 815 |
display_value = t_plus_24h_metric if t_plus_24h_metric is not None else predictions_24h[0]
|
| 816 |
st.metric(
|
| 817 |
label=f"Forecast @ {forecast_start_ts.strftime('%H:%M')} Tomorrow (Day 1 Agg.)",
|
|
|
|
| 790 |
st.info(f"The model runs based on data up to the latest known hour: **{latest_time_for_day.strftime('%Y-%m-%d %H:%M:%S')}**")
|
| 791 |
st.divider()
|
| 792 |
|
| 793 |
+
# 1. Chạy Dự đoán Hourly (cho biểu đồ T+1h đến T+24h)
|
| 794 |
predictions_24h = predict_next_24_hours(input_features_hourly, hourly_models_24h)
|
| 795 |
|
| 796 |
+
# --- TÍNH TOÁN METRIC T+24H CHÍNH XÁC (Dùng Daily Features) ---
|
| 797 |
t_plus_24h_metric = None
|
| 798 |
+
|
| 799 |
+
# Lấy ngày được chọn làm Timestamp
|
| 800 |
+
selected_date_ts = pd.Timestamp(selected_date)
|
| 801 |
+
|
| 802 |
+
# Lấy input features cho DAILY AGGREGATE MODEL từ X_test (Daily Features DataFrame)
|
| 803 |
+
input_features_daily_agg = pd.DataFrame()
|
| 804 |
+
if selected_date_ts in X_test.index:
|
| 805 |
+
# Lấy single row từ Daily Features (đã được aggregated)
|
| 806 |
+
input_features_daily_agg = X_test.loc[[selected_date_ts]]
|
| 807 |
+
|
| 808 |
+
if hourly_agg_model and not input_features_daily_agg.empty:
|
| 809 |
+
# CHẠY MODEL TRÊN INPUT DAILY FEATURES (1036 features)
|
| 810 |
try:
|
| 811 |
+
t_plus_24h_metric = hourly_agg_model.predict(input_features_daily_agg)[0]
|
|
|
|
| 812 |
except Exception as e:
|
| 813 |
+
# Bắt lỗi dự đoán và trả về cảnh báo nếu vẫn còn lỗi feature mismatch khác
|
| 814 |
+
st.error(f"Error predicting T+24h metric (Daily Agg. Model). Mismatch likely: {e}")
|
| 815 |
+
t_plus_24h_metric = None # Đảm bảo giá trị là None nếu lỗi
|
| 816 |
+
|
| 817 |
+
# 2. Hiển thị Dự đoán T+24h (Tức là giờ đó ngày mai)
|
| 818 |
st.subheader(f"Summary Forecast for Next Day (Starting {latest_time_for_day.strftime('%H:%M')})")
|
| 819 |
|
| 820 |
forecast_start_ts = latest_time_for_day + pd.Timedelta(hours=1)
|
| 821 |
|
| 822 |
col_daily_pred = st.columns(4)
|
| 823 |
with col_daily_pred[0]:
|
| 824 |
+
# Hiển thị T+24h (sử dụng model Aggregated thật)
|
| 825 |
display_value = t_plus_24h_metric if t_plus_24h_metric is not None else predictions_24h[0]
|
| 826 |
st.metric(
|
| 827 |
label=f"Forecast @ {forecast_start_ts.strftime('%H:%M')} Tomorrow (Day 1 Agg.)",
|