Randomize sort order of user IDs

This commit is contained in:
2025-05-02 16:45:25 +04:00
parent 1134b0991a
commit 04457b8912

View File

@@ -44,6 +44,16 @@ try {
const userIdsResult = await client.queryObject("SELECT id FROM users");
const userIds = userIdsResult.rows.map((row) => row.id);
// Shuffle userIds array to randomize processing order
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // Swap elements
}
return array;
}
shuffleArray(userIds);
// CSV file path
const csvFilePath = "./daily-stats.csv";