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

feat(v2): SENELEC dashboard + 7-day forecast + fixed quartier names

Browse files

- feat(stats): add 4 KPI metrics (total outages, highest risk area, avg rate, avg temp)
- feat(stats): add hourly risk lineplot + monthly risk barplot
- feat(forecast): add 7-day weather forecast chart (temp + precipitation)
- fix(data): normalize quartier names with accents at CSV load (Sicap-Liberté, Mermoz-Sacré-Coeur)

Files changed (1) hide show
  1. streamlit_app/app.py +87 -2
streamlit_app/app.py CHANGED
@@ -2,6 +2,7 @@
2
  import streamlit as st
3
  import pandas as pd
4
  import numpy as np
 
5
  from datetime import datetime
6
  from pathlib import Path
7
  import sys
@@ -22,7 +23,7 @@ from streamlit_app.utils_simple import (
22
  create_risk_trend_chart,
23
  )
24
  from src.config import QUARTIERS_DAKAR, QUARTIER_ADJUSTMENT, classify_risk
25
- from src.weather_api import get_current_weather_dakar
26
 
27
  st.set_page_config(page_title="Dakar Power", page_icon="⚡", layout="wide")
28
 
@@ -34,10 +35,17 @@ if 'initialized' not in st.session_state:
34
 
35
  models = load_models_cached()
36
 
 
 
 
 
 
37
  @st.cache_data
38
  def load_csv():
39
  try:
40
- return pd.read_csv("data/synthetic/synthetic_data_v2.csv")
 
 
41
  except Exception as e:
42
  logger.error(f"Failed to load CSV: {e}")
43
  return None
@@ -201,6 +209,20 @@ with tab2:
201
  with tab3:
202
  st.header("📊 Statistiques CSV")
203
  if df_hist is not None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  quartier_filter = st.selectbox("Quartier", ["Tous"] + QUARTIERS_DAKAR, index=0, key='stats_q')
205
  df_f = df_hist if quartier_filter == "Tous" else df_hist[df_hist['quartier'] == quartier_filter]
206
  stats = df_f.groupby('quartier').agg({'coupure': ['sum', 'count'], 'temp_celsius': 'mean', 'conso_megawatt': 'mean'}).reset_index()
@@ -212,6 +234,37 @@ with tab3:
212
  st.dataframe(stats, use_container_width=True, hide_index=True)
213
  st.info(f"📊 {len(df_f):,} enregistrements")
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  with tab4:
216
  st.header("📈 Historique")
217
  if df_hist is not None:
@@ -228,5 +281,37 @@ with tab4:
228
  if fig_risk:
229
  st.plotly_chart(fig_risk, use_container_width=True)
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
 
 
2
  import streamlit as st
3
  import pandas as pd
4
  import numpy as np
5
+ import plotly.graph_objects as go
6
  from datetime import datetime
7
  from pathlib import Path
8
  import sys
 
23
  create_risk_trend_chart,
24
  )
25
  from src.config import QUARTIERS_DAKAR, QUARTIER_ADJUSTMENT, classify_risk
26
+ from src.weather_api import get_current_weather_dakar, get_weather_forecast_7days
27
 
28
  st.set_page_config(page_title="Dakar Power", page_icon="⚡", layout="wide")
29
 
 
35
 
36
  models = load_models_cached()
37
 
38
+ _QUARTIER_RENAME = {
39
+ 'Sicap-Liberte': 'Sicap-Liberté',
40
+ 'Mermoz-Sacre-Coeur': 'Mermoz-Sacré-Cœur',
41
+ }
42
+
43
  @st.cache_data
44
  def load_csv():
45
  try:
46
+ df = pd.read_csv("data/synthetic/synthetic_data_v2.csv")
47
+ df['quartier'] = df['quartier'].replace(_QUARTIER_RENAME)
48
+ return df
49
  except Exception as e:
50
  logger.error(f"Failed to load CSV: {e}")
51
  return None
 
209
  with tab3:
210
  st.header("📊 Statistiques CSV")
211
  if df_hist is not None:
