2026-11-14 15:47:51 +01:00
# 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é
2026-11-14 15:18:26 +01:00
from outils import D , B , RACINE , station , bruit , hhmm , rejected , iso
BATCH = RACINE / "batches" / iso ( D )[: 10 ]
2026-11-14 15:47:51 +01:00
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 :]:
2026-11-14 15:18:26 +01:00
labels = [ json . loads ( l ) for l in open ( BATCH / "verite" / f " { nom } .jsonl" ) if l . strip ()]
2026-11-14 15:47:51 +01:00
labels = [( e , capteurs ( e )) for e in labels if e [ "categorie" ] != "Thermal displacement" ]
2026-11-14 15:18:26 +01:00
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 )}
2026-11-14 15:47:51 +01:00
sauts , rej = {}, {}
2026-11-14 15:18:26 +01:00
for s , ms in jour . items ():
2026-11-14 15:47:51 +01:00
for x in ms :
if rejected ( x ) and s not in habituel :
rej . setdefault ( x [ "t" ], set ()) . add ( s )
2026-11-14 15:18:26 +01:00
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 ):
2026-11-14 15:47:51 +01:00
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 :
2026-11-14 15:18:26 +01:00
continue
2026-11-14 15:47:51 +01:00
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 ] } " )