"""For a sensor of a station on a range: at each of its rejected instants, how many other sensors are rejected (out of those measured); a histogram. Usage: python3 shared.py """ import sys from collections import Counter from datetime import datetime, timezone from pathlib import Path ROOT = Path("/home/maxime/aimsight-optimizer") sys.path[:0] = [str(ROOT / "detectors" / "scripts"), str(ROOT / "tools" / "scripts")] from data import load, rejected # noqa: E402 folder, a, b, sensor = sys.argv[1:5] day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc) # noqa: E731 ms_all = load(folder) at = {} for s, ms in ms_all.items(): for m in ms: if day(a) <= m["t"] < day(b): at.setdefault(m["t"], {})[s] = rejected(m) hist = Counter() for t, r in sorted(at.items()): if r.get(sensor): others = {s: x for s, x in r.items() if s != sensor} hist[(sum(others.values()), len(others))] += 1 for (k, n), c in sorted(hist.items()): print(f"{k}/{n} others rejected: {c} instants")