# Label-by-label match: for each label, the detector events overlapping it (family, variety, bounds, sensors); then events overlapping no label. Args: detectors_dir station_folder labels.jsonl FROM TO [family] import json, sys from pathlib import Path det, folder, labels, a, b = sys.argv[1:6] fam = sys.argv[6] if len(sys.argv) > 6 else None sys.path.insert(0, str(Path(det) / "bench")) import score # noqa from data import load # noqa ms = load(folder) evs = score.events(ms, a, b, folder=folder) labs = [json.loads(l) for l in open(labels) if l.strip()] labs = [d for d in labs if d["start"] < b and d["end"] >= a] labs.sort(key=lambda d: d["start"]) def ov(x, y): return x["start"] <= y["end"] and x["end"] >= y["start"] for d in labs: if fam and d["family"] != fam: continue hit = [e for e in evs if e["start"] < d["end"] and e["end"] > d["start"]] print(f"{d['id']} {d['start']}→{d['end']} [{d['family']}]") for e in hit: mark = "=" if e["category"] == d["family"] else "x" lab = e["episodes"][0]["label"] print(f" {mark} {e['start']}→{e['end']} {e['category']} / {lab} ({len(e['sensors'])}: {','.join(e['sensors'][:6])})") print("\n# events overlapping no label of their family") for e in evs: same = [d for d in labs if d["family"] == e["category"] and d["start"] <= e["end"] and d["end"] >= e["start"]] if not same and (not fam or e["category"] == fam): others = [f"{d['id']}:{d['family']}" for d in labs if d["start"] <= e["end"] and d["end"] >= e["start"]] print(f" {e['start']}→{e['end']} {e['category']} / {e['episodes'][0]['label']} ({len(e['sensors'])}: {','.join(e['sensors'][:6])}) over {' '.join(others) or '-'}")