feat(weather): add sky conditions and snow type to predictions

Add WMO weather_code from Open-Meteo to derive sky conditions
(sunny/cloudy/foggy/storm) and infer snow type (powder/hard/wet/spring)
from temperature and snowfall data. Both fields flow through the full
pipeline: weather API, hybrid predictor, SQLite storage, REST API
schemas, Telegram bot messages, and scheduler tasks.
This commit is contained in:
dasemu committed 2026-03-17 17:54:43 +01:00
1 parent 5e2a22340f
commit 70e3a1cf92
10 files changed
+128 -1

No files matched your search

+52
View File
@@ -64,8 +64,15 @@ def _build_weather_summary(weather_data: dict[str, Any]) -> str:
A single-line string summarising the most operationally relevant
weather factors present in the data.
"""
from data_sources.weather_api import wmo_code_to_sky_condition
parts: list[str] = []
weather_code = weather_data.get("weather_code")
if weather_code is not None:
sky = wmo_code_to_sky_condition(weather_code)
parts.append(sky.capitalize())
temp_max = weather_data.get("temperature_2m_max")
temp_min = weather_data.get("temperature_2m_min")
if temp_max is not None and temp_min is not None:
@@ -181,8 +188,12 @@ class HybridPredictor:
Raises:
ValueError: If station_id is not found in the configuration.
"""
from data_sources.weather_api import wmo_code_to_sky_condition
station_name = _load_station_name(station_id, self._config_path)
weather_summary = _build_weather_summary(weather_data)
sky_condition = wmo_code_to_sky_condition(weather_data.get("weather_code"))
snow_type = self._infer_snow_type(weather_data)
logger.info("HybridPredictor.predict called for station '%s'.", station_name)
@@ -238,6 +249,8 @@ class HybridPredictor:
"open_probability": round(open_probability, 4),
"km_open": round(km_open, 2),
"crowd_level": crowd_level,
"sky_condition": sky_condition,
"snow_type": snow_type,
"weather_summary": weather_summary,
"rule_overrides": rule_reasons,
"prediction_source": prediction_source,
@@ -450,3 +463,42 @@ class HybridPredictor:
exc,
)
return 10.0
@staticmethod
def _infer_snow_type(weather_data: dict[str, Any]) -> str:
"""Infer snow type from weather conditions.
Uses temperature, snowfall and humidity to estimate snow quality:
- Cold temp + fresh snow = "polvo" (powder)
- Warm temp + snow = "humeda" (wet)
- Very cold + no fresh snow = "dura" (hard/icy)
- Warm temp + no fresh snow = "primavera" (spring)
If the Infonieve ``calidadnieve`` field is present it is used directly.
Args:
weather_data: Dict of weather variables for the prediction day.
Returns:
A snow type label in Spanish (e.g. ``"polvo"``, ``"dura"``).
"""
# If Infonieve provided snow quality directly, use it
if weather_data.get("calidadnieve"):
return str(weather_data["calidadnieve"]).lower()
temp_max = weather_data.get("temperature_2m_max")
snowfall = weather_data.get("snowfall_sum", 0) or 0
if temp_max is None:
return "desconocido"
if snowfall > 0:
if temp_max < 0:
return "polvo"
return "húmeda"
if temp_max < -2:
return "dura"
if temp_max > 8:
return "primavera"
return "dura"