Spaces:
Sleeping
Sleeping
Debugging kpi extraction...
Browse files- api/services/dataset_service.py +36 -25
api/services/dataset_service.py
CHANGED
|
@@ -25,21 +25,46 @@ DATA_PATH = Path(__file__).resolve().parent.parent.parent / "data"
|
|
| 25 |
DATASET_PATH = DATA_PATH / "medical_dataset_3M.csv"
|
| 26 |
KPIS_PATH = DATA_PATH / "kpis_export.json"
|
| 27 |
MOCK_KPIS_PATH = DATA_PATH / "kpis_export_mock.json"
|
|
|
|
| 28 |
|
| 29 |
WORKING_DIR = DATA_PATH
|
| 30 |
|
|
|
|
| 31 |
|
| 32 |
-
def extract_kpis():
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
# json.dump(data, f, ensure_ascii=False, indent=2)
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Configuration globale des graphes matplotlib
|
|
|
|
|
|
|
| 43 |
matplotlib.rcParams.update({
|
| 44 |
"figure.dpi": 120,
|
| 45 |
"figure.facecolor": "white",
|
|
@@ -58,39 +83,23 @@ def extract_kpis():
|
|
| 58 |
PALETTE_SEQUENTIELLE = "YlOrRd"
|
| 59 |
|
| 60 |
print("Imports effectues avec succes.")
|
|
|
|
| 61 |
print(f"Pandas version : {pd.__version__}")
|
| 62 |
print(f"NumPy version : {np.__version__}")
|
| 63 |
|
| 64 |
|
| 65 |
-
# In[3]:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
# Fonctions et variables utiles
|
| 69 |
-
start_time = 0
|
| 70 |
-
def start():
|
| 71 |
-
start_time = perf_counter()
|
| 72 |
-
|
| 73 |
-
def time_lapse(start_time = start_time, end_time = perf_counter(), display = True):
|
| 74 |
-
time_elapsed = end_time - start_time
|
| 75 |
-
hours, rem = divmod(time_elapsed, 3600)
|
| 76 |
-
minutes, seconds = divmod(rem, 60)
|
| 77 |
-
if display:
|
| 78 |
-
return f"{int(hours)}h {int(minutes)}m {seconds:.2f}s"
|
| 79 |
-
return int(hours), int(minutes), seconds
|
| 80 |
-
|
| 81 |
-
|
| 82 |
# In[4]:
|
| 83 |
|
| 84 |
|
| 85 |
# Chargement et Aperçu de la Dataset
|
| 86 |
print(f"Chemin de la dataset : {DATASET_PATH}")
|
| 87 |
print("Chargement du fichier...")
|
| 88 |
-
|
| 89 |
|
| 90 |
df = pd.read_csv(DATASET_PATH, low_memory=False)
|
| 91 |
|
| 92 |
-
print("Temps écroulé : ", time_lapse())
|
| 93 |
print(f"\nDataset charge avec succes.")
|
|
|
|
| 94 |
print(f"Dimensions : {df.shape[0]:,} lignes x {df.shape[1]} colonnes")
|
| 95 |
|
| 96 |
# Apercu des premieres lignes
|
|
@@ -110,6 +119,7 @@ def extract_kpis():
|
|
| 110 |
print(f"Exemples : {symptom_cols[:5]}")
|
| 111 |
|
| 112 |
# Résumé
|
|
|
|
| 113 |
symptom_cols = df.columns[4:].tolist()
|
| 114 |
meta = {
|
| 115 |
"shape": df.shape,
|
|
@@ -130,6 +140,7 @@ def extract_kpis():
|
|
| 130 |
with open(f"{WORKING_DIR}/dataset_summary.json", "w", encoding="utf-8") as f:
|
| 131 |
json.dump(meta, f, indent=2, ensure_ascii=False)
|
| 132 |
|
|
|
|
| 133 |
|
| 134 |
# In[ ]:
|
| 135 |
|
|
|
|
| 25 |
DATASET_PATH = DATA_PATH / "medical_dataset_3M.csv"
|
| 26 |
KPIS_PATH = DATA_PATH / "kpis_export.json"
|
| 27 |
MOCK_KPIS_PATH = DATA_PATH / "kpis_export_mock.json"
|
| 28 |
+
LOG_PATH = DATA_PATH / "trace.log"
|
| 29 |
|
| 30 |
WORKING_DIR = DATA_PATH
|
| 31 |
|
| 32 |
+
# In[3]:
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
+
# Fonctions et variables utiles
|
| 36 |
+
start_time = 0
|
| 37 |
+
|
| 38 |
+
def start():
|
| 39 |
+
global start_time
|
| 40 |
+
start_time = perf_counter()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def time_lapse(display=True):
|
| 44 |
+
|
| 45 |
+
time_elapsed = perf_counter() - start_time
|
| 46 |
+
|
| 47 |
+
hours, rem = divmod(time_elapsed, 3600)
|
| 48 |
+
minutes, seconds = divmod(rem, 60)
|
| 49 |
+
|
| 50 |
+
if display:
|
| 51 |
+
return f"{int(hours)}h {int(minutes)}m {seconds:.2f}s"
|
| 52 |
+
|
| 53 |
+
return int(hours), int(minutes), seconds
|
| 54 |
+
|
| 55 |
+
def log(message):
|
| 56 |
+
with open(LOG_PATH, "a", encoding="utf-8") as logger:
|
| 57 |
+
logger.write(f"[{time_lapse()}] :\t{message}\n")
|
| 58 |
|
| 59 |
+
def extract_kpis():
|
|
|
|
| 60 |
|
| 61 |
+
start()
|
| 62 |
+
|
| 63 |
+
log("KPIs Extraction started...")
|
| 64 |
|
| 65 |
# Configuration globale des graphes matplotlib
|
| 66 |
+
log("Configuration globale des graphes matplotlib...")
|
| 67 |
+
|
| 68 |
matplotlib.rcParams.update({
|
| 69 |
"figure.dpi": 120,
|
| 70 |
"figure.facecolor": "white",
|
|
|
|
| 83 |
PALETTE_SEQUENTIELLE = "YlOrRd"
|
| 84 |
|
| 85 |
print("Imports effectues avec succes.")
|
| 86 |
+
log("Imports effectues avec succes.")
|
| 87 |
print(f"Pandas version : {pd.__version__}")
|
| 88 |
print(f"NumPy version : {np.__version__}")
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
# In[4]:
|
| 92 |
|
| 93 |
|
| 94 |
# Chargement et Aperçu de la Dataset
|
| 95 |
print(f"Chemin de la dataset : {DATASET_PATH}")
|
| 96 |
print("Chargement du fichier...")
|
| 97 |
+
log("Chargement de la dataset...")
|
| 98 |
|
| 99 |
df = pd.read_csv(DATASET_PATH, low_memory=False)
|
| 100 |
|
|
|
|
| 101 |
print(f"\nDataset charge avec succes.")
|
| 102 |
+
log("Dataset chargée avec succes.")
|
| 103 |
print(f"Dimensions : {df.shape[0]:,} lignes x {df.shape[1]} colonnes")
|
| 104 |
|
| 105 |
# Apercu des premieres lignes
|
|
|
|
| 119 |
print(f"Exemples : {symptom_cols[:5]}")
|
| 120 |
|
| 121 |
# Résumé
|
| 122 |
+
log("Affichage du résumé...")
|
| 123 |
symptom_cols = df.columns[4:].tolist()
|
| 124 |
meta = {
|
| 125 |
"shape": df.shape,
|
|
|
|
| 140 |
with open(f"{WORKING_DIR}/dataset_summary.json", "w", encoding="utf-8") as f:
|
| 141 |
json.dump(meta, f, indent=2, ensure_ascii=False)
|
| 142 |
|
| 143 |
+
log("Résumé exporté avec succès.")
|
| 144 |
|
| 145 |
# In[ ]:
|
| 146 |
|