Files
Support-Agent/labeling/auto/revue-croisee/2026-11-04/carte/outils/rattacher_events.py
T

42 lines
1.8 KiB
Python
Raw Normal View History

"""Rattacher chaque event (noms codés) à sa station de data/ : mêmes instants, mêmes valeurs.
python3 labeling/auto/revue-croisee/2026-11-04/carte/outils/rattacher_events.py
Pour chaque event : la station dont les mesures ont le même time_utc et la même error_value,
et la table capteur codé -> capteur réel (par x, y au même instant).
"""
import csv
import glob
import os
RACINE = os.path.join(os.path.dirname(__file__), *[".."] * 6)
def lignes(chemin):
with open(chemin, encoding="utf-8") as f:
yield from csv.DictReader(f)
for ev in sorted(glob.glob(f"{RACINE}/events/E-*/")):
nom = os.path.basename(ev.rstrip("/"))
fichiers = sorted(glob.glob(f"{ev}displacement/*advanced*.csv"))
if not fichiers:
print(nom, ": pas de fichier advanced")
continue
codees = {}
for l in lignes(fichiers[0]):
if l["error_value"]:
codees[(l["time_utc"], l["error_value"])] = l["sensor_name"].strip()
jours = sorted({t[:10].replace("-", "") for t, _ in codees})
trouve = {}
for station in sorted(os.listdir(f"{RACINE}/data")):
for jour in jours[:3]:
for chemin in glob.glob(f"{RACINE}/data/{station}/displacement/*_{jour}.csv"):
for l in lignes(chemin):
code = codees.get((l["time_utc"], l["error_value"]))
if code:
trouve.setdefault(station, {})[code] = l["sensor_name"].strip()
if not trouve:
print(nom, ": aucune station de data/ (jours", jours[0], "à", jours[-1], ")")
for station, table in trouve.items():
print(nom, "->", station, f"({len(table)} capteurs) :",
", ".join(f"{c}={r}" for c, r in sorted(table.items(), key=lambda x: (x[0][0], int(x[0][1:]) if x[0][1:].isdigit() else 0))))