-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedx-data-formatter.js
43 lines (40 loc) · 1.57 KB
/
edx-data-formatter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var trackinglogs_to_mydataformat = function(dataArr) {
var formattedArray = {};
var quizProblems = [];
for (var i in dataArr) {
//the first item in the array of dictionaries should be a username
if (!(dataArr[i].username in formattedArray)) {
if (dataArr[i].event_type == "save_problem_check"){
if (dataArr[i].event.success == "correct") {
// { username: { problemID: attempts }}
formattedArray[dataArr[i].username] = {};
formattedArray[dataArr[i].username][dataArr[i].event.problem_id] = dataArr[i].event.attempts;
if (quizProblems.indexOf(dataArr[i].event.problem_id) == -1) {
quizProblems.push(dataArr[i].event.problem_id);
}
}
}
}
else if (dataArr[i].username in formattedArray) {
if (dataArr[i].event_type == "save_problem_check"){
if (dataArr[i].event.success == "correct") {
// { username: { problemID: attempts } }
if (dataArr[i].event.problem_id in formattedArray[dataArr[i].username]) {
if ( dataArr[i].event.attempts <= formattedArray[dataArr[i].username][dataArr[i].event.problem_id]) {
formattedArray[dataArr[i].username][dataArr[i].event.problem_id] = dataArr[i].event.attempts;
}
}
else {
if (quizProblems.indexOf(dataArr[i].event.problem_id) == -1) {
quizProblems.push(dataArr[i].event.problem_id);
}
formattedArray[dataArr[i].username][dataArr[i].event.problem_id] = dataArr[i].event.attempts;
}
}
}
}
}
quizProblems.sort();
console.log("quizproblems", quizProblems);
return [formattedArray, quizProblems];
}