mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:15:23 +02:00
Fix: Corrected ForecastView data structure and missing aggregated properties
This commit is contained in:
@@ -1656,23 +1656,39 @@ export const calculateForecastViewData = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Build monthly points
|
// 3. Build monthly points and aggregate
|
||||||
const monthlyData: MonthlyForecastPoint[] = MONTH_ORDER.map((m, idx) => {
|
const monthlyData: Record<string, MonthlyForecastPoint> = {};
|
||||||
|
let totalActualUnits = 0;
|
||||||
|
let totalForecastUnits = 0;
|
||||||
|
|
||||||
|
MONTH_ORDER.forEach((m, idx) => {
|
||||||
const forecastUnits = Math.round(fc.annualForecast * productWeights[idx]);
|
const forecastUnits = Math.round(fc.annualForecast * productWeights[idx]);
|
||||||
const actualUnits = actuals2026.get(identifier)?.get(m) || 0;
|
const actualUnits = actuals2026.get(identifier)?.get(m) || 0;
|
||||||
return {
|
|
||||||
|
monthlyData[m] = {
|
||||||
month: m,
|
month: m,
|
||||||
forecastUnits,
|
forecastUnits,
|
||||||
actualUnits
|
actualUnits,
|
||||||
};
|
units: actualUnits // Added for chart compatibility
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
totalActualUnits += actualUnits;
|
||||||
|
totalForecastUnits += forecastUnits;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const accuracy = totalForecastUnits > 0
|
||||||
|
? Math.min(100, Math.round((1 - Math.abs(totalActualUnits - totalForecastUnits) / totalForecastUnits) * 100))
|
||||||
|
: 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
asin: identifier,
|
asin: identifier,
|
||||||
sku: meta?.sku || fc.sku || identifier,
|
sku: meta?.sku || fc.sku || identifier,
|
||||||
title: meta?.title || fc.title || identifier,
|
title: meta?.title || fc.title || identifier,
|
||||||
line: meta?.line || fc.line || "",
|
line: meta?.line || fc.line || "Unassigned",
|
||||||
annualForecast: fc.annualForecast,
|
annualForecast: fc.annualForecast,
|
||||||
|
actualUnits: totalActualUnits,
|
||||||
|
forecastUnits: totalForecastUnits,
|
||||||
|
accuracy: Math.max(0, accuracy),
|
||||||
monthlyData
|
monthlyData
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -216,5 +216,8 @@ export interface ProductForecastData {
|
|||||||
title: string;
|
title: string;
|
||||||
line: string;
|
line: string;
|
||||||
annualForecast: number;
|
annualForecast: number;
|
||||||
monthlyData: MonthlyForecastPoint[];
|
actualUnits: number;
|
||||||
|
forecastUnits: number;
|
||||||
|
accuracy: number;
|
||||||
|
monthlyData: Record<string, MonthlyForecastPoint>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user