21 lines
1.2 KiB
Python
21 lines
1.2 KiB
Python
"""Per label of a range: its instants (bounds excluded, as score.py), how many the detectors flag in its family, and the families flagged there instead. Args: <detectors> <station folder> <labels.jsonl> <from YYYY-MM-DD> <to YYYY-MM-DD> [family]"""
|
|||
|
|
import sys
|
||
|
|
from collections import Counter
|
||
|
|
from pathlib import Path
|
||
|
|
det = Path(sys.argv[1]).resolve()
|
||
|
|
sys.path[:0] = [str(det / "bench"), str(det / "scripts")]
|
||
|
|
import score # noqa
|
||
|
|
from data import iso, load, parse_time # noqa
|
||
|
|
folder, lab, a, b = sys.argv[2], sys.argv[3], sys.argv[4] + "T00:00Z", sys.argv[5] + "T00:00Z"
|
||
|
|
ms = load(folder)
|
||
|
|
labels = score.read_labels(lab, a, b)
|
||
|
|
ev = score.events(ms, a, b, folder)
|
||
|
|
inst = sorted({iso(m["t"]) for v in ms.values() for m in v if a <= iso(m["t"]) < b})
|
||
|
|
for e in labels:
|
||
|
|
if len(sys.argv) > 6 and e["family"] != sys.argv[6]:
|
||
|
|
continue
|
||
|
|
ts = [t for t in inst if e["start"] < t < e["end"]] or [t for t in inst if e["start"] <= t <= e["end"]]
|
||
|
|
fam = [{v["category"] for v in ev if v["start"] <= t <= v["end"]} for t in ts]
|
||
|
|
hit = sum(e["family"] in f for f in fam)
|
||
|
|
other = Counter(c for f in fam for c in f if c != e["family"])
|
||
|
|
print(f'{e["id"]:<16} {e["start"][5:16]} {e["family"]:<20} {hit}/{len(ts)} others: {dict(other)}')
|