diff --git a/components/BSRUnitsCorrelationChart.tsx b/components/BSRUnitsCorrelationChart.tsx index d047e25..791ac04 100644 --- a/components/BSRUnitsCorrelationChart.tsx +++ b/components/BSRUnitsCorrelationChart.tsx @@ -12,6 +12,12 @@ interface Props { const MARKETS = ['Amazon DE', 'Amazon ES', 'Amazon FR', 'Amazon IT', 'Amazon UK'] as const; +// BSR Excel stores market as short codes ('DE', 'IT', โ€ฆ); normalize to full names +const BSR_MARKET_NORMALIZE: Record = { + 'DE': 'Amazon DE', 'ES': 'Amazon ES', 'FR': 'Amazon FR', 'IT': 'Amazon IT', 'UK': 'Amazon UK', +}; +const normalizeBsrMarket = (m: string) => BSR_MARKET_NORMALIZE[m.toUpperCase()] ?? m; + const MARKET_CONFIG: Record = { 'Amazon DE': { label: 'DE', color: '#f37526', flag: '๐Ÿ‡ฉ๐Ÿ‡ช' }, 'Amazon ES': { label: 'ES', color: '#2acbd6', flag: '๐Ÿ‡ช๐Ÿ‡ธ' }, @@ -55,7 +61,7 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal // Derive available markets from actual data const availableMarkets = useMemo(() => { - const bsrMarkets = new Set(bsrData.map(r => r.market)); + const bsrMarkets = new Set(bsrData.map(r => normalizeBsrMarket(r.market))); const salesMarkets = new Set(combinedSalesData.map(r => r.customer)); return MARKETS.filter(m => bsrMarkets.has(m) || salesMarkets.has(m)); }, [bsrData, combinedSalesData]); @@ -75,11 +81,11 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal }, [combinedSalesData]); // Per-market chart data: BSR avg + units sum aligned by week - const { chartData, pearsonCorrelation, debugInfo } = useMemo(() => { + const { chartData, pearsonCorrelation } = useMemo(() => { // BSR: average detailLevelBSR per week (falls back to topLevelBSR if detail is unavailable) // Coerce week to number to guard against string values at runtime const bsrByWeek = new Map(); - const bsrRecordsForMarket = bsrData.filter(r => r.market === resolvedMarket); + const bsrRecordsForMarket = bsrData.filter(r => normalizeBsrMarket(r.market) === resolvedMarket); bsrRecordsForMarket .filter(r => r.detailLevelBSR != null || r.topLevelBSR != null) .forEach(r => { @@ -98,14 +104,6 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal unitsByWeek.set(week, (unitsByWeek.get(week) ?? 0) + r.unitsTotal); }); - const debugInfo = { - bsrTotal: bsrData.length, - bsrForMarket: bsrRecordsForMarket.length, - bsrWithValues: bsrByWeek.size, - unitsWeeks: unitsByWeek.size, - uniqueMarkets: Array.from(new Set(bsrData.map(r => r.market))).join(', '), - }; - const allWeeks = Array.from( new Set([...bsrByWeek.keys(), ...unitsByWeek.keys()]) ).sort((a, b) => a - b); @@ -127,7 +125,7 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal paired.map(d => d.units as number) ); - return { chartData, pearsonCorrelation: r, debugInfo }; + return { chartData, pearsonCorrelation: r }; }, [resolvedMarket, bsrData, combinedSalesData, currentYear]); const config = MARKET_CONFIG[resolvedMarket] ?? { label: '?', color: '#94a3b8', flag: '๐ŸŒ' }; @@ -336,13 +334,6 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal - {/* Temporary debug strip โ€” remove once BSR line is confirmed working */} -
-
BSR records total: {debugInfo.bsrTotal} ยท for {resolvedMarket}: {debugInfo.bsrForMarket} ยท with values: {debugInfo.bsrWithValues} weeks
-
Units weeks found: {debugInfo.unitsWeeks} ยท year: {currentYear}
-
Markets in BSR data: {debugInfo.uniqueMarkets || '(none)'}
-
- ); };