Skip to content

feat(14): Forecasting Engine — BAU Track#21

Open
shiniguchi wants to merge 18 commits intomainfrom
feature/phase-14-forecasting-engine-bau-track
Open

feat(14): Forecasting Engine — BAU Track#21
shiniguchi wants to merge 18 commits intomainfrom
feature/phase-14-forecasting-engine-bau-track

Conversation

@shiniguchi
Copy link
Copy Markdown
Owner

Summary

  • 6 SQL migrations (0050-0055): forecast_daily table, forecast_quality table, forecast_daily_mv + forecast_with_actual_v wrapper view, weather_climatology lookup, pg_cron forecast MV refresh (03:30 UTC), weekly yhat_samples janitor
  • 12 Python modules in scripts/forecast/: 5 model fits (SARIMAX, Prophet, ETS, Theta, Naive same-DoW), shared exog builder with 3-tier weather cascade, closed-day handling, sample path bootstrap, forecast writer, last-7-day evaluator, orchestrator (run_all.py), weather history backfill
  • GHA workflow forecast-refresh.yml at 01:00 UTC with workflow_dispatch for manual reruns
  • 39 unit tests covering utilities, model interfaces, and evaluation metrics

Closes requirements FCS-01 through FCS-11.

Test plan

  • python -m pytest scripts/forecast/tests/ -v — all tests pass (requires pip install -r scripts/forecast/requirements.txt)
  • CI guards pass (Guard 7: no tenant_id; Guard 8: no cron overlap)
  • supabase db push applies all 6 migrations without error
  • Manual workflow_dispatch of forecast-refresh.yml completes <15 min
  • forecast_with_actual_v returns rows scoped to JWT restaurant_id
  • forecast_quality populated after first nightly run

shiniguchi and others added 18 commits April 29, 2026 15:11
…e .gstack/

CSO audit findings:
- Pin cloudflare/wrangler-action to v3.9.0 SHA (deploy.yml)
- Pin supabase/setup-cli to v1.6.0 SHA (migrations.yml, tests.yml)
- Update postcss 8.5.9 → 8.5.12 (fixes GHSA-qx2v-qp2m-jg93)
- Add .gstack/ to .gitignore (security reports stay local)
Decisions: y=NaN + is_open regressor for closed days, 200 sample paths
with latest-run-only retention, 3-tier weather cascade (actual → forecast
→ climatology with 2021-01-01 Bright Sky backfill), env-var-only feature
flags (feature_flags table deferred to Phase 17).
Investigates statsmodels SARIMAX/ETS, prophet 1.3, statsforecast
Theta, sample-path generation patterns, exog matrix assembly, and
closed-day handling strategies for the nightly forecast pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…, cron jobs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
D-01: zero_closed_days() forces yhat/yhat_lower/yhat_upper=0 for closed
dates in exog model predictions (SARIMAX, Prophet).

D-03: build_open_day_series() filters training data to open days only;
map_open_predictions_to_calendar() maps predictions back to calendar
dates with 0 for closed days (ETS, Theta, Naive).

Also adds scripts/__init__.py to make the package importable.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…uard

- sarimax_fit.py: fit_sarimax() with configurable ARIMA + seasonal order,
  FCS-06 exog drift assertion, simulate() for sample paths, weather_source
  provenance signature
- 3 smoke tests: shape validation, exog column assertion, numeric dtype check
- prophet_fit.py: fit_prophet() with C-04 yearly_seasonality=False,
  9 regressor columns, NaN guard on future regressors,
  predictive_samples() for posterior sample paths
- 2 smoke tests: shape + yearly_seasonality verification, NaN rejection
ETS(A,A,A) with weekly seasonality via statsmodels ETSModel.
Returns point forecast (yhat/lower/upper) + simulated sample paths.
Non-exog model: takes clean open-day-only Series.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant