diff --git a/_addons/clicker/grading.js b/_addons/clicker/grading.js index dc6df0d..8b0013b 100644 --- a/_addons/clicker/grading.js +++ b/_addons/clicker/grading.js @@ -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')])))); } diff --git a/_addons/clicker/stats.js b/_addons/clicker/stats.js index e2e79c1..3d16e01 100644 --- a/_addons/clicker/stats.js +++ b/_addons/clicker/stats.js @@ -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);