Repository navigation
Expand file tree
/
Copy pathgraphs.js
More file actions
102 lines (93 loc) · 3.03 KB
/
Copy pathgraphs.js
File metadata and controls
102 lines (93 loc) · 3.03 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const ChartjsNode = require('chartjs-node')
const moment = require('moment')
const assessments = require('./assessments.json')
const getStudentProgression = require('./src/student-progression')
const getAssessmentCompletionTime = require('./src/assessment-completion.js')
const getAssessmentAttempts = require('./src/assessment-attempts.js')
const destination = 'images'
function generate(studentProgress) {
const groupedStudentProgress = groupByStudent(studentProgress, assessments)
const progressData = getStudentProgression(groupedStudentProgress, assessments, false)
const sortedProgressData = getStudentProgression(groupedStudentProgress, assessments, true)
const assessmentCompletionData = getAssessmentCompletionTime(groupedStudentProgress, assessments)
const assessmentAttemptsData = getAssessmentAttempts(studentProgress, assessments)
generateChart('assessment-progression',
{
data: progressData,
type: 'line',
title: 'Student Progress of Passing Submission'
})
generateChart('sorted-assessment-progression',
{
data: sortedProgressData,
type: 'line',
title: 'Student Progress of Passing Submission'
})
generateChart('assessment-completion-time',
{
data: assessmentCompletionData,
type: 'bar',
title: 'Assessment Averaged Completion Time'
})
generateChart('assessment-attempts',
{
data: assessmentAttemptsData,
type: 'bar',
title: 'Assessment Failed Attempts'
})
}
function generateChart(name, options) {
if (global.CanvasGradient === undefined) {
global.CanvasGradient = function() {};
}
const chartNode = new ChartjsNode(4000, 2000);
chartNode.drawChart({
data: options.data,
type: options.type,
options: {
title: {
display: true,
text: options.title
},
scales: {
xAxes: [{
ticks: {
autoSkip: false
}
}]
}
}
})
.then(() => {
return chartNode.getImageBuffer('image/png');
})
.then(buffer => {
return chartNode.getImageStream('image/png');
})
.then(streamResult => {
streamResult.stream
streamResult.length
return chartNode.writeImageToFile('image/png', `./${destination}/${name}.png`);
})
.then(() => {
console.log(`${name} chart created`)
});
}
function groupByStudent(progress, assessments) {
return progress.reduce((group, submission) => {
const date = submission[0]
const student = submission[2]
const assessment = submission[3]
const assessmentVersion = submission[11]
const assessmentIndex = assessments.indexOf(`${assessment} - ${assessmentVersion}`)
const passing = submission[9]
group[student] = group[student] || { data: new Array(assessments.length), label: student, fill: false}
if (passing === 'TRUE' && !group[student].data[assessmentIndex]) {
group[student].data[assessmentIndex] = date ? moment(date.split(' ')[0]) : 0
}
return group
}, {})
}
module.exports = {
generate
}