fix: guard local-day pruning across monitoring gaps (#100)

This commit is contained in:
xavierk
2026-09-28 14:37:22 +05:30
parent d69753690a
commit 5aeee7b6f1
2 changed files with 86 additions and 1 deletions
+24 -1
View File
@@ -143,6 +143,24 @@ def _contains_instant(
return bounds is not None and bounds[0] <= instant < bounds[1]
def _monitoring_period_covers(
conn: sqlite3.Connection,
start: datetime,
end: datetime,
) -> bool:
"""Require continuous monitoring before a local-day total replaces detail."""
for started_at, ended_at in conn.execute(
"SELECT started_at, ended_at FROM monitoring_periods"
):
period_start = _parse_sample_time(started_at)
period_end = _parse_sample_time(ended_at) if ended_at is not None else None
if period_start is None or period_start > start:
continue
if ended_at is None or (period_end is not None and end <= period_end):
return True
return False
def _has_local_replacement(
conn: sqlite3.Connection,
previous: tuple,
@@ -157,7 +175,12 @@ def _has_local_replacement(
start_id, end_id = previous[0], current[0]
segment_id = current[2]
if start_tz and start_tz == end_tz and segment_id is not None:
if (
start_tz
and start_tz == end_tz
and segment_id is not None
and _monitoring_period_covers(conn, start, end)
):
known_days = conn.execute(
"SELECT local_days.utc_start, local_days.utc_end "
"FROM local_days JOIN local_day_segment_totals "