Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function simulateLeave() {
let delId;
do {
delId = Math.floor(Math.random() * id);
} while (freeIds.has(delId));
freeIds.add(delId);
delId = '' + delId;
const delTs = unwrap(state, ['visitors', delId, 'ts']);
// console.log('Unwrap', debug(state), ['visitors', delId, 'ts'], delTs);
leave++;
return graph(
{
visitors: { [delId]: null },
visitorsByTime: { [delTs]: null },
},
ts,
);
}
function simulateEnter() {
let addId;
if (freeIds.size) {
for (const id of freeIds) {
addId = id;
freeIds.delete(addId);
break;
}
} else {
addId = id++;
}
addId = '' + addId;
enter++;
return graph(
{
visitors: { [addId]: { id: addId, ts, ...visitorInfo() } },
visitorsByTime: { [ts]: link(['visitors', addId]) },
},
ts,
);
}
function simulateUpdate() {
let upId;
do {
upId = Math.floor(Math.random() * id);
} while (freeIds.has(upId));
upId = '' + upId;
const url = faker.internet.url();
update++;
return graph({ visitors: { [upId]: { pageviews: { [ts]: url } } } }, ts);
}