Build a TypeScript module that predicts future item requests from a partner organization so banks can proactively stock inventory. ```typescript forecastDemand( partnerId: string, itemId: string, horizon: 30 | 60 | 90 // days ahead to forecast ): Promise<ForecastResult> // ForecastResult: { // predicted: { month: string, units: number, confidence: 'high' | 'medium' | 'low' }[], // seasonalityDetected: boolean, // dataPointsUsed: number // } ``` Algorithm: 1. Fetch monthly distribution totals for the partner+item from the database (last 24 months max) 2. Apply simple exponential smoothing (α = 0.3): `S_t = α * x_t + (1 - α) * S_{t-1}` 3. Detect seasonality: if the coefficient of variation across same-month values across years > 0.2, set `seasonalityDetected: true` 4. Confidence based on data available: 'high' = 12+ months, 'medium' = 6-11, 'low' = under 6 5. Return one predicted entry per month for the forecast horizon Write unit tests for 3 scenarios: - Steady demand (should forecast near the historical average) - Seasonal pattern with summer spikes - Fewer than 6 data points (should return 'low' confidence and still produce a forecast)
No contributions yet.