REFACTOR external service and improve websocket training
This commit is contained in:
@@ -27,7 +27,9 @@ const ForecastingPage: React.FC = () => {
|
||||
const startDate = new Date();
|
||||
startDate.setDate(startDate.getDate() - parseInt(forecastPeriod));
|
||||
|
||||
// Fetch existing forecasts
|
||||
// NOTE: We don't need to fetch forecasts from API because we already have them
|
||||
// from the multi-day forecast response stored in currentForecastData
|
||||
// Keeping this disabled to avoid unnecessary API calls
|
||||
const {
|
||||
data: forecastsData,
|
||||
isLoading: forecastsLoading,
|
||||
@@ -38,7 +40,7 @@ const ForecastingPage: React.FC = () => {
|
||||
...(selectedProduct && { inventory_product_id: selectedProduct }),
|
||||
limit: 100
|
||||
}, {
|
||||
enabled: !!tenantId && hasGeneratedForecast && !!selectedProduct
|
||||
enabled: false // Disabled - we use currentForecastData from multi-day API response
|
||||
});
|
||||
|
||||
|
||||
@@ -72,12 +74,15 @@ const ForecastingPage: React.FC = () => {
|
||||
|
||||
// Build products list from ingredients that have trained models
|
||||
const products = useMemo(() => {
|
||||
if (!ingredientsData || !modelsData?.models) {
|
||||
if (!ingredientsData || !modelsData) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Handle both array and paginated response formats
|
||||
const modelsList = Array.isArray(modelsData) ? modelsData : (modelsData.models || modelsData.items || []);
|
||||
|
||||
// Get inventory product IDs that have trained models
|
||||
const modelProductIds = new Set(modelsData.models.map(model => model.inventory_product_id));
|
||||
const modelProductIds = new Set(modelsList.map((model: any) => model.inventory_product_id));
|
||||
|
||||
// Filter ingredients to only those with models
|
||||
const ingredientsWithModels = ingredientsData.filter(ingredient =>
|
||||
@@ -130,10 +135,10 @@ const ForecastingPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Use either current forecast data or fetched data
|
||||
const forecasts = currentForecastData.length > 0 ? currentForecastData : (forecastsData?.forecasts || []);
|
||||
const isLoading = forecastsLoading || ingredientsLoading || modelsLoading || isGenerating;
|
||||
const hasError = forecastsError || ingredientsError || modelsError;
|
||||
// Use current forecast data from multi-day API response
|
||||
const forecasts = currentForecastData;
|
||||
const isLoading = ingredientsLoading || modelsLoading || isGenerating;
|
||||
const hasError = ingredientsError || modelsError;
|
||||
|
||||
// Calculate metrics from real data
|
||||
const totalDemand = forecasts.reduce((sum, f) => sum + f.predicted_demand, 0);
|
||||
|
||||
Reference in New Issue
Block a user