Giao diện
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)
| Module | File | Mô tả |
|---|---|---|
| Core Engine | forecastEngine.ts | Main orchestrator (~50KB) |
| BAU Baseline | baselineCalculator.ts | Holt-Winters exponential smoothing |
| Exponential Smoothing | exponentialSmoothing.ts | Core HW implementation |
| Ensemble | ensembleForecaster.ts | Multi-model ensemble weights |
| Decision Tree | decisionTree.ts | Staffing decision rules |
| Anomaly Detection | anomalyDetection.ts | Statistical outlier detection |
| Auto Tuning | autoTuning.ts | Auto-tune forecast params |
| Forecast Monitor | forecastMonitor.ts | Accuracy monitoring |
| Forecast Tuning | forecastTuning.ts | Manual parameter tuning UI |
| Hierarchical | hierarchicalForecast.ts | Multi-level reconciliation |
| ML Cache | mlForecastCache.ts | Cache ML results from Supabase |
| ML Client | mlForecastClient.ts | Fetch ML predictions |
| Prophet | prophetIntegration.ts | Prophet model integration |
| Quantile | quantileRegression.ts | Confidence band calculation |
| Forecast Service | forecast.ts | High-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
- Workforce Engine — Sử dụng output từ forecast engine
- ML Engine (Python) — Backend ML counterpart
- Config Registry — Configs cho forecast params