mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:35:24 +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
|
||||
const monthlyData: MonthlyForecastPoint[] = MONTH_ORDER.map((m, idx) => {
|
||||
// 3. Build monthly points and aggregate
|
||||
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 actualUnits = actuals2026.get(identifier)?.get(m) || 0;
|
||||
return {
|
||||
|
||||
monthlyData[m] = {
|
||||
month: m,
|
||||
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 {
|
||||
asin: identifier,
|
||||
sku: meta?.sku || fc.sku || identifier,
|
||||
title: meta?.title || fc.title || identifier,
|
||||
line: meta?.line || fc.line || "",
|
||||
line: meta?.line || fc.line || "Unassigned",
|
||||
annualForecast: fc.annualForecast,
|
||||
actualUnits: totalActualUnits,
|
||||
forecastUnits: totalForecastUnits,
|
||||
accuracy: Math.max(0, accuracy),
|
||||
monthlyData
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user