Update app.py
Browse files
app.py
CHANGED
|
@@ -150,6 +150,32 @@ load_css()
|
|
| 150 |
# --- 3. DATA & MODEL LOADING FUNCTIONS (WITH CACHING) ---
|
| 151 |
# Checklist Items 1 & 2: Cache all heavy operations
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
@st.cache_resource
|
| 154 |
def load_hourly_aggregate_model():
|
| 155 |
"""Tải mô hình Daily Champion (Hourly Aggregate) cho metric T+24h."""
|
|
@@ -282,7 +308,7 @@ HOURLY_TARGET_COLS = ['target_temp_next_24h', 'target_temp_next_48h', 'target_te
|
|
| 282 |
'target_temp_next_96h', 'target_temp_next_120h']
|
| 283 |
|
| 284 |
# Load models và data mới
|
| 285 |
-
hourly_data_df = load_hourly_data(file_path="data/final_hourly_feature_dataset") # Dùng tên file features demo
|
| 286 |
hourly_models_24h = load_24_hourly_models() # Dùng 24 mô hình LGBM
|
| 287 |
hourly_agg_model = load_hourly_aggregate_model() # Dùng mô hình Aggregate T+24h
|
| 288 |
|
|
|
|
| 150 |
# --- 3. DATA & MODEL LOADING FUNCTIONS (WITH CACHING) ---
|
| 151 |
# Checklist Items 1 & 2: Cache all heavy operations
|
| 152 |
|
| 153 |
+
@st.cache_datadef load_hourly_data(file_path="data/final_hourly_feature_dataset.csv"):
|
| 154 |
+
"""Loads the Hourly Direct dataset using the provided demo file."""
|
| 155 |
+
try:
|
| 156 |
+
# Tải file features hourly từ thư mục 'data/'
|
| 157 |
+
df_hourly = pd.read_csv(file_path)
|
| 158 |
+
|
| 159 |
+
# --- Xử lý Cột Ngày Giờ (CRITICAL CUSTOMIZATION) ---
|
| 160 |
+
DATE_COLUMN = 'datetime'
|
| 161 |
+
|
| 162 |
+
if DATE_COLUMN not in df_hourly.columns:
|
| 163 |
+
st.error(f"Error: Date column '{DATE_COLUMN}' not found in hourly data CSV. Please check the column name.")
|
| 164 |
+
return pd.DataFrame()
|
| 165 |
+
|
| 166 |
+
# Chuyển cột 'datetime' sang định dạng datetime và đặt làm index
|
| 167 |
+
df_hourly[DATE_COLUMN] = pd.to_datetime(df_hourly[DATE_COLUMN])
|
| 168 |
+
df_hourly = df_hourly.set_index(DATE_COLUMN)
|
| 169 |
+
df_hourly = df_hourly.sort_index()
|
| 170 |
+
return df_hourly
|
| 171 |
+
|
| 172 |
+
except FileNotFoundError:
|
| 173 |
+
st.error(f"ERROR: Hourly data file not found at: {file_path}. Please check the path and file name.")
|
| 174 |
+
return pd.DataFrame()
|
| 175 |
+
except Exception as e:
|
| 176 |
+
st.error(f"An unexpected error occurred while loading hourly data: {e}")
|
| 177 |
+
return pd.DataFrame()
|
| 178 |
+
|
| 179 |
@st.cache_resource
|
| 180 |
def load_hourly_aggregate_model():
|
| 181 |
"""Tải mô hình Daily Champion (Hourly Aggregate) cho metric T+24h."""
|
|
|
|
| 308 |
'target_temp_next_96h', 'target_temp_next_120h']
|
| 309 |
|
| 310 |
# Load models và data mới
|
| 311 |
+
hourly_data_df = load_hourly_data(file_path="data/final_hourly_feature_dataset.csv") # Dùng tên file features demo
|
| 312 |
hourly_models_24h = load_24_hourly_models() # Dùng 24 mô hình LGBM
|
| 313 |
hourly_agg_model = load_hourly_aggregate_model() # Dùng mô hình Aggregate T+24h
|
| 314 |
|