Files

32 lines
1.8 KiB
Python
Raw Normal View History

"""Per label: instants found by its family, and families flagged on it; per event: overlapping labels. Args: detectors_dir station labels from to [family]"""
import sys
from pathlib import Path
det, folder, lab, start, end = sys.argv[1:6]
fam = sys.argv[6] if len(sys.argv) > 6 else None
sys.path.insert(0, str(Path(det) / "bench")); sys.path.insert(0, str(Path(det) / "scripts"))
import score
from data import iso, load
ms = load(folder)
labels = score.read_labels(lab, start, end)
evts = score.events(ms, start, end, folder)
inst = sorted({iso(m["t"]) for v in ms.values() for m in v if start <= iso(m["t"]) < end})
print("== LABELS")
for e in sorted(labels, key=lambda e: e["start"]):
if fam and e["family"] != fam: 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"]]
hit = sum(any(v["category"] == e["family"] and v["start"] <= t <= v["end"] for v in evts) for t in ts)
other = {}
for t in ts:
for v in evts:
if v["start"] <= t <= v["end"] and v["category"] != e["family"]:
other[v["category"]] = other.get(v["category"], 0) + 1
print(f'{e["id"]:16} {e["start"][:16]} {e["end"][:16]} {e["family"]:20} {hit}/{len(ts)} other={other}')
print("== EVENTS (flagged instants not in a label of their family)")
for v in evts:
if fam and v["category"] != fam: continue
ts = [t for t in inst if v["start"] <= t <= v["end"] and t >= start]
ok = sum(any(e["family"] == v["category"] and e["start"] < t < e["end"] for e in labels) for t in ts)
if ok < len(ts):
ov = [e["id"] + ":" + e["family"][:5] for e in labels if e["start"] <= v["end"] and e["end"] >= v["start"]]
lbl = v.get("episodes", [{}])
print(f'{v["start"]} {v["end"]} {v["category"]:20} {ok}/{len(ts)} {v.get("text","")[:50]!r} {len(v.get("sensors",[]))}s ov={ov[:6]}')