Files

21 lines
1.1 KiB
Python

"""No data family: no measurement in the export for more than MISSING steps of its cadence (episodes.cadence), between two
measurements or, when the caller gives the end of the window read, between the last measurement and that end."""
from episodes import cadence, episode
MISSING = 2 # more than 2 missing steps is a hole (user's rule, 2026-10-23); also up to the end (CLARIDEN, batch 01)
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 []
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]