Skip to content

Commit

Permalink
Added function to download all grades + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca De Feo committed Mar 9, 2018
1 parent 777becf commit d9dea2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 16 additions & 4 deletions _addons/clicker/grading.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ function grade(timeline, total) {
}

function gradeAll(users, total) {
users.forEach(function(u) {
clicker._authXHR('/stats/user/' + u._id, clicker.user.token, function(answers, xhr) {
return users.map((u) => new Promise((resolve, reject) => {
clicker._authXHR('/stats/user/' + u._id, clicker.user.token, (answers, xhr) => {
u.grade = grade(timeline(answers), total);
}, function(err) {
resolve(u);
}, (err) => {
console.log(err);
reject(err);
});
});
}));
}

function downloadGrades(since=Date.now() - 1000*60*60*24*90) {
return Promise.all(gradeAll(users, count(quizzes)))
.then((users) => window.open(
URL.createObjectURL(new Blob(
[users
.filter(u => u.lastSeen > Date.now() - 1000*60*60*24*90)
.map(u => `${u._id},${u.profile.name},${u.grade}`)
.join('\n')]))));
}
12 changes: 12 additions & 0 deletions _addons/clicker/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,15 @@ quizzes.forEach(function(l) {
});
}
});


console.info(`Hello, this is Clicker!
To grade all students seen in the last 30 days, and export their
grades as CSV you may run
downloadGrades(Date.now() - 1000*60*60*24*30)
Without parameters, it defaults to the last 90 days.
Have a look at the source code:`, downloadGrades);

0 comments on commit d9dea2f

Please sign in to comment.