fix: add slm start time grace_minutes=15 grace period to include data starting at start time.
This commit is contained in:
@@ -119,10 +119,18 @@ def _filter_rnd_rows(
|
||||
filter_start_date: str,
|
||||
filter_end_date: str,
|
||||
) -> list[dict]:
|
||||
"""Filter RND data rows by time window and/or date range. Handles overnight ranges."""
|
||||
"""Filter RND data rows by time window and/or date range. Handles overnight ranges.
|
||||
|
||||
Grace window: intervals starting up to 15 minutes before the filter start time are
|
||||
included. This covers the common case where a unit is deployed slightly early
|
||||
(e.g. set up at 6:50 for a 7:00 PM start) and the first interval begins just before
|
||||
the nominal window. The grace window applies only to the start boundary.
|
||||
"""
|
||||
if not filter_start_time and not filter_end_time and not filter_start_date and not filter_end_date:
|
||||
return rows
|
||||
|
||||
_GRACE_MINUTES = 15
|
||||
|
||||
filtered = []
|
||||
|
||||
start_hour = start_minute = end_hour = end_minute = None
|
||||
@@ -174,14 +182,23 @@ def _filter_rnd_rows(
|
||||
row_time_minutes = row_hour * 60 + row_minute
|
||||
start_time_minutes = start_hour * 60 + start_minute
|
||||
end_time_minutes = end_hour * 60 + end_minute
|
||||
# Effective start allows up to 15 min early (wraps midnight correctly)
|
||||
effective_start = (start_time_minutes - _GRACE_MINUTES) % (24 * 60)
|
||||
|
||||
if start_time_minutes > end_time_minutes:
|
||||
# Overnight range (e.g., 19:00-07:00)
|
||||
if not (row_time_minutes >= start_time_minutes or row_time_minutes < end_time_minutes):
|
||||
# With grace: effective start may be e.g. 18:45
|
||||
if effective_start > end_time_minutes:
|
||||
# Grace window doesn't wrap past midnight itself
|
||||
in_window = (row_time_minutes >= effective_start or row_time_minutes < end_time_minutes)
|
||||
else:
|
||||
# Grace window wraps midnight (rare: start near 00:00)
|
||||
in_window = (row_time_minutes >= effective_start and row_time_minutes < end_time_minutes)
|
||||
if not in_window:
|
||||
continue
|
||||
else:
|
||||
# Same-day range (e.g., 07:00-19:00)
|
||||
if not (start_time_minutes <= row_time_minutes < end_time_minutes):
|
||||
if not (effective_start <= row_time_minutes < end_time_minutes):
|
||||
continue
|
||||
|
||||
filtered.append(row)
|
||||
|
||||
Reference in New Issue
Block a user