feat: unified architecture and webcam archive optimization

- Refactor backend into a single process (FastAPI + APScheduler + Telegram Bot)
- Implement 'current_forecasts' and 'past_forecasts' architecture in storage
- Optimize historical webcam collector with date range discovery for Pajares, San Isidro, and Fuentes
- Clean up legacy scripts and tables (prediction_runs, prediction_stations)
- Update tests and operations documentation
This commit is contained in:
dasemu committed 2026-03-13 11:56:59 +01:00
1 parent a70eff3e45
commit f6a65f41d9
14 files changed
+563 -660

No files matched your search

+43 -56
View File
@@ -5,70 +5,57 @@ from __future__ import annotations
from storage import SQLiteStore
def test_prediction_run_roundtrip(tmp_path):
"""Prediction payloads must round-trip through SQLite unchanged."""
def test_current_forecasts_roundtrip(tmp_path):
"""Forecasts must round-trip through current_forecasts table."""
store = SQLiteStore(tmp_path / "skipredictor.db")
payload = {
"generated_at": "2026-03-13T10:00:00+00:00",
"prediction_date": "2026-03-14",
"stations": {
"pajares": {
"station_name": "Valgrande-Pajares",
"open_probability": 0.82,
"km_open": 12.4,
"crowd_level": "medium",
"weather_summary": "Temp -2-5 C",
"rule_overrides": ["Wind below threshold."],
"prediction_source": "ml",
}
},
}
forecasts = [
{
"station_id": "pajares",
"prediction_date": "2026-03-14",
"open_probability": 0.82,
"km_open": 12.4,
"crowd_level": "medium",
"weather_summary": "Temp -2-5 C",
"rule_notes": ["Wind below threshold."],
"prediction_source": "ml",
}
]
store.save_prediction_run(payload)
store.save_current_forecasts(forecasts, run_hour=10)
loaded = store.load_current_forecasts()
loaded = store.load_latest_predictions()
assert loaded == payload
assert len(loaded) == 1
row = loaded[0]
assert row["station_id"] == "pajares"
assert row["prediction_date"] == "2026-03-14"
assert row["open_probability"] == 0.82
assert row["km_open"] == 12.4
def test_load_predictions_for_date_ignores_newer_other_dates(tmp_path):
"""Date-specific loads must not be displaced by a newer run for tomorrow."""
def test_archive_moves_to_past_forecasts(tmp_path):
"""Archiving must move rows from current to past_forecasts."""
store = SQLiteStore(tmp_path / "skipredictor.db")
today_payload = {
"generated_at": "2026-03-13T06:00:00+00:00",
"prediction_date": "2026-03-13",
"stations": {
"pajares": {
"station_name": "Valgrande-Pajares",
"open_probability": 0.79,
"km_open": 10.1,
"crowd_level": "low",
"weather_summary": "Temp 0-5 C",
"rule_overrides": [],
"prediction_source": "ml",
}
},
}
tomorrow_payload = {
"generated_at": "2026-03-13T07:00:00+00:00",
"prediction_date": "2026-03-14",
"stations": {
"pajares": {
"station_name": "Valgrande-Pajares",
"open_probability": 0.88,
"km_open": 7.4,
"crowd_level": "medium",
"weather_summary": "Temp 2-7 C",
"rule_overrides": ["Warm rain expected."],
"prediction_source": "hybrid",
}
},
}
forecasts = [
{
"station_id": "pajares",
"prediction_date": "2026-03-14",
"open_probability": 0.79,
"km_open": 10.1,
"crowd_level": "low",
"weather_summary": "Temp 0-5 C",
"rule_notes": [],
"prediction_source": "ml",
}
]
store.save_prediction_run(today_payload)
store.save_prediction_run(tomorrow_payload)
store.save_current_forecasts(forecasts, run_hour=5)
archived = store.archive_current_forecasts()
loaded = store.load_predictions_for_date(prediction_date="2026-03-13")
assert loaded == today_payload
assert archived == 1
assert store.load_current_forecasts() == []
past = store.load_past_forecasts()
assert len(past) == 1
assert past[0]["station_id"] == "pajares"
def test_feature_importances_replace_latest_values(tmp_path):