feat(analysis): _max_zero_streak su flag fetch_ok

This commit is contained in:
root
2026-05-13 09:31:38 +00:00
parent 75fe803296
commit aeac8f2a95
2 changed files with 30 additions and 0 deletions
+13
View File
@@ -126,6 +126,19 @@ def _expected_ticks(since: datetime, until: datetime) -> int:
return math.ceil(span_seconds / (_TICK_INTERVAL_MIN * 60))
def _max_zero_streak(flags: list[int]) -> int:
"""Longest run of consecutive zeros."""
longest = 0
current = 0
for v in flags:
if v == 0:
current += 1
longest = max(longest, current)
else:
current = 0
return longest
def _detect_gaps(timestamps: list[datetime]) -> tuple[GapRecord, ...]:
"""Return gaps where consecutive timestamps differ by > threshold."""
out: list[GapRecord] = []
+17
View File
@@ -7,6 +7,7 @@ from datetime import UTC, datetime
from cerbero_bite.analysis.data_audit import ( # noqa: PLC2701
_detect_gaps,
_expected_ticks,
_max_zero_streak,
)
@@ -77,3 +78,19 @@ def test_detect_gaps_ignores_threshold_boundary() -> None:
datetime(2026, 5, 12, 12, 20, tzinfo=UTC),
]
assert _detect_gaps(ts) == ()
def test_max_zero_streak_empty() -> None:
assert _max_zero_streak([]) == 0
def test_max_zero_streak_no_zeros() -> None:
assert _max_zero_streak([1, 1, 1, 1]) == 0
def test_max_zero_streak_single_zero_block() -> None:
assert _max_zero_streak([1, 0, 0, 0, 1, 0, 1]) == 3
def test_max_zero_streak_all_zeros() -> None:
assert _max_zero_streak([0, 0, 0]) == 3