- 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).
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
CONTROL_TOKEN = "test-token"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def client(tmp_path_factory):
|
|
os.environ["CONTROL_TOKEN"] = CONTROL_TOKEN
|
|
os.environ["PULSECAST_MODELS"] = str(tmp_path_factory.mktemp("models"))
|
|
os.environ["PULSECAST_UPLOADS"] = str(tmp_path_factory.mktemp("uploads"))
|
|
from pulsecast.server import app
|
|
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def auth_headers() -> dict[str, str]:
|
|
return {"Authorization": f"Bearer {CONTROL_TOKEN}"}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def synthetic_csv(tmp_path_factory) -> Path:
|
|
"""Two sensors, 60 days hourly, clear daily/weekly pattern + weather."""
|
|
rng = np.random.default_rng(7)
|
|
hours = pd.date_range("2026-06-01", periods=24 * 60, freq="h", tz="UTC")
|
|
rows = []
|
|
for sensor in ("test-store-a", "test-store-b"):
|
|
for timestamp in hours:
|
|
local = timestamp.tz_convert("Europe/Berlin")
|
|
daily = 35.0 * np.exp(-((local.hour - 19) ** 2) / 18.0)
|
|
weekend = 12.0 if local.day_of_week == 5 else 0.0
|
|
value = max(0.0, 8.0 + daily + weekend + rng.normal(0, 4))
|
|
rows.append(
|
|
{
|
|
"time": timestamp.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"sensor": sensor,
|
|
"value": round(value, 3),
|
|
"temp_c": round(15.0 + rng.normal(0, 5), 2),
|
|
"precip_mm": round(max(0.0, rng.normal(0, 1)), 2),
|
|
}
|
|
)
|
|
path = tmp_path_factory.mktemp("csv") / "upload.csv"
|
|
pd.DataFrame(rows).to_csv(path, index=False)
|
|
return path
|