bde-liste/stats.js
2023-01-17 13:16:58 +01:00

29 lines
901 B
JavaScript

const fs = require('fs');
let PrankData = JSON.parse(fs.readFileSync("prankdata.txt"));
let nbPrank = 0;
let nbCrepe = 0;
let meanCrepe = 0;
let userPrank = {};
for (var uid in PrankData) {
if (PrankData[uid].type == "crêpe") {
if (PrankData[uid].state == "Done") {
nbPrank ++;
nbCrepe += parseInt(PrankData[uid].amount)
if (!userPrank[PrankData[uid].creator]) {
userPrank[PrankData[uid].creator] = 0;
}
userPrank[PrankData[uid].creator] += parseInt(PrankData[uid].amount);
}
}
}
meanCrepe = nbCrepe / nbPrank;
console.log("Nombre de mission mission achevé: " + nbPrank)
console.log("Nombre de crêpe servis: " + nbCrepe)
console.log("Nombre moyen de crêpe par demande: " + meanCrepe + "\n")
for (var user in userPrank) {
console.log(user + " a commandé " + userPrank[user] + " crêpe")
}