File size: 972 Bytes
b8c1afe
 
 
0ad7b2b
b8c1afe
 
 
0ad7b2b
b8c1afe
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad7b2b
 
 
 
 
 
 
b8c1afe
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import pandas as pd
from pathlib import Path
import os

LOG_FILE = Path("logs/api_requests.jsonl")
OUT_FILE = Path("monitoring/prod_data.csv")
MODE = os.getenv("PROD_MODE", "recent_half")  # all | recent_half

records = []

with open(LOG_FILE, "r", encoding="utf-8") as f:
    for line in f:
        record = json.loads(line)
        if record.get("event") == "prediction":
            records.append({
                "probability_default": record["output"]["probability_default"]
            })

df = pd.DataFrame(records)

if df.empty:
    raise ValueError("Aucune donnée de production trouvée (event=prediction dans les logs).")

# Par défaut: on prend la moitié la plus récente comme 'current' pour le drift
mode = MODE
if mode == "recent_half" and len(df) > 1:
    split_index = max(1, len(df) // 2)
    df = df.iloc[split_index:].reset_index(drop=True)

df.to_csv(OUT_FILE, index=False)
print(f"✅ Données de production exportées : {OUT_FILE}")