feat(analysis): _max_zero_streak su flag fetch_ok
This commit is contained in:
@@ -126,6 +126,19 @@ def _expected_ticks(since: datetime, until: datetime) -> int:
|
|||||||
return math.ceil(span_seconds / (_TICK_INTERVAL_MIN * 60))
|
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, ...]:
|
def _detect_gaps(timestamps: list[datetime]) -> tuple[GapRecord, ...]:
|
||||||
"""Return gaps where consecutive timestamps differ by > threshold."""
|
"""Return gaps where consecutive timestamps differ by > threshold."""
|
||||||
out: list[GapRecord] = []
|
out: list[GapRecord] = []
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from datetime import UTC, datetime
|
|||||||
from cerbero_bite.analysis.data_audit import ( # noqa: PLC2701
|
from cerbero_bite.analysis.data_audit import ( # noqa: PLC2701
|
||||||
_detect_gaps,
|
_detect_gaps,
|
||||||
_expected_ticks,
|
_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),
|
datetime(2026, 5, 12, 12, 20, tzinfo=UTC),
|
||||||
]
|
]
|
||||||
assert _detect_gaps(ts) == ()
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user