cheikhaidev-ui commited on
Commit
472a145
·
1 Parent(s): 09a6a42

fix(charts): weekly aggregation + contextual annotations

Browse files

- fix(temporal): replace random 1000-sample with weekly resample (reproducible, readable)
- fix(stats): add annotation on 18-22h peak (SENELEC context)
- fix(stats): add annotation on Dec/Feb anomaly (synthetic dataset limitation)

streamlit_app/app.py CHANGED
@@ -252,6 +252,7 @@ with tab3:
252
  height=350, margin=dict(t=10),
253
  )
254
  st.plotly_chart(fig_h, use_container_width=True)
 
255
  with col2:
256
  st.subheader("📅 Risque par Mois")
257
  by_month = df_hist.groupby('mois')['coupure'].mean() * 100
@@ -264,6 +265,7 @@ with tab3:
264
  ))
265
  fig_m.update_layout(xaxis_title="Mois", yaxis_title="Taux (%)", height=350, margin=dict(t=10))
266
  st.plotly_chart(fig_m, use_container_width=True)
 
267
 
268
  with tab4:
269
  st.header("📈 Historique")
 
252
  height=350, margin=dict(t=10),
253
  )
254
  st.plotly_chart(fig_h, use_container_width=True)
255
+ st.caption("⚡ Le pic 18-22h correspond aux heures de pointe du réseau SENELEC (données historiques)")
256
  with col2:
257
  st.subheader("📅 Risque par Mois")
258
  by_month = df_hist.groupby('mois')['coupure'].mean() * 100
 
265
  ))
266
  fig_m.update_layout(xaxis_title="Mois", yaxis_title="Taux (%)", height=350, margin=dict(t=10))
267
  st.plotly_chart(fig_m, use_container_width=True)
268
+ st.caption("ℹ️ Dataset synthétique 2023-2024 : les pics de Déc/Fév reflètent la distribution des données d'entraînement, pas nécessairement la saisonnalité réelle.")
269
 
270
  with tab4:
271
  st.header("📈 Historique")
streamlit_app/utils_simple.py CHANGED
@@ -199,28 +199,33 @@ def create_temporal_chart(df_hist, quartier_filter):
199
  if date_col is None:
200
  df['index_date'] = pd.date_range(start='2023-01-01', periods=len(df), freq='H')
201
  date_col = 'index_date'
202
- df[date_col] = pd.to_datetime(df[date_col])
203
  df = df.sort_values(date_col)
204
  if quartier_filter != "Tous" and 'quartier' in df.columns:
205
  df = df[df['quartier'] == quartier_filter]
206
- df_sample = df.sample(min(1000, len(df))).sort_values(date_col)
207
-
 
 
 
 
 
208
  fig = go.Figure()
209
- if 'conso_megawatt' in df_sample.columns:
210
  fig.add_trace(go.Scatter(
211
- x=df_sample[date_col], y=df_sample['conso_megawatt'],
212
  mode='lines', name='Consommation', line=dict(color='#00bcd4', width=1.5),
213
  fill='tozeroy', hovertemplate='<b>Conso</b><br>%{y:.0f} MW<extra></extra>'
214
  ))
215
- if 'temp_celsius' in df_sample.columns:
216
  fig.add_trace(go.Scatter(
217
- x=df_sample[date_col], y=df_sample['temp_celsius'],
218
  mode='lines', name='Température', line=dict(color='#ff5722', width=1.5, dash='dot'),
219
  yaxis='y2', hovertemplate='<b>Temp</b><br>%{y:.1f}°C<extra></extra>'
220
  ))
221
- title = f"Évolution - {quartier_filter}" if quartier_filter != "Tous" else "Évolution Historique"
222
  fig.update_layout(
223
- title=title, xaxis_title="Date",
224
  yaxis=dict(title="Consommation (MW)"),
225
  yaxis2=dict(title="Température (°C)", overlaying='y', side='right'),
226
  hovermode='x unified', height=500
 
199
  if date_col is None:
200
  df['index_date'] = pd.date_range(start='2023-01-01', periods=len(df), freq='H')
201
  date_col = 'index_date'
202
+ df[date_col] = pd.to_datetime(df[date_col], errors='coerce')
203
  df = df.sort_values(date_col)
204
  if quartier_filter != "Tous" and 'quartier' in df.columns:
205
  df = df[df['quartier'] == quartier_filter]
206
+ df_agg = (
207
+ df.set_index(date_col)
208
+ .resample('W')[['conso_megawatt', 'temp_celsius']]
209
+ .mean()
210
+ .reset_index()
211
+ )
212
+
213
  fig = go.Figure()
214
+ if 'conso_megawatt' in df_agg.columns:
215
  fig.add_trace(go.Scatter(
216
+ x=df_agg[date_col], y=df_agg['conso_megawatt'],
217
  mode='lines', name='Consommation', line=dict(color='#00bcd4', width=1.5),
218
  fill='tozeroy', hovertemplate='<b>Conso</b><br>%{y:.0f} MW<extra></extra>'
219
  ))
220
+ if 'temp_celsius' in df_agg.columns:
221
  fig.add_trace(go.Scatter(
222
+ x=df_agg[date_col], y=df_agg['temp_celsius'],
223
  mode='lines', name='Température', line=dict(color='#ff5722', width=1.5, dash='dot'),
224
  yaxis='y2', hovertemplate='<b>Temp</b><br>%{y:.1f}°C<extra></extra>'
225
  ))
226
+ title = f"Évolution Hebdomadaire — Consommation & Température ({quartier_filter})" if quartier_filter != "Tous" else "Évolution Hebdomadaire — Consommation & Température"
227
  fig.update_layout(
228
+ title=title, xaxis_title="Semaine",
229
  yaxis=dict(title="Consommation (MW)"),
230
  yaxis2=dict(title="Température (°C)", overlaying='y', side='right'),
231
  hovermode='x unified', height=500