mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
Merge branch 'feature/weather-sky-snow-type'
This commit is contained in:
commit
2e40eee95a
10 files changed
+128
-1
No files matched your search
@@ -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"
|
||||
Reference in new issue
Block a user