# Per label of a range: share of its instants flagged in its family, and which families the detectors put there; then per # event: share of its instants inside a label of its family. Args: FROM TO import sys from pathlib import Path sys.path.insert(0, str(Path(sys.argv[1]).resolve() / "bench")) import score # noqa: E402 from data import iso, load, parse_time # noqa: E402 det, folder, lab, a, b = sys.argv[1:6] start, end = iso(parse_time(a)), iso(parse_time(b)) 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}) fl = {t: {v["category"] for v in evts if v["start"] <= t <= v["end"]} for t in inst} print("== labels") for e in labels: ts = [t for t in inst if e["start"] < t < e["end"]] hit = sum(e["family"] in fl[t] for t in ts) other = {} for t in ts: for c in fl[t] - {e["family"]}: other[c] = other.get(c, 0) + 1 print(f"{e['id']:<15} {e['start'][5:16]} {e['end'][5:16]} {e['family']:<20} {hit}/{len(ts)} other: {other}") print("== events") for v in evts: ts = [t for t in inst if v["start"] <= t <= v["end"]] 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): ids = sorted({e["id"] + ":" + e["family"][:4] for e in labels for t in ts if e["start"] < t < e["end"]}) print(f"{v['start'][5:16]} {v['end'][5:16]} {v['category']:<20} {v['episodes'][0]['label']:<28} wrong {len(ts)-ok}/{len(ts)} labels: {' '.join(ids)[:150]}")