Yes, reorder recommendations are directly based on demand forecasting results! The system uses forecasted demand to calculate optimal reorder quantities and urgency levels.
Location: src/api/routers/advanced_forecasting.py:197-204
# Get current inventory levels
inventory_query = """
SELECT sku, name, quantity, reorder_point, location
FROM inventory_items
WHERE quantity <= reorder_point * 1.5
ORDER BY quantity ASC
"""The system identifies items that are at or near their reorder point (within 150% of reorder point).
Location: src/api/routers/advanced_forecasting.py:213-218
For each low-stock item, the system:
- Calls
get_real_time_forecast(sku, 30)- Gets 30-day forecast - Extracts
recent_average_demandfrom the forecast - Uses this as the expected daily demand for calculations
# Get recent demand forecast
try:
forecast = await self.get_real_time_forecast(sku, 30)
avg_daily_demand = forecast['recent_average_demand']
except:
avg_daily_demand = 10 # Default fallbackKey Point: The recent_average_demand comes from the ML forecasting models (XGBoost, Random Forest, etc.) that analyze historical patterns and predict future demand.
Location: src/api/routers/advanced_forecasting.py:220-223
# Calculate recommended order quantity
safety_stock = max(reorder_point, avg_daily_demand * 7) # 7 days safety stock
recommended_quantity = int(safety_stock * 2) - current_stock
recommended_quantity = max(0, recommended_quantity)Formula Breakdown:
- Safety Stock = max(reorder_point, forecasted_daily_demand × 7 days)
- Recommended Quantity = (Safety Stock × 2) - Current Stock
- Ensures enough inventory for 14 days of forecasted demand
Location: src/api/routers/advanced_forecasting.py:225-239
The urgency is calculated based on days until stockout:
days_remaining = current_stock / max(avg_daily_demand, 1)
if days_remaining <= 3:
urgency = "CRITICAL" # Stock will run out in 3 days or less
elif days_remaining <= 7:
urgency = "HIGH" # Stock will run out within a week
elif days_remaining <= 14:
urgency = "MEDIUM" # Stock will run out within 2 weeks
else:
urgency = "LOW" # Stock levels are adequateKey Calculation: days_remaining = current_stock ÷ forecasted_daily_demand
This directly uses the forecast to predict when stockout will occur!
Location: src/api/routers/advanced_forecasting.py:241-242
confidence_score = min(0.95, max(0.5, 1.0 - (days_remaining / 30)))Confidence increases as urgency increases (more urgent = higher confidence in the recommendation).
The get_real_time_forecast() method:
- Checks Redis cache for recent forecasts
- If not cached, loads forecast from
all_sku_forecasts.json - Returns forecast data including:
recent_average_demand- Used for reorder calculationspredictions- 30-day forecastconfidence_intervals- Model confidencebest_model- Which ML model performed best
Forecast Source: ML models trained on historical demand data:
- XGBoost
- Random Forest
- Gradient Boosting
- Linear Regression
- Ridge Regression
- SVR (Support Vector Regression)
Location: ui/web/src/pages/Forecasting.tsx:429-476
The forecasting dashboard displays reorder recommendations in a table showing:
- SKU - Item identifier
- Current Stock - Current inventory level
- Recommended Order - Calculated quantity to order
- Urgency - CRITICAL/HIGH/MEDIUM/LOW (color-coded chips)
- Reason - Explanation (e.g., "Stock will run out in 3 days or less")
- Confidence - Percentage confidence score
Inventory Database
↓
[Items with quantity ≤ reorder_point × 1.5]
↓
For each SKU:
↓
get_real_time_forecast(SKU, 30 days)
↓
ML Forecast Models (XGBoost, Random Forest, etc.)
↓
recent_average_demand (from forecast)
↓
Calculate:
- Safety Stock = max(reorder_point, avg_daily_demand × 7)
- Recommended Qty = (Safety Stock × 2) - Current Stock
- Days Remaining = Current Stock ÷ avg_daily_demand
- Urgency = Based on days_remaining
- Confidence = Function of days_remaining
↓
ReorderRecommendation
↓
API Endpoint: /api/v1/forecasting/dashboard
↓
React UI: http://localhost:3001/forecasting
Reorder recommendations are entirely based on demand forecasting results.
The system performs the following operations:
- Uses ML models to predict daily demand
- Calculates how many days of stock remain based on forecast
- Determines urgency from predicted stockout date
- Calculates optimal order quantity using forecasted demand
- Provides confidence scores based on forecast reliability
Without the forecasting system, reorder recommendations would only use static reorder_point values. With forecasting, the system:
- Adapts to changing demand patterns
- Predicts stockout dates accurately
- Optimizes order quantities based on forecasted needs
- Prioritizes urgent items based on forecasted demand velocity
This makes the reorder system intelligent and proactive rather than reactive.