Files
aimsight-labeling/auto/revue-croisee/2026-11-04/finition/nordend/outils/resume_creux.py
T

42 lines
2.4 KiB
Python
Raw Normal View History

"""Pour chaque étiquette Thermal displacement de NORDEND et chaque capteur : l'écart horaire le plus fort (signé) des
10 premières heures, face au niveau des 5 dernières heures de l'étiquette (à défaut, sa médiane), en bruits, et son heure ;
puis ce qui en reste à 16 h et à 19 h. Seuls les écarts d'au moins 4 bruits sont écrits. Lit le cache de jours_td.py.
Les heures des gênes de toute la scène (GENES de jours_td.py) sont écartées.
Usage, depuis la racine : python3 <ce fichier> COLONNE [ID ...]"""
import json, os, pickle, statistics as st, sys
from datetime import timedelta
sys.path.insert(0, "agent-tools")
from donnees import instant # noqa: E402
H = timedelta(hours=1)
M, C, T = pickle.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache.pkl"), "rb"))
L = [json.loads(l) for l in open("labeling/auto/NORDEND.jsonl")]
GENES = (36, 38, 41, 42, 50, 52, 64, 79, 81, 88, 93)
AUTRES = [(instant(L[n - 1]["debut"]), instant(L[n - 1]["fin"])) for n in GENES]
libre = lambda t: not any(a < t < b for a, b in AUTRES)
col = sys.argv[1]
ids = [int(x.lstrip("#")) for x in sys.argv[2:]] or [i for i, l in enumerate(L, 1) if l["categorie"] == "Thermal displacement"]
caps = sorted(M, key=lambda s: (not s.startswith("CTR"), s))
for i in ids:
l = L[i - 1]
t0, t1 = instant(l["debut"]), instant(l["fin"])
out = []
for cap in caps:
pts = [(m["t"], m[col]) for m in M[cap] if m[col] is not None and t0 <= m["t"] <= t1 and libre(m["t"])]
if len(pts) < 8:
continue
nz = st.median(abs(pts[k + 1][1] - pts[k][1]) for k in range(len(pts) - 1)) or 1e-9
ref = [v for t, v in pts if t >= t1 - 5 * H]
b = st.median(ref) if len(ref) >= 4 else st.median(v for _, v in pts)
h = {}
for t, v in pts:
h.setdefault(t.replace(minute=0, second=0, microsecond=0), []).append(v)
hh = {k: (st.median(v) - b) / nz for k, v in h.items()}
jour = [(k, v) for k, v in hh.items() if k - t0 <= 10 * H]
if not jour:
continue
k, v = max(jour, key=lambda x: abs(x[1]))
if abs(v) >= 4:
r = lambda hr: next((f"{x:+.0f}" for kk, x in hh.items() if kk.hour == hr and kk.date() == t0.date()), "-")
out.append(f"{cap} {v:+.0f}@{k:%H}[16h {r(16)} 19h {r(19)}]")
print(f"#{i} {l['debut'][5:10]} {col} : " + ("; ".join(out) or "aucun"))