|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
define('IGNORE_LTI', true); |
|
4
|
|
|
require_once __DIR__ . '/../course/common.inc.php'; |
|
5
|
|
|
|
|
6
|
|
|
// http://paletton.com/#uid=33s0u0koA++cP+Mj9+Yus+WMOZA |
|
7
|
|
|
define('TRANSPARENT', 'rgba(0, 0, 0, 0)'); |
|
8
|
|
|
define('HIGH_STROKE', '#6ed0ff'); // less light blue |
|
9
|
|
|
define('HIGH_FILL', TRANSPARENT); |
|
10
|
|
|
define('THIRD_QUARTILE_STROKE', TRANSPARENT); |
|
11
|
|
|
define('THIRD_QUARTILE_FILL', '#9ddffe'); // light blue |
|
12
|
|
|
define('MEDIAN_STROKE', '#fff'); // white |
|
13
|
|
|
define('MEDIAN_FILL', THIRD_QUARTILE_FILL); |
|
14
|
|
|
define('FIRST_QUARTILE_STROKE', TRANSPARENT); |
|
15
|
|
|
define('FIRST_QUARTILE_FILL', '#ffe399'); // light yellow |
|
16
|
|
|
define('LOW_STROKE', '#ff3f0c'); // medium red |
|
17
|
|
|
define('LOW_FILL', '#fff'); // white |
|
18
|
|
|
define('SCORE_STROKE', '#000'); // black |
|
19
|
|
|
define('SCORE_FILL', TRANSPARENT); |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
$points = 0; |
|
23
|
|
|
function normalize($numerator, $denominator = false) |
|
24
|
|
|
{ |
|
25
|
|
|
global $points; |
|
|
|
|
|
|
26
|
|
|
if ($numerator === null) { |
|
27
|
|
|
return null; |
|
28
|
|
|
} |
|
29
|
|
|
$denominator = ($denominator !== false ? $denominator : $points); |
|
30
|
|
|
$points = $denominator; |
|
31
|
|
|
return ($denominator > 0 ? min(100, $numerator / $denominator * 100) : 100); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
header('Content-Type: application/javascript'); |
|
35
|
|
|
|
|
36
|
|
|
$toolbox->cache_pushKey(basename(__FILE__, '.js.php')); |
|
37
|
|
|
$toolbox->cache_pushKey($_REQUEST['advisee']); |
|
38
|
|
|
|
|
39
|
|
|
$analytics = $toolbox->cache_get('analytics'); |
|
40
|
|
|
if ($analytics === false) { |
|
41
|
|
|
exit; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
?> |
|
45
|
|
|
|
|
46
|
|
|
Chart.defaults.global.showTooltips = false; |
|
47
|
|
|
Chart.defaults.global.scaleShowLabels = false; |
|
48
|
|
|
Chart.defaults.global.scaleBeginAtZero = true; |
|
49
|
|
|
|
|
50
|
|
|
<?php foreach ($analytics as $course => $analytic) : ?> |
|
51
|
|
|
|
|
52
|
|
|
<?php |
|
53
|
|
|
|
|
54
|
|
|
$labels = array(); |
|
55
|
|
|
$max_scores = array(); |
|
56
|
|
|
$min_scores = array(); |
|
57
|
|
|
$medians = array(); |
|
58
|
|
|
$first_quartiles = array(); |
|
59
|
|
|
$third_quartiles = array(); |
|
60
|
|
|
$scores = array(); |
|
61
|
|
|
foreach ($analytic as $data) { |
|
62
|
|
|
// if ($data['points_possible'] > 0 && $data['max_score'] > 0) { |
|
|
|
|
|
|
63
|
|
|
$labels[] = addslashes($data['title']); |
|
64
|
|
|
$max_scores[] = normalize($data['max_score'], $data['points_possible']); |
|
65
|
|
|
$min_scores[] = normalize($data['min_score']); |
|
66
|
|
|
$medians[] = normalize($data['median']); |
|
67
|
|
|
$first_quartiles[] = normalize($data['first_quartile']); |
|
68
|
|
|
$third_quartiles[] = normalize($data['third_quartile']); |
|
69
|
|
|
if (empty($data['submission'])) { |
|
70
|
|
|
$scores[] = '""'; /* some assignments may not have grades */ |
|
71
|
|
|
} else { |
|
72
|
|
|
$scores[] = normalize($data['submission']['score']); |
|
73
|
|
|
} |
|
74
|
|
|
// } |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
?> |
|
78
|
|
|
|
|
79
|
|
|
var data = { |
|
80
|
|
|
labels: [<?= '"' . implode('", "', $labels) . '"' ?>], |
|
81
|
|
|
datasets: [ |
|
82
|
|
|
{ |
|
83
|
|
|
label: "Score", |
|
84
|
|
|
backgroundColor: "<?= SCORE_FILL ?>", |
|
85
|
|
|
borderColor: "<?= SCORE_STROKE ?>", |
|
86
|
|
|
data: [<?= implode(', ', $scores) ?>] |
|
87
|
|
|
}, |
|
88
|
|
|
{ |
|
89
|
|
|
label: "Low Score", |
|
90
|
|
|
backgroundColor: "<?= LOW_FILL ?>", |
|
91
|
|
|
borderColor: "<?= LOW_STROKE ?>", |
|
92
|
|
|
borderWidth: 1, |
|
93
|
|
|
radius: 0, |
|
94
|
|
|
tooltips: {enabled: false}, |
|
95
|
|
|
data: [<?= implode(', ', $min_scores) ?>] |
|
96
|
|
|
}, |
|
97
|
|
|
{ |
|
98
|
|
|
label: "First Quartile", |
|
99
|
|
|
backgroundColor: "<?= FIRST_QUARTILE_FILL ?>", |
|
100
|
|
|
borderColor: "<?= FIRST_QUARTILE_STROKE ?>", |
|
101
|
|
|
borderWidth: 0, |
|
102
|
|
|
radius: 0, |
|
103
|
|
|
tooltips: {enabled: false}, |
|
104
|
|
|
data: [<?= implode(', ', $first_quartiles) ?>] |
|
105
|
|
|
}, |
|
106
|
|
|
{ |
|
107
|
|
|
label: "Median", |
|
108
|
|
|
backgroundColor: "<?= MEDIAN_FILL ?>", |
|
109
|
|
|
borderColor: "<?= MEDIAN_STROKE ?>", |
|
110
|
|
|
borderWidth: 1, |
|
111
|
|
|
radius: 0, |
|
112
|
|
|
tooltips: {enabled: false}, |
|
113
|
|
|
data: [<?= implode(', ', $medians) ?>] |
|
114
|
|
|
}, |
|
115
|
|
|
{ |
|
116
|
|
|
label: "Third Quartile", |
|
117
|
|
|
backgroundColor: "<?= THIRD_QUARTILE_FILL ?>", |
|
118
|
|
|
borderColor: "<?= THIRD_QUARTILE_STROKE ?>", |
|
119
|
|
|
borderWidth: 0, |
|
120
|
|
|
radius: 0, |
|
121
|
|
|
tooltips: {enabled: false}, |
|
122
|
|
|
data: [<?= implode(', ', $third_quartiles) ?>] |
|
123
|
|
|
}, |
|
124
|
|
|
{ |
|
125
|
|
|
label: "High Score", |
|
126
|
|
|
backgroundColor: "<?= HIGH_FILL ?>", |
|
127
|
|
|
borderColor: "<?= HIGH_STROKE ?>", |
|
128
|
|
|
borderWidth: 1, |
|
129
|
|
|
radius: 0, |
|
130
|
|
|
tooltips: {enabled: false}, |
|
131
|
|
|
data: [<?= implode(', ', $max_scores) ?>] |
|
132
|
|
|
} |
|
133
|
|
|
] |
|
134
|
|
|
}; |
|
135
|
|
|
|
|
136
|
|
|
var options = { |
|
137
|
|
|
pointDot: false, |
|
138
|
|
|
scaleShowGridLines: false |
|
139
|
|
|
}; |
|
140
|
|
|
|
|
141
|
|
|
// Get context with jQuery - using jQuery's .get() method. |
|
142
|
|
|
var ctx = $("#course_<?= $course ?>").get(0).getContext("2d"); |
|
143
|
|
|
|
|
144
|
|
|
// TODO detect empty datasets and remove canvas and replace with message |
|
145
|
|
|
|
|
146
|
|
|
// This will get the first returned node in the jQuery collection. |
|
147
|
|
|
var chart = new Chart(ctx, { |
|
148
|
|
|
type: 'line', |
|
149
|
|
|
data: data, |
|
150
|
|
|
options: options |
|
151
|
|
|
}); |
|
152
|
|
|
|
|
153
|
|
|
<?php endforeach; ?> |
|
154
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.