Files
aimsight-detectors/bench/sensors.py
T
maximeandClaude Opus 5.5 5e9a7aa9d1 The single reader: data.py of the tools repository (sibling ~/aimsight-tools), located once in categories.py
scripts/data.py removed; the detectors' standalone CLIs go (categories.py runs them).
Benchmark identical to the baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:25:01 +01:00

32 lines
1.8 KiB
Python

"""For the upgrader: the cadence of the measurements of the range, the number of targets and references, then each event
of the range with its sensors (categories.py only gives their number). Same computation as categories.py without
--chunk (3 days of history).
Usage: python3 sensors.py <folder> --from YYYY-MM-DD --to YYYY-MM-DD
"""
import argparse
import statistics
import sys
from datetime import datetime, timedelta, timezone
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import categories # noqa: E402
from data import iso, load # noqa: E402 (the tools repository's reader, on the path through categories)
p = argparse.ArgumentParser(usage=__doc__)
p.add_argument("folder")
p.add_argument("--from", dest="start", required=True)
p.add_argument("--to", dest="end", required=True)
a = p.parse_args()
day = lambda d: datetime.strptime(d[:10], "%Y-%m-%d").replace(tzinfo=timezone.utc) # noqa: E731
start, end = day(a.start), day(a.end)
batch = {s: k for s, ms in load(a.folder).items() if (k := [m for m in ms if start - timedelta(days=3) <= m["t"] < end])}
ts = sorted({m["t"] for ms in batch.values() for m in ms if m["t"] >= start})
steps = [(y - x).total_seconds() / 60 for x, y in zip(ts, ts[1:])]
print(f"cadence: {statistics.median(steps):.0f} min (median of the steps between measurements)" if steps else "cadence: no measurement")
refs = sum(ms[0]["pattern_type"] == "global_ref" for ms in batch.values())
print(f"sensors: {len(batch) - refs} targets, {refs} references")
for v in (v for v in categories.events(batch, end, a.folder) if v["end"] >= iso(start)) if batch else []:
print(v["start"], "→", v["end"], f"{v['category']:<20}", "|", v["episodes"][0]["label"], "|",
", ".join(sorted(v["sensors"])) or "all sensors")