mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-27 07:46:22 +00:00
fix(setup): enforce webcam crowd labels
This commit is contained in:
1 parent
f6a65f41d9
commit
f63913b23c
5 files changed
+261
-31
No files matched your search
@@ -0,0 +1,86 @@
|
||||
"""Tests for scripts/build_full_dataset.py crowd-label logic."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from scripts.build_full_dataset import _load_webcam_crowd_labels, load_station_data
|
||||
|
||||
|
||||
class _FakeStore:
|
||||
"""Minimal store stub for dataset-builder tests."""
|
||||
|
||||
def __init__(self, station_df: pd.DataFrame, crowd_df: pd.DataFrame):
|
||||
self._station_df = station_df
|
||||
self._crowd_df = crowd_df
|
||||
|
||||
def load_historical_station_raw(self) -> pd.DataFrame:
|
||||
return self._station_df.copy()
|
||||
|
||||
def load_crowd_analyses(self, **_: object) -> pd.DataFrame:
|
||||
return self._crowd_df.copy()
|
||||
|
||||
|
||||
def _station_raw_row() -> pd.DataFrame:
|
||||
return pd.DataFrame(
|
||||
{
|
||||
"date": ["2026-03-10"],
|
||||
"station_id": ["pajares"],
|
||||
"idestado": [1.0],
|
||||
"kmopen": [20.0],
|
||||
"pistasopen": [30.0],
|
||||
"pistastotal": [40.0],
|
||||
"espesormax": [120.0],
|
||||
"calidadnieve": ["polvo"],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_crowd_level_is_sourced_from_webcam_labels():
|
||||
"""Crowd labels must be read from crowd_analysis data."""
|
||||
crowd_df = pd.DataFrame(
|
||||
{
|
||||
"analyzed_at": ["2026-03-10T10:00:00"],
|
||||
"analysis_date": ["2026-03-10"],
|
||||
"station_id": ["pajares"],
|
||||
"crowd_density": ["low"],
|
||||
}
|
||||
)
|
||||
store = _FakeStore(_station_raw_row(), crowd_df)
|
||||
|
||||
result = load_station_data(store)
|
||||
|
||||
assert result.iloc[0]["crowd_level"] == "low"
|
||||
assert result.iloc[0]["crowd_level_source"] == "webcam"
|
||||
|
||||
|
||||
def test_crowd_level_is_missing_when_webcam_label_is_missing():
|
||||
"""Without webcam data, crowd labels must remain null."""
|
||||
store = _FakeStore(_station_raw_row(), pd.DataFrame())
|
||||
|
||||
result = load_station_data(store)
|
||||
|
||||
assert pd.isna(result.iloc[0]["crowd_level"])
|
||||
assert pd.isna(result.iloc[0]["crowd_level_source"])
|
||||
|
||||
|
||||
def test_load_webcam_labels_keeps_latest_valid_label_per_day():
|
||||
"""The latest valid label must be used when multiple rows exist per day."""
|
||||
crowd_df = pd.DataFrame(
|
||||
{
|
||||
"analyzed_at": [
|
||||
"2026-03-10T09:00:00",
|
||||
"2026-03-10T10:00:00",
|
||||
"2026-03-10T11:00:00",
|
||||
],
|
||||
"analysis_date": ["2026-03-10", "2026-03-10", "2026-03-10"],
|
||||
"station_id": ["pajares", "pajares", "pajares"],
|
||||
"crowd_density": ["low", "medium", "unknown"],
|
||||
}
|
||||
)
|
||||
store = _FakeStore(_station_raw_row(), crowd_df)
|
||||
|
||||
labels = _load_webcam_crowd_labels(store)
|
||||
|
||||
assert len(labels) == 1
|
||||
assert labels.iloc[0]["webcam_crowd_level"] == "medium"
|
||||
Reference in new issue
Block a user