Files
aimsight-optimizer/outils/non_couverts.py
T

51 lines
2.5 KiB
Python

# Les instants anormaux (rejets non habituels, cibles qui sautent face à leur niveau local) qu'aucune étiquette de la vérité ne couvre, toutes stations (JOUR=AAAA-MM-JJ) ; une étiquette ne couvre que ses capteurs (lus dans « Détecteurs : variété, capteurs ») ; « N capteurs », « tous » ou une ligne du scanner couvrent tout ; une référence rejetée couverte couvre les sauts de l'instant. Hors Thermal. STATION... (JOUR=AAAA-MM-JJ).
import json, re, statistics, sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # outils.py, à côté
from outils import D, B, RACINE, station, bruit, hhmm, rejected, iso
BATCH = RACINE / "batches" / iso(D)[:10]
K, N = 10, 3
def capteurs(e):
m = re.match(r"Détecteurs : [^,]+, (.*?)(, grisé)?\. ", e["description"])
if not m or re.fullmatch(r"\d+ capteurs|tous les capteurs", m.group(1)):
return None # tout
return set(m.group(1).split(", "))
for nom in sys.argv[1:]:
labels = [json.loads(l) for l in open(BATCH / "verite" / f"{nom}.jsonl") if l.strip()]
labels = [(e, capteurs(e)) for e in labels if e["categorie"] != "Thermal displacement"]
m, refs = station(nom)
jour = {s: [x for x in ms if D <= x["t"] < B] for s, ms in m.items()}
habituel = {s for s, ms in jour.items() if ms and sum(map(rejected, ms)) > 0.5 * len(ms)}
sauts, rej = {}, {}
for s, ms in jour.items():
for x in ms:
if rejected(x) and s not in habituel:
rej.setdefault(x["t"], set()).add(s)
if s in refs:
continue
for col in ("corr_x", "corr_y"):
b = bruit(m[s], col, 10)
if not b:
continue
for i, x in enumerate(ms):
v = [y[col] for y in ms[max(0, i - 6):i] + ms[i + 1:i + 7] if y[col] is not None]
if x[col] is not None and len(v) >= 4 and abs(x[col] - statistics.median(v)) > K * b:
sauts.setdefault(x["t"], set()).add(s)
print(f"== {nom} (rejet habituel : {sorted(habituel)})")
for t in sorted(set(sauts) | set(rej)):
S, r = set(sauts.get(t, ())), set(rej.get(t, ()))
if len(S) < N and not r:
continue
for e, c in labels:
if e["debut"] <= iso(t) <= e["fin"]:
if c is None:
S, r = set(), set()
break
if c & r & refs:
S = set()
S -= c; r -= c
if len(S) >= N or r:
print(f" {hhmm(t)} sauts={len(S)} rejets={sorted(r)[:5]}")