fix: adapt experiment calculation engine to consume both CombinedKPIs and SalesRecord data structures

This commit is contained in:
Christian Vidal Wolf
2026-02-21 22:51:38 +01:00
parent 411448e4d2
commit 99d524db12
2 changed files with 22 additions and 10 deletions
+12 -4
View File
@@ -92,11 +92,15 @@ const ExperimentDetail: React.FC<ExperimentDetailProps> = ({ experimentId, onClo
const asin = (r.asin || '').toUpperCase();
if (!asinMap.has(asin)) return;
const mkt = (r.marketplace || (r as any).customer || '').toLowerCase();
const isMarket = !experiment.marketplace || experiment.marketplace === 'All' || mkt.includes(experiment.marketplace.toLowerCase());
if (!isMarket) return;
const recordDate = new Date(r.year, 0, 1 + ((r.week || 1) - 1) * 7);
if (recordDate >= startDate && recordDate <= endDate) {
const d = asinMap.get(asin)!;
d.units += r.unitsTotal || 0;
d.revenue += r.salesTotal || 0;
d.units += (r.unitsTotal ?? (r as any).units ?? 0);
d.revenue += (r.salesTotal ?? (r as any).sellOut ?? 0);
d.gv += r.glanceViews || 0;
d.spend += r.cost || 0;
}
@@ -125,6 +129,10 @@ const ExperimentDetail: React.FC<ExperimentDetailProps> = ({ experimentId, onClo
const asin = (r.asin || '').toUpperCase();
if (!asinSet.has(asin)) return;
const mkt = (r.marketplace || (r as any).customer || '').toLowerCase();
const isMarket = !experiment.marketplace || experiment.marketplace === 'All' || mkt.includes(experiment.marketplace.toLowerCase());
if (!isMarket) return;
const weekNum = r.week || 1;
const yearStr = r.year || new Date().getFullYear();
const weekStr = `${yearStr}-W${String(weekNum).padStart(2, '0')}`;
@@ -142,8 +150,8 @@ const ExperimentDetail: React.FC<ExperimentDetailProps> = ({ experimentId, onClo
}
const w = weeklyMap.get(weekStr);
w.units += r.unitsTotal || 0;
w.revenue += r.salesTotal || 0;
w.units += (r.unitsTotal ?? (r as any).units ?? 0);
w.revenue += (r.salesTotal ?? (r as any).sellOut ?? 0);
w.gv += r.glanceViews || 0;
w.spend += r.cost || 0;
});