Skip to content

Forecast Engine (TypeScript)

TÓM TẮT

forecastEngine.ts (~800+ dòng, 50KB) là frontend forecast orchestrator. Kết hợp BAU baseline (Holt-Winters) + Event Impact (calendar weights) + ML Model Results (from Supabase) để tạo daily forecast.

File: src/services/modules/forecast/forecastEngine.ts

Sub-modules (15 files)

ModuleFileMô tả
Core EngineforecastEngine.tsMain orchestrator (~50KB)
BAU BaselinebaselineCalculator.tsHolt-Winters exponential smoothing
Exponential SmoothingexponentialSmoothing.tsCore HW implementation
EnsembleensembleForecaster.tsMulti-model ensemble weights
Decision TreedecisionTree.tsStaffing decision rules
Anomaly DetectionanomalyDetection.tsStatistical outlier detection
Auto TuningautoTuning.tsAuto-tune forecast params
Forecast MonitorforecastMonitor.tsAccuracy monitoring
Forecast TuningforecastTuning.tsManual parameter tuning UI
HierarchicalhierarchicalForecast.tsMulti-level reconciliation
ML CachemlForecastCache.tsCache ML results from Supabase
ML ClientmlForecastClient.tsFetch ML predictions
ProphetprophetIntegration.tsProphet model integration
QuantilequantileRegression.tsConfidence band calculation
Forecast Serviceforecast.tsHigh-level API

Flow chính: runCombinedForecast()

Output Format

typescript
interface ForecastOutput {
  totalVolume: number;
  totalWlu: number;           // WLU-weighted volume
  hourlyDistribution: number[];
  bauVolume: number;          // BAU baseline
  eventVolume: number;        // Event-driven additional volume
  holidayMultiplier: number;  // Holiday adjustment factor
  confidence_p10: number;     // Lower bound
  confidence_p90: number;     // Upper bound
}

THIẾT KẾ CẦN XEM XÉT

Frontend có forecast engine riêng (Holt-Winters) trùng lặp với backend ML. Khi ML accuracy cải thiện, nên chuyển sang ML-primary. Xem ADR-003.

Tài liệu liên quan

BoxMe Forecast — Tài liệu kỹ thuật nội bộ