fix: resolve UTC date matching and implement per-product ASIN breakdown table for Line experiments

This commit is contained in:
Christian Vidal Wolf
2026-02-21 19:37:07 +01:00
parent 8bd78c2e7f
commit aa9a7845b7
3 changed files with 181 additions and 13 deletions
+69
View File
@@ -0,0 +1,69 @@
import fs from 'fs';
import path from 'path';
// read dummy data or mock
const mockSalesData = [
{
asin: 'B08F2J8S1Y',
line: 'LEGENDS',
year: 2026,
week: 1,
unitsTotal: 10,
salesTotal: 100,
},
{
asin: 'B08F2J8S1Y',
line: 'LEGENDS',
year: 2026,
week: 2,
unitsTotal: 15,
salesTotal: 150,
}
];
const experimentAsins = ['LINE:LEGENDS'];
const lines = new Set();
const explicitAsins = new Set();
experimentAsins.forEach(a => {
const val = (a || '').trim().toUpperCase();
if (val.startsWith('LINE:')) {
lines.add(val.substring(5).trim());
} else if (val) {
explicitAsins.add(val);
}
});
const asinSet = new Set(explicitAsins);
if (lines.size > 0 && mockSalesData) {
mockSalesData.forEach(r => {
const line = (r.line || '').trim().toUpperCase();
if (line && lines.has(line)) {
if (r.asin) asinSet.add(r.asin.toUpperCase());
}
});
}
console.log('Resolved ASINs:', Array.from(asinSet));
// Date test
const startDateStr = '2026-01-01';
const endDateStr = '2026-01-14';
const startDate = new Date(startDateStr);
const endDate = new Date(endDateStr);
console.log('Start Date UTC:', startDate.toISOString(), 'Local:', startDate.toString());
console.log('End Date UTC:', endDate.toISOString(), 'Local:', endDate.toString());
const recordDate1 = new Date(2026, 0, 1); // week 1
const recordDate2 = new Date(2026, 0, 8); // week 2
const recordDate3 = new Date(2026, 0, 15); // week 3
console.log('Week 1 Record Date Local:', recordDate1.toString());
console.log('Week 1 included in experiment?', recordDate1 >= startDate && recordDate1 <= endDate);
console.log('Week 2 Record Date Local:', recordDate2.toString());
console.log('Week 2 included in experiment?', recordDate2 >= startDate && recordDate2 <= endDate);
console.log('Week 3 Record Date Local:', recordDate3.toString());
console.log('Week 3 included in experiment?', recordDate3 >= startDate && recordDate3 <= endDate);