212
+ # Métriques globales SENELEC
213
+ m1, m2, m3, m4 = st.columns(4)
214
+ q_max = df_hist.groupby('quartier')['coupure'].mean().idxmax()
215
+ with m1:
216
+ st.metric("🔴 Total Coupures", f"{int(df_hist['coupure'].sum()):,}")
217
+ with m2:
218
+ st.metric("⚠️ Plus à risque", q_max)
219
+ with m3:
220
+ st.metric("📊 Taux moyen", f"{df_hist['coupure'].mean()*100:.1f}%")
221
+ with m4:
222
+ st.metric("🌡️ Temp. moyenne", f"{df_hist['temp_celsius'].mean():.1f}°C")
223
+
224
+ st.markdown("---")
225
+
226
  quartier_filter = st.selectbox("Quartier", ["Tous"] + QUARTIERS_DAKAR, index=0, key='stats_q')
227
  df_f = df_hist if quartier_filter == "Tous" else df_hist[df_hist['quartier'] == quartier_filter]
228
  stats = df_f.groupby('quartier').agg({'coupure': ['sum', 'count'], 'temp_celsius': 'mean', 'conso_megawatt': 'mean'}).reset_index()
 
234
  st.dataframe(stats, use_container_width=True, hide_index=True)
235
  st.info(f"📊 {len(df_f):,} enregistrements")
236
 
237
+ st.markdown("---")
238
+ col1, col2 = st.columns(2)
239
+ with col1:
240
+ st.subheader("⏰ Risque par Heure")
241
+ by_hour = df_hist.groupby('heure')['coupure'].mean() * 100
242
+ fig_h = go.Figure()
243
+ fig_h.add_trace(go.Scatter(
244
+ x=list(range(24)),
245
+ y=by_hour.reindex(range(24), fill_value=0).values,
246
+ mode='lines+markers', fill='tozeroy',
247
+ line=dict(color='#e74c3c', width=2), marker=dict(size=5),
248
+ ))
249
+ fig_h.update_layout(
250
+ xaxis_title="Heure", yaxis_title="Taux (%)",
251
+ xaxis=dict(tickmode='linear', tick0=0, dtick=3),
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
258
+ month_labels = ['Jan','Fév','Mar','Avr','Mai','Juin','Juil','Aoû','Sep','Oct','Nov','Déc']
259
+ fig_m = go.Figure()
260
+ fig_m.add_trace(go.Bar(
261
+ x=month_labels,
262
+ y=by_month.reindex(range(1, 13), fill_value=0).values,
263
+ marker_color='#f39c12', opacity=0.85,
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")
270
  if df_hist is not None:
 
281
  if fig_risk:
282
  st.plotly_chart(fig_risk, use_container_width=True)
283
 
284
+ st.markdown("---")
285
+ st.subheader("🌤️ Prévisions Météo 7 Jours")
286
+ forecast = get_weather_forecast_7days()
287
+ if forecast:
288
+ df_fc = pd.DataFrame(forecast)
289
+ fig_fc = go.Figure()
290
+ fig_fc.add_trace(go.Bar(
291
+ x=df_fc['date'], y=df_fc['precipitation'],
292
+ name='Précipitations (mm)', marker_color='#3498db', opacity=0.6,
293
+ ))
294
+ fig_fc.add_trace(go.Scatter(
295
+ x=df_fc['date'], y=df_fc['temp_max'],
296
+ mode='lines+markers', name='Temp max (°C)',
297
+ line=dict(color='#e74c3c', width=2), yaxis='y2',
298
+ ))
299
+ fig_fc.add_trace(go.Scatter(
300
+ x=df_fc['date'], y=df_fc['temp_min'],
301
+ mode='lines+markers', name='Temp min (°C)',
302
+ line=dict(color='#2ecc71', width=2, dash='dot'), yaxis='y2',
303
+ ))
304
+ fig_fc.update_layout(
305
+ title="Prévisions Météo Dakar — 7 prochains jours",
306
+ xaxis_title="Date",
307
+ yaxis=dict(title="Précipitations (mm)"),
308
+ yaxis2=dict(title="Température (°C)", overlaying='y', side='right'),
309
+ hovermode='x unified',
310
+ height=400,
311
+ )
312
+ st.plotly_chart(fig_fc, use_container_width=True)
313
+ else:
314
+ st.info("🌐 Prévisions indisponibles (API météo)")
315
+
316
 
317