jaimalklyde commited on
Commit
5374493
·
verified ·
1 Parent(s): d7a4991

Update src/module/Dashboard.py

Browse files
Files changed (1) hide show
  1. src/module/Dashboard.py +21 -4
src/module/Dashboard.py CHANGED
@@ -392,20 +392,37 @@ class RealtimeMonitor:
392
  'timestamp': datetime.now()
393
  }
394
 
 
395
  def get_service_breakdown(self):
396
- """Répartition par service"""
397
-
398
- recent = self.df.tail(30)
399
 
400
  if 'service_code' not in recent.columns:
401
  return None
402
 
403
- service_stats = recent.groupby('service_code').agg({
 
 
 
 
 
 
 
 
 
404
  'taux_occupation': 'mean',
405
  'tension_personnel': 'mean',
406
  'nb_admissions': 'sum'
407
  }).round(4)
408
 
 
 
 
 
 
 
 
 
409
  service_stats.columns = ['Taux Occupation', 'Tension Personnel', 'Admissions (30j)']
410
  service_stats = service_stats.sort_values('Taux Occupation', ascending=False)
411
 
 
392
  'timestamp': datetime.now()
393
  }
394
 
395
+
396
  def get_service_breakdown(self):
397
+ """Répartition par service (Avec traduction automatique des codes numériques)"""
398
+ recent = self.df.tail(30).copy()
 
399
 
400
  if 'service_code' not in recent.columns:
401
  return None
402
 
403
+ # Mapping de secours (basé sur ton injecteur de données)
404
+ # Permet de retraduire 0, 1, 2 en noms lisibles si l'IA a encodé les données
405
+ SERVICE_MAP = {
406
+ 0: "URG", 1: "MED", 2: "PED",
407
+ 3: "REA", 4: "INF", 5: "ISO",
408
+ 6: "CAR", 7: "NEU", 8: "TRA"
409
+ }
410
+
411
+ # Agrégation
412
+ service_stats = recent.groupby('service_code', as_index=True).agg({
413
  'taux_occupation': 'mean',
414
  'tension_personnel': 'mean',
415
  'nb_admissions': 'sum'
416
  }).round(4)
417
 
418
+ # --- BLOC DE CORRECTION D'AFFICHAGE ---
419
+ # Si l'index est numérique (ex: 0, 1, 2), on applique le mapping
420
+ if pd.api.types.is_numeric_dtype(service_stats.index):
421
+ # On essaie de traduire, sinon on met "Svc N" pour ne pas planter
422
+ new_index = service_stats.index.map(lambda x: SERVICE_MAP.get(int(x), f"Svc {x}"))
423
+ service_stats.index = new_index
424
+ # --------------------------------------
425
+
426
  service_stats.columns = ['Taux Occupation', 'Tension Personnel', 'Admissions (30j)']
427
  service_stats = service_stats.sort_values('Taux Occupation', ascending=False)
428