Files

71 lines
2.7 KiB
TypeScript
Raw Permalink Normal View History

import XLSX from 'xlsx';
import { readFileSync } from 'fs';
import { processAdsExcel, mergeSalesAndAdsData } from './services/dataProcessor';
import { computeDiD } from './services/experimentAnalysis';
import { getExperimentAsins } from './services/experiments';
import { Experiment, CombinedKPIs } from './types';
// Simulate the getWeekStartSunday function from experimentAnalysis.ts
function getWeekStartSunday(year: number, week: number): number {
const jan1 = new Date(year, 0, 1);
const day = jan1.getDay();
const startYear = new Date(year, 0, 1 - day);
return startYear.getTime() + (week - 1) * 7 * 86400000;
}
async function run() {
const buf = readFileSync('/tmp/Ads-Weekly.xlsx').buffer;
const adsData = await processAdsExcel(buf);
const merged = mergeSalesAndAdsData([], adsData);
// Show the timestamps for INKEE DE weeks
const inkeeDE = merged.filter(m =>
m.asin.startsWith('B0CQ') &&
(m.marketplace || m.customer || '').includes('DE')
);
console.log('=== INKEE DE TIMESTAMP ANALYSIS ===');
for (const r of inkeeDE.slice(0, 5)) {
const weekStartTs = getWeekStartSunday(r.year, r.week);
const weekStartDate = new Date(weekStartTs).toISOString().split('T')[0];
console.log(`ASIN:${r.asin} ${r.year}-W${r.week} weekStart:${weekStartDate} cost:${r.cost.toFixed(2)}`);
}
console.log('\n=== WEEK DATE RANGES ===');
for (let week = 1; week <= 8; week++) {
const ts2025 = getWeekStartSunday(2025, week);
const ts2026 = getWeekStartSunday(2026, week);
const d2025 = new Date(ts2025).toISOString().split('T')[0];
const d2026 = new Date(ts2026).toISOString().split('T')[0];
console.log(`Week ${week}: 2025 → ${d2025} | 2026 → ${d2026}`);
}
// Now simulate an experiment that spans the existing data range
// The experiment "INKEE DE" - let's test with dates in Jan 2026 (W1-W4)
const testExperiment: Experiment = {
id: 'test',
name: 'INKEE DE Test',
type: 'advertising',
status: 'active',
asins: ['B0CQ247T2V', 'B0CQTLZRCV'],
control_asins: [],
marketplace: 'DE',
start_date: '2026-01-05', // Start of week 2, 2026
end_date: '2026-02-22', // End of week 8, 2026
baseline_start_date: '2025-01-06', // Week 2, 2025
baseline_end_date: '2025-02-23', // Week 8, 2025
primary_metric: 'acos',
notes: '',
owner: ''
};
console.log('\n=== DiD SIMULATION ===');
const did = computeDiD(testExperiment, merged as CombinedKPIs[]);
console.log('ACOS:', did.metrics['acos']);
console.log('ROAS:', did.metrics['roas']);
console.log('Units:', did.metrics['units']);
}
run().catch(console.error);