mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 14:05:24 +02:00
fix: restrict actual units to forecast region scope in ForecastView
This commit is contained in:
@@ -1654,7 +1654,19 @@ export const calculateForecastViewData = (
|
|||||||
// Use referenceData if provided (for global weights), otherwise fallback to rawData
|
// Use referenceData if provided (for global weights), otherwise fallback to rawData
|
||||||
const seasonalitySource = referenceData || rawData;
|
const seasonalitySource = referenceData || rawData;
|
||||||
const historicalData = seasonalitySource.filter(r => r.year < 2026);
|
const historicalData = seasonalitySource.filter(r => r.year < 2026);
|
||||||
const data2026 = seasonalitySource.filter(r => r.year === 2026);
|
|
||||||
|
// IMPORTANT: Actuals for 2026 must be strictly scoped to the forecast region
|
||||||
|
// to avoid mixing UK stats into Pan-EU or vice-versa.
|
||||||
|
const isForecastUKMode = filters?.customer?.includes('Amazon UK');
|
||||||
|
const data2026 = rawData.filter(r => {
|
||||||
|
if (r.year !== 2026) return false;
|
||||||
|
if (isForecastUKMode) {
|
||||||
|
return r.customer === 'Amazon UK';
|
||||||
|
} else {
|
||||||
|
// In Pan-EU mode, explicitly exclude UK units even if they are in the dataset
|
||||||
|
return r.customer !== 'Amazon UK';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Calculate Seasonality weights for 2025
|
// Calculate Seasonality weights for 2025
|
||||||
const getWeightsInfo = (records: SalesRecord[]): { weights: number[]; monthsCount: number } | null => {
|
const getWeightsInfo = (records: SalesRecord[]): { weights: number[]; monthsCount: number } | null => {
|
||||||
|
|||||||
Reference in New Issue
Block a user