Created
June 22, 2023 19:31
-
-
Save yaf/177cb96b9828b082111a2d2d594089e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Faire le compte par « étape » du nombre d'assessmentId par challengId | |
const fs = require("fs"); | |
const { parse } = require("csv-parse"); | |
let parcours = [] | |
let maxParcoursLength = 0 | |
fs.createReadStream("./data.csv") | |
.pipe(parse({ delimiter: ",", from_line: 2 })) | |
.on("data", function (row) { | |
//console.log(row[0]); | |
const assessmentId = row[0]; | |
const resultat = row[18]; | |
const challengeId = row[20]; | |
const createdAt = row[21]; | |
const etape = { | |
assessmentId: assessmentId, | |
number: 0, | |
resultat: resultat, | |
challengeId: challengeId, | |
createdAt: createdAt | |
} | |
if (!parcours[assessmentId]) { | |
parcours[assessmentId] = new Array() | |
} else { | |
// hypothèse : les lignes sont déjà trié par createdAt d'answer | |
etape.number = parcours[assessmentId].length | |
if (parcours[assessmentId].length > maxParcoursLength) { | |
maxParcoursLength = parcours[assessmentId].length | |
} | |
} | |
parcours[assessmentId].push(etape) | |
}) | |
.on("end", function () { | |
console.log("maxParcoursLength ", maxParcoursLength) | |
parcours = parcours | |
.map((parcour) => { | |
let p = parcour.filter((p) => p.number == 55)[0] | |
if (p) return p.challengeId | |
}).reduce((a, b) => { | |
if(a[b] !== undefined) { | |
a[b] += 1; | |
} else { | |
a[b] = 1; | |
} | |
return a | |
}, {}) | |
console.log("parcours après", parcours) | |
console.log("finished"); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment