Files
aimsight-detectors/scripts/no_data.py
T

20 lines
1.1 KiB
Python
Raw Normal View History

"""No data family: no measurement in the export for more than MISSING steps of its cadence (episodes.cadence), between two
2026-11-16 16:39:11 +01:00
measurements or, when the caller gives the end of the window read, between the last measurement and that end."""
from episodes import cadence, episode
2026-11-16 16:39:11 +01:00
MISSING = 2 # more than 2 missing steps is a hole (user's rule, 2026-10-23); also up to the end (CLARIDEN, batch 01)
2026-11-16 16:39:11 +01:00
def duration(d):
h, m = divmod(round(d.total_seconds() / 60), 60)
return f"{h} h {m:02d} min" if h else f"{m} min"
def detect(measurements, end=None):
ts = sorted({m["t"].replace(second=0, microsecond=0) for ms in measurements.values() for m in ms})
if len(ts) < 3:
return []
2026-11-16 16:39:11 +01:00
step = cadence(measurements)
holes = [(a, b, "") for a, b in zip(ts, ts[1:])] + ([(ts[-1], end, ", up to the end of the period")] if end else [])
return [episode(a, b, "No data", "No data", f"No measurement in the export for {duration(b - a)}{tail} (usually one "
f"every {duration(step)}).", [], False) for a, b, tail in holes if b - a > (MISSING + 1) * step]