import numpy as np
import pandas as pd
from statsforecast import StatsForecast
from statsforecast.models import AutoTBATS, SeasonalNaive

# four weeks of hourly demand with a daily (24h) and a weekly (168h) cycle
rng = np.random.default_rng(42)
t = np.arange(24 * 7 * 4)
y = (100 + 0.02 * t + 15 * np.sin(2 * np.pi * t / 24) + 8 * np.sin(2 * np.pi * t / 168)
     + rng.normal(0, 3, t.size))
df = pd.DataFrame({"unique_id": "demand",
                   "ds": pd.date_range("2025-01-06", periods=t.size, freq="h"), "y": y})
train, test = df.iloc[:-48], df.iloc[-48:]

sf = StatsForecast(models=[AutoTBATS(season_length=[24, 168]), SeasonalNaive(season_length=168)],
                   freq="h")
fc = sf.forecast(df=train, h=48, level=[80])
for col in ["AutoTBATS", "SeasonalNaive"]:
    print(f"{col:14s} MAE {np.mean(np.abs(test['y'].values - fc[col].values)):.2f}")
print(fc[["ds", "AutoTBATS", "AutoTBATS-lo-80", "AutoTBATS-hi-80"]].head(3))
