Skip to content

Commit

Permalink
v2.9.2: grade distribution chart rendering for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienjoly committed Mar 27, 2018
1 parent daee2af commit 702ea6c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 3 deletions.
104 changes: 103 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "js-test",
"version": "2.9.1",
"version": "2.9.2",
"description": "Exercise/exam software for evaluating JavaScript students' progress",
"repository": {
"type": "git",
"url": "https://github.com/adrienjoly/js-test.git"
},
"dependencies": {
"@gribnoysup/wunderbar": "^2.1.0",
"async": "^1.5.2",
"bower": "^1.7.9",
"firebase": "^3.6",
Expand Down
8 changes: 7 additions & 1 deletion src/evaluateGroupFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ var fs = require('fs');
var _ = require('lodash');
var async = require('async');
var evaluateStudent = require('./StudentEvaluator');
var renderDistributionChart = require('./renderDistributionChart');

var filePath = process.argv[2] || '../student-groups/js-controle-1-classe-1.json';

var PATH_SOURCE = './exam-data/';
var SCORES_FILE = PATH_SOURCE + 'scores.csv';
var SCORES_DETAIL_FILE = PATH_SOURCE + 'scores-detail.csv';
var SCORES_CHART_FILE = PATH_SOURCE + 'scores-chart.txt';

function appendScoreValues(array) {
var csvLine = array.toString() + '\n';
Expand Down Expand Up @@ -39,14 +41,18 @@ var submissions = Object.keys(submissionSet).map(function(key){
return _.extend(submissionSet[key], { key: key });
});

async.mapSeries(submissions, evaluateStudent, function(err, res){
async.mapSeries(submissions, evaluateStudent, function(err, res) {
if (err) throw err;
// list students' total scores
var flatScores = res.map(function(student) {
return student.studentTotalScore;
});
// compute average and median
[
[ '(AVERAGE)', flatScores.reduce(sum) / res.length ],
[ '(MEDIAN)', median(flatScores) ]
].map(appendScoreValues);
// generate grade/score distribution chart
fs.appendFileSync(SCORES_CHART_FILE, renderDistributionChart({ flatScores }));
process.exit();
});
32 changes: 32 additions & 0 deletions src/renderDistributionChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const wunderbar = require('@gribnoysup/wunderbar');

const gradeStep = 3;
const gradeLines = [0, 3, 6, 9, 12, 15, 18];
const gradePadding = Math.max.apply(null, gradeLines).toString().length;
const rangePadding = gradePadding * 2 + 1 + 1; // number of characters to display range

// generate grade/score distribution chart
function renderDistributionChart({ flatScores }) {
const nbStudentsPerGrade = gradeLines.map(function(grade) {
return flatScores.reduce(function(count, studentScore) {
return count + (studentScore >= grade && studentScore < grade + gradeStep ? 1 : 0);
}, 0);
});
const { chart, scale } = wunderbar(nbStudentsPerGrade, {
min: 0,
max: flatScores.length, // number of students
length: 42,
});
return []
.concat(chart.split('\n').map(function(line, i) {
var low = Math.floor(i * gradeStep).toString().padStart(gradePadding, '0');
var high = Math.floor((i + 1) * gradeStep - 1).toString().padStart(gradePadding, '0');
var range = [low, high].join('-');
return range.padEnd(rangePadding, ' ') + line
+ ' (' + nbStudentsPerGrade[i] + ' stud.)';
}))
.concat([ ''.padStart(rangePadding, ' ') + scale ])
.join('\n');
}

module.exports = renderDistributionChart;

0 comments on commit 702ea6c

Please sign in to comment.