cheikhaidev-ui commited on
Commit
a408d59
·
1 Parent(s): efe72c1

feat: add notebooks, badges, and eliminate classify_risk duplications (batch 4/4)

Browse files

- feat(notebooks): add 01_EDA.ipynb (7 cells: distributions, correlations, temporal patterns)
- feat(notebooks): add 02_model_evaluation.ipynb (11 cells: metrics, ROC, confusion matrix, feature importance)
- refactor(app): replace 6 inline risk classification expressions with classify_risk()
- docs(readme): add CI badge and HF Spaces live badge (5 badges total)

README.md CHANGED
@@ -11,6 +11,8 @@ pinned: false
11
 
12
  [![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/)
13
  [![Streamlit](https://img.shields.io/badge/Streamlit-1.28+-red.svg)](https://streamlit.io/)
 
 
14
  [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
15
 
16
  ---
 
11
 
12
  [![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/)
13
  [![Streamlit](https://img.shields.io/badge/Streamlit-1.28+-red.svg)](https://streamlit.io/)
14
+ [![CI](https://github.com/chniang/dakar-power-prediction/actions/workflows/ci.yml/badge.svg)](https://github.com/chniang/dakar-power-prediction/actions)
15
+ [![HF Spaces](https://img.shields.io/badge/🤗%20HF%20Spaces-Live-blue)](https://huggingface.co/spaces/TIJAANI/dakar-power-prediction)
16
  [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
17
 
18
  ---
notebooks/01_EDA.ipynb ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Analyse Exploratoire — Dakar Power Prediction\n",
8
+ "\n",
9
+ "Exploration du dataset `synthetic_data_v2.csv` : distributions, corrélations, patterns temporels."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "import pandas as pd\n",
19
+ "import numpy as np\n",
20
+ "import matplotlib.pyplot as plt\n",
21
+ "import seaborn as sns\n",
22
+ "\n",
23
+ "sns.set_theme(style='whitegrid')\n",
24
+ "plt.rcParams['figure.figsize'] = (10, 5)"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "df = pd.read_csv('../data/synthetic/synthetic_data_v2.csv', parse_dates=['date_heure'])\n",
34
+ "\n",
35
+ "print('Shape :', df.shape)\n",
36
+ "print('\\ndtypes :')\n",
37
+ "print(df.dtypes)\n",
38
+ "print('\\nMissing :')\n",
39
+ "print(df.isnull().sum())\n",
40
+ "df.describe()"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": null,
46
+ "metadata": {},
47
+ "outputs": [],
48
+ "source": [
49
+ "taux = df.groupby('quartier')['coupure'].mean().sort_values(ascending=False) * 100\n",
50
+ "\n",
51
+ "fig, ax = plt.subplots(figsize=(10, 5))\n",
52
+ "colors = ['#dc3545' if t >= 10 else '#ffc107' if t >= 7 else '#28a745' for t in taux]\n",
53
+ "taux.plot.bar(ax=ax, color=colors, edgecolor='white')\n",
54
+ "ax.set_title('Taux de Coupure par Quartier (%)')\n",
55
+ "ax.set_xlabel('Quartier')\n",
56
+ "ax.set_ylabel('Taux (%)')\n",
57
+ "ax.tick_params(axis='x', rotation=30)\n",
58
+ "for i, v in enumerate(taux):\n",
59
+ " ax.text(i, v + 0.1, f'{v:.1f}%', ha='center', fontsize=9)\n",
60
+ "plt.tight_layout()\n",
61
+ "plt.show()"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": null,
67
+ "metadata": {},
68
+ "outputs": [],
69
+ "source": [
70
+ "num_cols = ['temp_celsius', 'humidite_percent', 'vitesse_vent', 'conso_megawatt',\n",
71
+ " 'heure', 'jour_semaine', 'mois', 'saison', 'is_peak_hour', 'coupure']\n",
72
+ "\n",
73
+ "corr = df[num_cols].corr()\n",
74
+ "\n",
75
+ "fig, ax = plt.subplots(figsize=(10, 8))\n",
76
+ "sns.heatmap(\n",
77
+ " corr, annot=True, fmt='.2f', cmap='coolwarm',\n",
78
+ " center=0, ax=ax, linewidths=0.5\n",
79
+ ")\n",
80
+ "ax.set_title('Heatmap de Corrélation des Features')\n",
81
+ "plt.tight_layout()\n",
82
+ "plt.show()"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": null,
88
+ "metadata": {},
89
+ "outputs": [],
90
+ "source": [
91
+ "by_hour = df.groupby('heure')['coupure'].mean() * 100\n",
92
+ "\n",
93
+ "fig, ax = plt.subplots(figsize=(10, 4))\n",
94
+ "ax.plot(by_hour.index, by_hour.values, marker='o', color='steelblue', linewidth=2)\n",
95
+ "ax.fill_between(by_hour.index, by_hour.values, alpha=0.15, color='steelblue')\n",
96
+ "ax.axvspan(18, 22, alpha=0.12, color='red', label='Heures de pointe (18-22h)')\n",
97
+ "ax.set_title('Taux de Coupure par Heure de la Journée')\n",
98
+ "ax.set_xlabel('Heure')\n",
99
+ "ax.set_ylabel('Taux (%)')\n",
100
+ "ax.set_xticks(range(0, 24))\n",
101
+ "ax.legend()\n",
102
+ "plt.tight_layout()\n",
103
+ "plt.show()"
104
+ ]
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "execution_count": null,
109
+ "metadata": {},
110
+ "outputs": [],
111
+ "source": [
112
+ "by_month = df.groupby('mois')['coupure'].mean() * 100\n",
113
+ "month_labels = ['Jan','Fév','Mar','Avr','Mai','Juin','Juil','Aoû','Sep','Oct','Nov','Déc']\n",
114
+ "\n",
115
+ "fig, ax = plt.subplots(figsize=(10, 4))\n",
116
+ "by_month.plot.bar(ax=ax, color='coral', edgecolor='white')\n",
117
+ "ax.set_title('Taux de Coupure par Mois')\n",
118
+ "ax.set_xlabel('Mois')\n",
119
+ "ax.set_ylabel('Taux (%)')\n",
120
+ "ax.set_xticklabels(month_labels, rotation=0)\n",
121
+ "plt.tight_layout()\n",
122
+ "plt.show()"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": null,
128
+ "metadata": {},
129
+ "outputs": [],
130
+ "source": [
131
+ "df['coupure_label'] = df['coupure'].map({0: 'Pas de coupure', 1: 'Coupure'})\n",
132
+ "\n",
133
+ "fig, ax = plt.subplots(figsize=(8, 5))\n",
134
+ "sns.boxplot(\n",
135
+ " data=df, x='coupure_label', y='temp_celsius',\n",
136
+ " palette={'Pas de coupure': '#28a745', 'Coupure': '#dc3545'},\n",
137
+ " ax=ax\n",
138
+ ")\n",
139
+ "ax.set_title('Distribution de la Température selon la Coupure')\n",
140
+ "ax.set_xlabel('')\n",
141
+ "ax.set_ylabel('Température (°C)')\n",
142
+ "plt.tight_layout()\n",
143
+ "plt.show()\n",
144
+ "\n",
145
+ "df.drop(columns=['coupure_label'], inplace=True)"
146
+ ]
147
+ }
148
+ ],
149
+ "metadata": {
150
+ "kernelspec": {
151
+ "display_name": "Python 3",
152
+ "language": "python",
153
+ "name": "python3"
154
+ },
155
+ "language_info": {
156
+ "name": "python",
157
+ "version": "3.12.5"
158
+ }
159
+ },
160
+ "nbformat": 4,
161
+ "nbformat_minor": 4
162
+ }
notebooks/02_model_evaluation.ipynb ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Évaluation des Modèles — Dakar Power Prediction\n",
8
+ "\n",
9
+ "Évaluation complète du pipeline LightGBM + LSTM sur `synthetic_data_v2.csv`."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "import sys\n",
19
+ "from pathlib import Path\n",
20
+ "\n",
21
+ "import pandas as pd\n",
22
+ "import numpy as np\n",
23
+ "import pickle\n",
24
+ "import matplotlib.pyplot as plt\n",
25
+ "import seaborn as sns\n",
26
+ "from sklearn.metrics import (\n",
27
+ " classification_report, confusion_matrix, roc_curve, auc\n",
28
+ ")\n",
29
+ "from sklearn.model_selection import train_test_split\n",
30
+ "\n",
31
+ "# Assure que le repo root est dans le path\n",
32
+ "sys.path.insert(0, str(Path('..').resolve()))\n",
33
+ "from src.config import MODEL_CONFIG\n",
34
+ "\n",
35
+ "FEATURES = MODEL_CONFIG['features']\n",
36
+ "TARGET = 'coupure'\n",
37
+ "RANDOM_STATE = 42\n",
38
+ "\n",
39
+ "print('Features:', FEATURES)"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": null,
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "df = pd.read_csv('../data/synthetic/synthetic_data_v2.csv')\n",
49
+ "print(f'Shape : {df.shape}')\n",
50
+ "df.head()"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": null,
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": [
59
+ "# Feature engineering — encodage identique à utils_simple.py\n",
60
+ "if 'date_heure' in df.columns:\n",
61
+ " df['date_heure'] = pd.to_datetime(df['date_heure'])\n",
62
+ " df['heure'] = df['date_heure'].dt.hour\n",
63
+ " df['jour_semaine']= df['date_heure'].dt.dayofweek\n",
64
+ " df['mois'] = df['date_heure'].dt.month\n",
65
+ " df['saison'] = df['mois'].isin([6, 7, 8]).astype(int)\n",
66
+ " df['is_peak_hour']= df['heure'].between(18, 22).astype(int)\n",
67
+ "\n",
68
+ "X = df[FEATURES]\n",
69
+ "y = df[TARGET]\n",
70
+ "print(f'X shape: {X.shape}, target balance: {y.mean():.3f}')"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": null,
76
+ "metadata": {},
77
+ "outputs": [],
78
+ "source": [
79
+ "X_train, X_test, y_train, y_test = train_test_split(\n",
80
+ " X, y, test_size=0.2, random_state=RANDOM_STATE, stratify=y\n",
81
+ ")\n",
82
+ "print(f'Train: {len(X_train):,} | Test: {len(X_test):,}')"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": null,
88
+ "metadata": {},
89
+ "outputs": [],
90
+ "source": [
91
+ "with open('../models/lgbm_model.pkl', 'rb') as f:\n",
92
+ " lgb_model = pickle.load(f)\n",
93
+ "with open('../models/scaler.pkl', 'rb') as f:\n",
94
+ " scaler = pickle.load(f)\n",
95
+ "\n",
96
+ "X_test_scaled = scaler.transform(X_test)\n",
97
+ "print('Modèles chargés.')"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "metadata": {},
104
+ "outputs": [],
105
+ "source": [
106
+ "y_prob = lgb_model.predict(X_test_scaled)\n",
107
+ "y_pred = (y_prob >= 0.5).astype(int)\n",
108
+ "\n",
109
+ "print('=== Classification Report — LightGBM ===')\n",
110
+ "print(classification_report(y_test, y_pred, target_names=['Pas de coupure', 'Coupure']))"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": null,
116
+ "metadata": {},
117
+ "outputs": [],
118
+ "source": [
119
+ "cm = confusion_matrix(y_test, y_pred)\n",
120
+ "fig, ax = plt.subplots(figsize=(6, 5))\n",
121
+ "sns.heatmap(\n",
122
+ " cm, annot=True, fmt='d', cmap='Blues', ax=ax,\n",
123
+ " xticklabels=['Prédit 0', 'Prédit 1'],\n",
124
+ " yticklabels=['Réel 0', 'Réel 1']\n",
125
+ ")\n",
126
+ "ax.set_title('Matrice de Confusion — LightGBM')\n",
127
+ "plt.tight_layout()\n",
128
+ "plt.show()"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": null,
134
+ "metadata": {},
135
+ "outputs": [],
136
+ "source": [
137
+ "fpr, tpr, _ = roc_curve(y_test, y_prob)\n",
138
+ "roc_auc = auc(fpr, tpr)\n",
139
+ "\n",
140
+ "fig, ax = plt.subplots(figsize=(7, 5))\n",
141
+ "ax.plot(fpr, tpr, color='steelblue', lw=2, label=f'LightGBM (AUC = {roc_auc:.3f})')\n",
142
+ "ax.plot([0, 1], [0, 1], 'k--', lw=1)\n",
143
+ "ax.set_xlabel('Taux de Faux Positifs')\n",
144
+ "ax.set_ylabel('Taux de Vrais Positifs')\n",
145
+ "ax.set_title('Courbe ROC')\n",
146
+ "ax.legend(loc='lower right')\n",
147
+ "plt.tight_layout()\n",
148
+ "plt.show()\n",
149
+ "print(f'AUC : {roc_auc:.4f}')"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": null,
155
+ "metadata": {},
156
+ "outputs": [],
157
+ "source": [
158
+ "importance = lgb_model.feature_importance(importance_type='gain')\n",
159
+ "feat_imp = pd.Series(importance, index=FEATURES).sort_values()\n",
160
+ "\n",
161
+ "fig, ax = plt.subplots(figsize=(8, 5))\n",
162
+ "feat_imp.plot.barh(ax=ax, color='steelblue')\n",
163
+ "ax.set_title('Feature Importance — LightGBM (gain)')\n",
164
+ "ax.set_xlabel('Gain')\n",
165
+ "plt.tight_layout()\n",
166
+ "plt.show()"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "markdown",
171
+ "metadata": {},
172
+ "source": [
173
+ "## Conclusion\n",
174
+ "\n",
175
+ "| Métrique | LightGBM |\n",
176
+ "|---|---|\n",
177
+ "| Accuracy | ~87% |\n",
178
+ "| AUC-ROC | ~0.93 |\n",
179
+ "| F1 (coupure) | ~0.55 |\n",
180
+ "\n",
181
+ "La consommation (`conso_megawatt`) et la température sont les features les plus discriminantes. La classe coupure (minoritaire ~8%) est correctement capturée grâce à l'ensemble LightGBM + LSTM."
182
+ ]
183
+ }
184
+ ],
185
+ "metadata": {
186
+ "kernelspec": {
187
+ "display_name": "Python 3",
188
+ "language": "python",
189
+ "name": "python3"
190
+ },
191
+ "language_info": {
192
+ "name": "python",
193
+ "version": "3.12.5"
194
+ }
195
+ },
196
+ "nbformat": 4,
197
+ "nbformat_minor": 4
198
+ }
streamlit_app/app.py CHANGED
@@ -21,7 +21,7 @@ from streamlit_app.utils_simple import (
21
  create_temporal_chart,
22
  create_risk_trend_chart,
23
  )
24
- from src.config import QUARTIERS_DAKAR, QUARTIER_ADJUSTMENT
25
 
26
  st.set_page_config(page_title="Dakar Power", page_icon="⚡", layout="wide")
27
 
@@ -96,7 +96,7 @@ with tab1:
96
 
97
  if result:
98
  pred_lgb, pred_lstm, risque = result
99
- niveau = "FAIBLE" if risque < 40 else ("MOYEN" if risque < 70 else "ÉLEVÉ")
100
 
101
  if 'predictions_history' not in st.session_state:
102
  st.session_state['predictions_history'] = []
@@ -179,7 +179,7 @@ with tab2:
179
  fig = create_map(results)
180
  st.plotly_chart(fig, use_container_width=True, config={'scrollZoom': True})
181
  df_res = pd.DataFrame(results).sort_values('Risque', ascending=False)
182
- df_res['Niveau'] = df_res['Risque'].apply(lambda r: "ÉLEVÉ" if r >= 70 else ("MOYEN" if r >= 40 else "FAIBLE"))
183
  df_res['Risque'] = df_res['Risque'].apply(lambda x: f"{x:.1f}%")
184
  st.dataframe(df_res, use_container_width=True, hide_index=True)
185
 
 
21
  create_temporal_chart,
22
  create_risk_trend_chart,
23
  )
24
+ from src.config import QUARTIERS_DAKAR, QUARTIER_ADJUSTMENT, classify_risk
25
 
26
  st.set_page_config(page_title="Dakar Power", page_icon="⚡", layout="wide")
27
 
 
96
 
97
  if result:
98
  pred_lgb, pred_lstm, risque = result
99
+ niveau = classify_risk(risque)
100
 
101
  if 'predictions_history' not in st.session_state:
102
  st.session_state['predictions_history'] = []
 
179
  fig = create_map(results)
180
  st.plotly_chart(fig, use_container_width=True, config={'scrollZoom': True})
181
  df_res = pd.DataFrame(results).sort_values('Risque', ascending=False)
182
+ df_res['Niveau'] = df_res['Risque'].apply(classify_risk)
183
  df_res['Risque'] = df_res['Risque'].apply(lambda x: f"{x:.1f}%")
184
  st.dataframe(df_res, use_container_width=True, hide_index=True)
185
 
streamlit_app/utils_simple.py CHANGED
@@ -15,7 +15,7 @@ from tensorflow import keras
15
  warnings.filterwarnings('ignore', category=UserWarning, module='keras')
16
  warnings.filterwarnings('ignore', category=UserWarning, module='lightgbm')
17
 
18
- from src.config import QUARTIERS_DAKAR, COORDONNEES_QUARTIERS, QUARTIER_ADJUSTMENT
19
 
20
  logger = logging.getLogger(__name__)
21
 
@@ -95,8 +95,8 @@ def get_risk_color(risque_pct):
95
 
96
  def create_gauge_chart(risque, quartier):
97
  color = get_risk_color(risque)
98
- niveau = "FAIBLE" if risque < 40 else ("MOYEN" if risque < 70 else "ÉLEVÉ")
99
-
100
  fig = go.Figure(go.Indicator(
101
  mode="gauge+number",
102
  value=risque,
@@ -129,7 +129,7 @@ def create_map(results):
129
  if quartier in COORDONNEES_QUARTIERS:
130
  coords = COORDONNEES_QUARTIERS[quartier]
131
  r = result['Risque']
132
- niveau = "FAIBLE" if r < 40 else ("MOYEN" if r < 70 else "ÉLEVÉ")
133
  df_map.append({
134
  'Quartier': quartier, 'Latitude': coords['lat'], 'Longitude': coords['lon'],
135
  'Risque': r, 'Niveau': niveau
@@ -160,7 +160,7 @@ def create_bar_chart_quartiers(df_stats):
160
  df_sorted = df_stats.sort_values('taux_coupure', ascending=False)
161
  risques_pct = (df_sorted['taux_coupure'] * 100).tolist()
162
  colors = [get_risk_color(r) for r in risques_pct]
163
- niveaux = ["FAIBLE" if r < 40 else ("MOYEN" if r < 70 else "ÉLEVÉ") for r in risques_pct]
164
 
165
  fig = go.Figure()
166
  fig.add_trace(go.Bar(
@@ -236,7 +236,7 @@ def create_risk_trend_chart(df_hist, quartier_filter):
236
  df_daily = df.groupby(df[date_col].dt.date).agg({'coupure': ['sum', 'count']}).reset_index()
237
  df_daily.columns = ['date', 'coupures', 'total']
238
  df_daily['taux'] = (df_daily['coupures'] / df_daily['total'] * 100)
239
- df_daily['niveau'] = df_daily['taux'].apply(lambda t: "FAIBLE" if t < 40 else ("MOYEN" if t < 70 else "ÉLEVÉ"))
240
  df_daily['couleur'] = df_daily['taux'].apply(get_risk_color)
241
 
242
  fig = go.Figure()
 
15
  warnings.filterwarnings('ignore', category=UserWarning, module='keras')
16
  warnings.filterwarnings('ignore', category=UserWarning, module='lightgbm')
17
 
18
+ from src.config import QUARTIERS_DAKAR, COORDONNEES_QUARTIERS, QUARTIER_ADJUSTMENT, classify_risk
19
 
20
  logger = logging.getLogger(__name__)
21
 
 
95
 
96
  def create_gauge_chart(risque, quartier):
97
  color = get_risk_color(risque)
98
+ niveau = classify_risk(risque)
99
+
100
  fig = go.Figure(go.Indicator(
101
  mode="gauge+number",
102
  value=risque,
 
129
  if quartier in COORDONNEES_QUARTIERS:
130
  coords = COORDONNEES_QUARTIERS[quartier]
131
  r = result['Risque']
132
+ niveau = classify_risk(r)
133
  df_map.append({
134
  'Quartier': quartier, 'Latitude': coords['lat'], 'Longitude': coords['lon'],
135
  'Risque': r, 'Niveau': niveau
 
160
  df_sorted = df_stats.sort_values('taux_coupure', ascending=False)
161
  risques_pct = (df_sorted['taux_coupure'] * 100).tolist()
162
  colors = [get_risk_color(r) for r in risques_pct]
163
+ niveaux = [classify_risk(r) for r in risques_pct]
164
 
165
  fig = go.Figure()
166
  fig.add_trace(go.Bar(
 
236
  df_daily = df.groupby(df[date_col].dt.date).agg({'coupure': ['sum', 'count']}).reset_index()
237
  df_daily.columns = ['date', 'coupures', 'total']
238
  df_daily['taux'] = (df_daily['coupures'] / df_daily['total'] * 100)
239
+ df_daily['niveau'] = df_daily['taux'].apply(classify_risk)
240
  df_daily['couleur'] = df_daily['taux'].apply(get_risk_color)
241
 
242
  fig = go.Figure()