mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
feat(rules): refactor rules to be deterministic and add validation script
This commit is contained in:
1 parent
d2f543f19c
commit
49580ec010
2 files changed
+83
-59
No files matched your search
+10
-59
@@ -149,11 +149,11 @@ class RulesEngine:
|
||||
if wind_gust >= wind_threshold:
|
||||
force_closed = True
|
||||
reasons.append(
|
||||
f"Rachas de viento de {wind_gust:.1f} km/h superan el umbral de cierre de "
|
||||
f"{wind_threshold} km/h."
|
||||
f"Cierre forzoso por viento extremo: {wind_gust:.1f} km/h "
|
||||
f"(umbral histórico de seguridad: {wind_threshold} km/h)."
|
||||
)
|
||||
logger.info(
|
||||
"[%s] Rule 1 fired: wind gust %.1f > %.1f km/h -> force_closed",
|
||||
"[%s] Deterministic Rule: wind gust %.1f >= %.1f km/h -> force_closed",
|
||||
station_name,
|
||||
wind_gust,
|
||||
wind_threshold,
|
||||
@@ -168,76 +168,27 @@ class RulesEngine:
|
||||
force_closed = True
|
||||
km_factor = 0.0
|
||||
reasons.append(
|
||||
f"El espesor de nieve ({snow_depth:.1f} cm) está por debajo del mínimo "
|
||||
f"requerido ({min_snow} cm)."
|
||||
f"Espesor de nieve insuficiente ({snow_depth:.1f} cm) "
|
||||
f"para la apertura de pistas (mínimo requerido: {min_snow} cm)."
|
||||
)
|
||||
logger.info(
|
||||
"[%s] Rule 2 fired: snow depth %.1f < %.1f cm -> force_closed",
|
||||
"[%s] Deterministic Rule: snow depth %.1f < %.1f cm -> force_closed",
|
||||
station_name,
|
||||
snow_depth,
|
||||
min_snow,
|
||||
)
|
||||
|
||||
# ---- Rule 3: Heavy fresh snow + moderate wind -> likely open -----
|
||||
snowfall_24h = weather_data.get("snowfall_sum")
|
||||
wind_speed = weather_data.get("wind_gusts_10m_max", 0.0)
|
||||
|
||||
if (
|
||||
snowfall_24h is not None
|
||||
and snowfall_24h >= _HEAVY_FRESH_SNOW_THRESHOLD_CM
|
||||
and wind_speed is not None
|
||||
and wind_speed <= _MODERATE_WIND_THRESHOLD_KMH
|
||||
and not force_closed
|
||||
):
|
||||
force_open = True
|
||||
reasons.append(
|
||||
f"Nevada intensa ({snowfall_24h:.1f} cm en 24 h) con viento moderado "
|
||||
f"({wind_speed:.1f} km/h); es muy probable que la estación abra y esté concurrida."
|
||||
)
|
||||
logger.info(
|
||||
"[%s] Rule 3 fired: heavy snow %.1f cm + wind %.1f km/h -> force_open",
|
||||
station_name,
|
||||
snowfall_24h,
|
||||
wind_speed,
|
||||
)
|
||||
|
||||
# ---- Rule 4: Weekday + no fresh snow -> low crowd ----------------
|
||||
is_weekend = bool(weather_data.get("is_weekend", False))
|
||||
is_holiday = bool(weather_data.get("is_holiday", False))
|
||||
is_busy_day = is_weekend or is_holiday
|
||||
no_fresh_snow = (snowfall_24h is None or snowfall_24h < 5.0)
|
||||
|
||||
if not is_busy_day and no_fresh_snow and not force_closed:
|
||||
reasons.append(
|
||||
"Día laborable sin nevadas significativas; se espera un nivel de afluencia bajo."
|
||||
)
|
||||
logger.debug("[%s] Rule 4 fired: weekday + no fresh snow -> low crowd", station_name)
|
||||
|
||||
# ---- Rule 5: Weekend/holiday + fresh snow -> high crowd ----------
|
||||
if is_busy_day and snowfall_24h is not None and snowfall_24h >= 5.0 and not force_closed:
|
||||
reasons.append(
|
||||
f"Fin de semana o festivo con {snowfall_24h:.1f} cm de nieve fresca; "
|
||||
"se espera un nivel de afluencia alto."
|
||||
)
|
||||
logger.debug(
|
||||
"[%s] Rule 5 fired: busy day + fresh snow %.1f cm -> high crowd",
|
||||
station_name,
|
||||
snowfall_24h,
|
||||
)
|
||||
|
||||
# ---- Derive confidence -------------------------------------------
|
||||
if force_closed or force_open:
|
||||
# Confidence is 1.0 only if a deterministic closure rule fired.
|
||||
# Otherwise, confidence is 0.0, delegating all responsibility to ML.
|
||||
if force_closed:
|
||||
confidence = 1.0
|
||||
elif reasons:
|
||||
# Soft rules fired but no deterministic outcome
|
||||
confidence = 0.6
|
||||
else:
|
||||
# No rules fired; rules engine is inconclusive
|
||||
confidence = 0.0
|
||||
|
||||
result = {
|
||||
"force_closed": force_closed,
|
||||
"force_open": force_open,
|
||||
"force_open": False, # No force_open rules in this version
|
||||
"confidence": confidence,
|
||||
"reasons": reasons,
|
||||
"estimated_km_factor": km_factor,
|
||||
|
||||
Reference in new issue
Block a user