mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 16:05:23 +02:00
38 lines
1.9 KiB
TypeScript
38 lines
1.9 KiB
TypeScript
import XLSX from 'xlsx';
|
|
import { readFileSync } from 'fs';
|
|
|
|
const buf = readFileSync('/Users/christianvidalwolf/github/CrazeAnalytix/docs/plans/Ads_Performance_Export_2026-02-26.xlsx');
|
|
const wb = XLSX.read(buf, { type: 'buffer' });
|
|
|
|
console.log('Sheets:', wb.SheetNames);
|
|
|
|
for (const sheetName of wb.SheetNames) {
|
|
const ws = wb.Sheets[sheetName];
|
|
const rows: any[] = XLSX.utils.sheet_to_json(ws, { defval: '' });
|
|
|
|
if (rows.length === 0) { console.log(`Sheet "${sheetName}" is empty`); continue; }
|
|
|
|
console.log(`\n=== Sheet: "${sheetName}" (${rows.length} rows) ===`);
|
|
const headers = Object.keys(rows[0]);
|
|
console.log('Columns:', headers.join(' | '));
|
|
console.log('First 3 rows:');
|
|
rows.slice(0, 3).forEach(r => console.log(' ', JSON.stringify(r).slice(0, 300)));
|
|
|
|
// Look for key columns
|
|
const weekCol = headers.find(h => /week|woche|semana/i.test(h));
|
|
const asinCol = headers.find(h => /asin/i.test(h));
|
|
const countryCol = headers.find(h => /country|marketplace|portfolio|land|país/i.test(h));
|
|
const costCol = headers.find(h => /^cost$|^spend$|^ausgaben$|^gasto$/i.test(h) || (/cost|spend/i.test(h) && !/acos|of sales/i.test(h)));
|
|
const salesCol = headers.find(h => /sales|umsatz|ventas/i.test(h) && !/acos|cost of/i.test(h));
|
|
|
|
console.log(`\nKey columns: week="${weekCol}" | asin="${asinCol}" | country="${countryCol}" | cost="${costCol}" | sales="${salesCol}"`);
|
|
|
|
if (weekCol && costCol) {
|
|
const weeks = [...new Set(rows.map(r => r[weekCol!]))];
|
|
console.log('Unique weeks:', weeks.sort());
|
|
const totalCost = rows.reduce((s, r) => s + (parseFloat(String(r[costCol!]).replace(',', '.')) || 0), 0);
|
|
const totalSales = salesCol ? rows.reduce((s, r) => s + (parseFloat(String(r[salesCol!]).replace(',', '.')) || 0), 0) : 0;
|
|
console.log(`Total cost: ${totalCost.toFixed(2)}, Total sales: ${totalSales.toFixed(2)}`);
|
|
}
|
|
}
|