# Every Brief obstruction episode of visibility.py over each station's label range: its share of the sensors measured at that instant, and the label families covering it; a table share bucket x family per station. Args: 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, visibility # noqa: E402 from regression import label_range # noqa: E402 from data import iso, load, parse_time # noqa: E402 tot = Counter() for path in sorted(Path(sys.argv[2]).glob("*.jsonl")): folder = Path(sys.argv[3]) / path.stem if not folder.is_dir(): continue start, end = label_range(path) ms = load(str(folder)) h = parse_time(start) - score.HISTORY chunk = {s: k for s, v in ms.items() if (k := [m for m in v if h <= m["t"] < parse_time(end)])} labels = score.read_labels(str(path), start, end) present = {} for s, v in chunk.items(): for m in v: if m["error_value"] is not None: present.setdefault(iso(m["t"]), set()).add(s) c = Counter() for e in visibility.detect(chunk): if e["label"] != "Brief obstruction" or e["start"] < start: continue t = e["start"] share = len(e["sensors"]) / max(1, len(present.get(t, ()))) b = "<1/4" if share < .25 else "1/4-1/2" if share < .5 else "1/2-3/4" if share < .75 else ">=3/4" fam = ",".join(sorted({l["family"] for l in labels if l["start"] < t < l["end"]} - {"Thermal displacement", "Target issue"})) or "-" c[(b, fam)] += 1 tot[(b, fam)] += 1 print(path.stem, dict(sorted(c.items()))) print("TOTAL") for k, v in sorted(tot.items()): print(" ", k, v)