diff --git a/generate-stats.ts b/generate-stats.ts index 9259a68..31653e6 100644 --- a/generate-stats.ts +++ b/generate-stats.ts @@ -100,6 +100,16 @@ function getFuzzFactor(amount) { return normalized * 0.02 - 0.01; // -1% to +1% for larger amounts } +// Randomly choose a date shift between 7 and 14 days +const dateShiftDays = Math.floor(Math.random() * 8) + 7; + +// Shift date to the past by a number of days +function shiftDate(date, days) { + const shifted = new Date(date); + shifted.setDate(date.getDate() - days); // Subtract days to shift to past + return shifted.toISOString().split("T")[0]; // YYYY-MM-DD +} + // Process a single user and return CSV rows async function processUser(userId, client) { // Check the number of settled invoices for the user @@ -131,10 +141,10 @@ async function processUser(userId, client) { // Aggregate daily statistics using BigInt const dailyData = {}; - let runningBalance = BigInt(0); // Initialize as BigInt + let runningBalance = BigInt(0); for (const invoice of invoices) { - const day = invoice.settled_at.toISOString().split("T")[0]; // YYYY-MM-DD + const day = shiftDate(invoice.settled_at, dateShiftDays); // Get fuzzing factor for this invoice const fuzzFactor = getFuzzFactor(Number(invoice.amount));