"""Pour une cible, dans quelles étiquettes (Visibility, Obstruction, No data de moins de trois jours) tombent ses rejets, et si l'étiquette la nomme. Usage : python3 dans.py STATION CAPTEUR [DEBUT] [FIN]""" import csv, glob, json, sys, collections from datetime import datetime st, cap = sys.argv[1], sys.argv[2] d0, d1 = (sys.argv[3:5] + ['2026-10-01', '2026-11-01'])[:2] if len(sys.argv) > 3 else ('2026-10-01', '2026-11-01') t = lambda s: datetime.fromisoformat(s.replace('Z', '+00:00').replace(' ', 'T')) lab = [(n, json.loads(l)) for n, l in enumerate(open(f'labeling/auto/{st}.jsonl'), 1) if l.strip()] lab = [(n, e, t(e['debut']), t(e['fin'])) for n, e in lab if e['categorie'] in ('Visibility', 'Obstruction', 'No data') and (t(e['fin']) - t(e['debut'])).days < 3] c = collections.Counter(); hors = [] for p in sorted(glob.glob(f'data/{st}/displacement/{st}_advanced_2026*.csv')): for l in csv.DictReader(open(p)): if l['sensor_name'].strip() != cap or not l['error_value'] or float(l['error_value']) <= float(l['error_threshold']): continue i = t(l['time_utc'][:19] + '+00:00') if not (t(d0 + 'T00:00Z') <= i < t(d1 + 'T00:00Z')): continue k = [n for n, e, a, b in lab if a < i < b] if k: c[k[0]] += 1 else: hors.append(i.strftime('%m-%d %H:%M')) d = {n: e for n, e, a, b in lab} for n, k in sorted(c.items()): e = d[n]; print(f"#{n}\t{k}\t{e['categorie']}\t{e['debut']}\t{e['fin']}\t{'nommée' if cap in e['description'] else 'NON NOMMÉE'}\t{e['description'][:90]}") print('hors étiquettes :', len(hors), ' '.join(hors))