jaimalklyde commited on
Commit
1c2c1a3
·
verified ·
1 Parent(s): 1fc3fd2

Update src/module/Data_Exploration.py

Browse files
Files changed (1) hide show
  1. src/module/Data_Exploration.py +27 -25
src/module/Data_Exploration.py CHANGED
@@ -11,9 +11,9 @@ import plotly.graph_objects as go
11
  import gspread
12
  from datetime import datetime
13
  import json
 
14
 
15
  # --- DEBUG MARKER ---
16
- # Si cette ligne s'affiche dans les logs, le module est bien lu
17
  print("✅ Module Data_Exploration chargé avec succès")
18
 
19
  class DataExplorer:
@@ -125,7 +125,11 @@ class DataExplorer:
125
  st.info("Données ressources insuffisantes pour le calcul des KPIs.")
126
 
127
  def show_stock_alerts(self):
128
- df_stock = self.get_dataframe('materiel')
 
 
 
 
129
  if df_stock is not None and 'tension_stock' in df_stock.columns:
130
  alerts = df_stock[df_stock['tension_stock'] > 0.8]
131
  if not alerts.empty:
@@ -136,8 +140,7 @@ class DataExplorer:
136
 
137
 
138
  # ==============================================================================
139
- # ⚠️ C'EST ICI QUE SE JOUE VOTRE PROBLÈME
140
- # La fonction show_terminal DOIT être collée à gauche (pas d'indentation)
141
  # ==============================================================================
142
  def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
143
  """Fonction principale du Dashboard"""
@@ -148,33 +151,30 @@ def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
148
 
149
  explorer = st.session_state.data_explorer
150
 
151
- # Layout Dashboard
152
  st.markdown("## 🔬 DATA EXPLORER & MONITORING")
153
 
154
- # Bouton de chargement intelligent
 
155
  if not explorer.dataframes:
156
- if st.button("📥 Initialiser la connexion aux données", type="primary"):
 
157
 
158
- with st.spinner("Téléchargement des données Google Sheets..."):
159
- # On capture le succès ou l'échec
160
- success = explorer.load_all_sheets()
161
-
162
- if success:
163
- st.success("✅ Données chargées ! Actualisation...")
164
- import time
165
- time.sleep(1) # On laisse le temps de lire le succès
166
- st.rerun()
167
- else:
168
- # SI CA RATE : On ne fait SURTOUT PAS de rerun.
169
- # L'erreur affichée dans load_all_sheets restera ainsi visible.
170
- st.error("🛑 Le chargement a échoué. Regardez le message d'erreur ci-dessus.")
171
  else:
172
  # Barre d'outils
173
  col_actions, _ = st.columns([1, 4])
174
  with col_actions:
175
- if st.button("🔄 Rafraîchir"):
176
- explorer.dataframes = {}
177
- st.rerun()
178
 
179
  # Onglets de navigation
180
  tabs = st.tabs(["Vue Globale", "Patients", "Qualité & Stock", "Inspection"])
@@ -194,5 +194,7 @@ def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
194
  explorer.show_stock_alerts()
195
 
196
  with tabs[3]:
197
- sheet = st.selectbox("Choisir une table", list(explorer.dataframes.keys()))
198
- explorer.show_detailed_inspection(sheet)
 
 
 
11
  import gspread
12
  from datetime import datetime
13
  import json
14
+ import time
15
 
16
  # --- DEBUG MARKER ---
 
17
  print("✅ Module Data_Exploration chargé avec succès")
18
 
19
  class DataExplorer:
 
125
  st.info("Données ressources insuffisantes pour le calcul des KPIs.")
126
 
127
  def show_stock_alerts(self):
128
+ df_stock = self.get_dataframe('stock_materiel_jour') # Correction probable du nom ici selon tes fichiers précédents
129
+ # Si ça ne marche pas, remets 'materiel' si c'est le nom de ta table
130
+ if df_stock is None:
131
+ df_stock = self.get_dataframe('materiel')
132
+
133
  if df_stock is not None and 'tension_stock' in df_stock.columns:
134
  alerts = df_stock[df_stock['tension_stock'] > 0.8]
135
  if not alerts.empty:
 
140
 
141
 
142
  # ==============================================================================
143
+ # FONCTION PRINCIPALE AVEC CHARGEMENT AUTO
 
144
  # ==============================================================================
145
  def show_terminal(gspread_client, sheet_name="bdd_mvp_faker"):
146
  """Fonction principale du Dashboard"""
 
151
 
152
  explorer = st.session_state.data_explorer
153
 
 
154
  st.markdown("## 🔬 DATA EXPLORER & MONITORING")
155
 
156
+ # --- LOGIQUE DE CHARGEMENT AUTOMATIQUE ---
157
+ # Si les données ne sont pas chargées, on lance le chargement immédiatement
158
  if not explorer.dataframes:
159
+ with st.spinner("🔄 Connexion automatique à Google Sheets en cours..."):
160
+ success = explorer.load_all_sheets()
161
 
162
+ if success:
163
+ st.success("✅ Données chargées avec succès !")
164
+ time.sleep(0.5) # Petit délai pour voir le message
165
+ st.rerun() # On recharge la page pour afficher le dashboard
166
+ else:
167
+ st.error("🛑 Le chargement a échoué. Vérifiez votre connexion ou la clé API.")
168
+ return # On arrête l'exécution ici si ça plante
169
+
170
+ # --- DASHBOARD (S'affiche seulement si les données sont là) ---
 
 
 
 
171
  else:
172
  # Barre d'outils
173
  col_actions, _ = st.columns([1, 4])
174
  with col_actions:
175
+ if st.button("🔄 Rafraîchir Données"):
176
+ explorer.dataframes = {} # On vide le cache
177
+ st.rerun() # On relance, ce qui déclenchera le chargement auto ci-dessus
178
 
179
  # Onglets de navigation
180
  tabs = st.tabs(["Vue Globale", "Patients", "Qualité & Stock", "Inspection"])
 
194
  explorer.show_stock_alerts()
195
 
196
  with tabs[3]:
197
+ # Sélecteur de table sécurisé
198
+ if explorer.dataframes:
199
+ sheet = st.selectbox("Choisir une table", list(explorer.dataframes.keys()))
200
+ explorer.show_detailed_inspection(sheet)