-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.9.2: grade distribution chart rendering for groups
- Loading branch information
1 parent
daee2af
commit 702ea6c
Showing
4 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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; |