feat(charting): unify configurable time windows

This commit is contained in:
Developer
2026-07-15 18:55:57 +00:00
parent 3871f24724
commit e0f66a51f7
25 changed files with 1607 additions and 1146 deletions
+21 -4
View File
@@ -14,16 +14,33 @@ from media_library_viewer_api.widgets.prometheus_range import (
class TestStepForWindow:
"""SC-104: every preset must yield 100300 points."""
"""SC-104: presets preserve usable resolution without sub-15s steps."""
@pytest.mark.parametrize("preset", sorted(WINDOW_PRESETS))
def test_presets_yield_in_band_point_counts(self, preset: str) -> None:
def test_presets_yield_supported_point_counts(self, preset: str) -> None:
window = WINDOW_PRESETS[preset]
step = step_for_window(window)
# Clamped minimum.
# The Prometheus-safe 15-second floor limits the two short presets to
# 20 and 60 points; all longer windows stay in the 100300 target band.
assert step >= 15
point_count = window // step
assert 100 <= point_count <= 300, f"{preset}: {point_count} points (step={step})"
assert min(100, window // 15) <= point_count <= 300, f"{preset}: {point_count} points (step={step})"
def test_window_presets_cover_the_shared_chart_windows(self) -> None:
assert WINDOW_PRESETS == {
"5m": 300,
"15m": 900,
"30m": 1_800,
"1h": 3_600,
"3h": 10_800,
"6h": 21_600,
"12h": 43_200,
"24h": 86_400,
"2d": 172_800,
"7d": 604_800,
"14d": 1_209_600,
"30d": 2_592_000,
}
def test_floor_of_fifteen_seconds(self) -> None:
# A tiny window that would otherwise produce a sub-15s step is clamped.