Fuzzing for dates
In addition to fuzzing amounts, this shifts all dates to the past by a random number of days (between 7 and 14).
This commit is contained in:
parent
c16db7bbb2
commit
0e8228a0bb
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user