feat: complete ML pipeline, FastAPI service, small model, tests, image

- finish the global HistGB bundle, scenario forecasts and 28-day ablation
- export sensors/series/forecasts/metrics/context plus baked weather frames
- add FastAPI health/meta/predict/simulate and background /train jobs
- add the p75 busy classifier, retraining from CSV, and hot-swap persistence
- add pytest coverage, multi-stage non-root Dockerfile, README and model card

Holdout: weather 7d MAE 3.32 / WAPE 27.5% / R2 0.777 vs seasonal naive
MAE 4.23 / WAPE 35.0% / R2 0.656 (5,350 eval rows).
This commit is contained in:
Noel Sabia committed 2026-11-14 05:01:16 +01:00
1 parent 68402803b2
commit 939a8db482
43 files changed
+4090 -105

No files matched your search

+5 -5
View File
@@ -10,7 +10,7 @@ from __future__ import annotations
import json
import logging
import time
from datetime import date, datetime, timedelta, timezone
from datetime import UTC, date, datetime, timedelta
from pathlib import Path
import httpx
@@ -40,7 +40,7 @@ def _get_json(url: str, params: dict, *, retries: int = 3) -> dict:
if payload.get("error"):
raise RuntimeError(f"Open-Meteo error: {payload.get('reason', payload)}")
return payload
except Exception as exc: # network / HTTP / payload
except Exception as exc: # noqa: BLE001 - network/HTTP/payload retry boundary
last = exc
if attempt < retries - 1:
time.sleep(2**attempt)
@@ -113,7 +113,7 @@ def fetch_forecast(days: int = 8) -> tuple[pd.DataFrame, dict, dict]:
}
grid = {"latitude": payload.get("latitude"), "longitude": payload.get("longitude")}
meta = {
"fetched_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"fetched_at": datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ"),
"current": now,
"grid": grid,
"source": "open-meteo",
@@ -158,7 +158,7 @@ def ensure_weather(
if not meta:
meta = {
"fetched_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"fetched_at": datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ"),
"current": None,
"grid": {"latitude": config.LATITUDE, "longitude": config.LONGITUDE},
"source": "cache",
@@ -181,7 +181,7 @@ def load_cached_weather() -> tuple[pd.DataFrame, pd.DataFrame, dict]:
def refresh_weather() -> None:
archive, forecast, meta = ensure_weather(refresh=True)
archive, forecast, _ = ensure_weather(refresh=True)
log.info("weather refreshed: archive=%s forecast=%s", len(archive), len(forecast))