jaimalklyde commited on
Commit
5c7ad35
·
verified ·
1 Parent(s): c9670d7

Update src/module/Data_Exploration.py

Browse files
Files changed (1) hide show
  1. src/module/Data_Exploration.py +65 -41
src/module/Data_Exploration.py CHANGED
@@ -324,57 +324,81 @@ class DataExplorer:
324
  st.info("ℹ️ Colonne 'tension_stock' non trouvée dans les données")
325
 
326
 
 
 
327
  def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
328
  """
329
- Fonction principale à appeler depuis Streamlit pour afficher l'interface EDA
330
-
331
- Args:
332
- gspread_client: Client gspread authentifié
333
- sheet_name: Nom du fichier Google Sheets
334
  """
335
- st.markdown("## 🔬 EXPLORATEUR DE DONNÉES")
336
-
337
- # Initialisation
338
  if 'data_explorer' not in st.session_state:
339
  st.session_state.data_explorer = DataExplorer(gspread_client, sheet_name)
340
 
341
  explorer = st.session_state.data_explorer
342
 
343
- # Bouton de chargement
344
- if st.button("📥 Charger les Données", type="primary"):
345
- with st.spinner("Chargement en cours..."):
346
  success = explorer.load_all_sheets()
347
- if success:
348
- st.success("✅ Données chargées avec succès !")
349
-
350
- # Menu d'analyse
 
351
  if explorer.dataframes:
352
- st.divider()
353
-
354
- analysis_mode = st.selectbox(
355
- "Mode d'Analyse",
356
- ["Aperçu Général", "Inspection Détaillée", "Analyse Patients",
357
- "Qualité des Données", "KPIs", "Alertes Stock"]
358
- )
359
-
360
- if analysis_mode == "Aperçu Général":
 
 
 
 
 
 
 
 
 
 
 
361
  explorer.show_data_overview()
362
-
363
- elif analysis_mode == "Inspection Détaillée":
364
- sheet_to_inspect = st.selectbox(
365
- "Sélectionner un onglet",
366
- list(explorer.dataframes.keys())
367
- )
368
- explorer.show_detailed_inspection(sheet_to_inspect)
369
-
370
- elif analysis_mode == "Analyse Patients":
371
  explorer.analyze_patients()
372
-
373
- elif analysis_mode == "Qualité des Données":
374
- explorer.analyze_data_quality()
375
-
376
- elif analysis_mode == "KPIs":
 
 
 
 
 
 
 
 
 
 
377
  explorer.calculate_kpis()
378
-
379
- elif analysis_mode == "Alertes Stock":
380
- explorer.show_stock_alerts()
 
 
 
 
 
 
 
 
 
 
324
  st.info("ℹ️ Colonne 'tension_stock' non trouvée dans les données")
325
 
326
 
327
+ # ... (Le reste de la classe DataExplorer reste identique) ...
328
+
329
  def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
330
  """
331
+ Fonction d'affichage optimisée "Dashboard" pour Streamlit
 
 
 
 
332
  """
333
+ # 1. Initialisation persistante
 
 
334
  if 'data_explorer' not in st.session_state:
335
  st.session_state.data_explorer = DataExplorer(gspread_client, sheet_name)
336
 
337
  explorer = st.session_state.data_explorer
338
 
339
+ # 2. Auto-chargement des données (Si vide, on charge direct)
340
+ if not explorer.dataframes:
341
+ with st.spinner("🔄 Initialisation du Dashboard Data... Récupération GSheets..."):
342
  success = explorer.load_all_sheets()
343
+ if not success:
344
+ st.error("Impossible de récupérer les données.")
345
+ return
346
+
347
+ # 3. Interface DASHBOARD (Vue immédiate via Tabs)
348
  if explorer.dataframes:
349
+ # Titre avec bouton de rafraîchissement discret à droite
350
+ col_titre, col_refresh = st.columns([6, 1])
351
+ with col_titre:
352
+ st.markdown("## 🔬 MONITORING & EXPLORATION")
353
+ with col_refresh:
354
+ if st.button("🔄 Actualiser"):
355
+ explorer.dataframes = {} # Force le reload
356
+ st.rerun()
357
+
358
+ # Création des onglets principaux
359
+ tab_overview, tab_patients, tab_quality, tab_business = st.tabs([
360
+ "📊 Vue Globale",
361
+ "👥 Analyse Patients",
362
+ "🛡️ Qualité & Santé Données",
363
+ "💼 Business & KPIs"
364
+ ])
365
+
366
+ # --- ONGLET 1 : VUE GLOBALE ---
367
+ with tab_overview:
368
+ st.markdown("### 🩻 Radiographie des Données")
369
  explorer.show_data_overview()
370
+
371
+ st.divider()
372
+ st.caption("Sélectionnez un onglet ci-dessus pour entrer dans le détail.")
373
+
374
+ # --- ONGLET 2 : PATIENTS ---
375
+ with tab_patients:
 
 
 
376
  explorer.analyze_patients()
377
+
378
+ # --- ONGLET 3 : QUALITÉ (Regroupement Qualité + Stock) ---
379
+ with tab_quality:
380
+ col_q1, col_q2 = st.columns(2)
381
+
382
+ with col_q1:
383
+ st.markdown("#### 📉 Anomalies Détectées")
384
+ explorer.analyze_data_quality()
385
+
386
+ with col_q2:
387
+ st.markdown("#### 📦 Tensions Logistiques")
388
+ explorer.show_stock_alerts()
389
+
390
+ # --- ONGLET 4 : KPIs BUSINESS ---
391
+ with tab_business:
392
  explorer.calculate_kpis()
393
+
394
+ # Ajout d'une zone d'inspection manuelle ici si besoin
395
+ st.divider()
396
+ with st.expander("🔍 Inspection brute d'une table spécifique"):
397
+ sheet_choice = st.selectbox("Choisir la table", list(explorer.dataframes.keys()))
398
+ explorer.show_detailed_inspection(sheet_choice)
399
+
400
+ else:
401
+ # Fallback si le chargement a échoué mais sans erreur critique
402
+ st.warning("Aucune donnée n'a pu être chargée pour le moment.")
403
+ if st.button("Réessayer le chargement"):
404
+ st.rerun()