forked from howardpchen/capricorn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats_classcomparison.php
192 lines (157 loc) · 6.31 KB
/
stats_classcomparison.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/*
Capricorn - Open-source analytics tool for radiology residents.
Copyright (C) 2014 (Howard) Po-Hao Chen
This file is part of Capricorn.
Capricorn is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (isset($_GET['yrend'])) $yrend = floatval($_GET['yrend']); // The final year to use (until July 1 for the calculation).
else {
// If not set, then use the most recent elapsed July 1.
$thisJulyFirst = thisJulyFirst();
$yrend = intval($thisJulyFirst->format("Y"));
}
if (isset($_GET['yrstr'])) $yrstr = floatval($_GET['yrstr']);
else $yrstr = $yrend - 5; // By Default use 5 years for averaging.
if (isset($_GET['sigma'])) $sig = floatval($_GET['sigma']);
else $sig = 0.674;
/* echoYouVSClassGraph
This assembles a graph that allows the trainee to compare their progress with
their classmates over a given academic year.
The function uses their year-to-date performance to estimate for the rest of the year
The data array should look like this:
$data['Trainee1'] = 120;
$data['Trainee2'] = 100;
$data['Trainee3'] = 10;
$data['Trainee4'] = 1029;
$data['Trainee5'] = 320;
*/
function echoYouVSClassGraphJS($data) {
global $examCountGoal;
// Sort the data in an ascending fashion
// This function preserves the key, value relationships
asort($data);
// Mask the other trainees and set the logged in user to You.
$id = 1;
$graph_data = array();
foreach ($data as $key => $value) {
if ($key == $_SESSION['traineeid']) {
$graph_data['You'] = $value;
} else {
$graph_data['R'. $id] = $value;
$id++;
}
}
// Prepare $categories JSON from the $graph_data array
$categories = json_encode(array_keys($graph_data));
$today = new DateTime('NOW');
$nextJuneThirty = nextJuneThirty();
// Now we take the counts and turn them into projections
$daysLeft = $nextJuneThirty->diff($today)->format("%a");
$daysSoFar = $today->diff(thisJulyFirst())->format("%a");
// Update the $graph_data array with projected data
// Format the data as expected in the JSON object for
// highcharts and make the projection calculation
$series_data = array();
$sum = 0;
$max = $examCountGoal * 1.20; // Set the Y axis to 20% more than the goal
foreach($graph_data as $key => $value) {
// We are ignoring vacation days, which admittedly adds some noise
$projectedValue = $value + ($value/$daysSoFar) * $daysLeft;
$sum += $projectedValue;
// Adjust the Y axis if someone is killing the goal
if ($max < $projectedValue) $max = $projectedValue * 1.1;
if ($key == 'You') {
$series_data[] = array('name' => $key, 'y' => $projectedValue, 'color' => 'red');
} else {
$series_data[] = array('name' => $key, 'y' => $projectedValue);
}
}
// Calculate the average to display as a plotLine below
$average = $sum / count($data);
$examCountGoal = (isset($examCountGoal) ? $examCountGoal : 40 * 310); // assuming 40 exams/day 310 workdays
$series_data = json_encode($series_data);
echo <<< END
<script>
<!--
$(function () {
$('#projected').highcharts({
chart: {
type: 'column',
backgroundColor:'rgba(255, 255, 255, 0.0)'
},
legend: {
enabled: false
},
title: {
text: 'Projected Exam Counts For Your Class This Academic Year'
},
xAxis: {
categories: $categories
},
yAxis: {
min: 0,
max: $max,
plotLines: [{
id: 'average',
label: {
text: 'average'
},
dashStyle: 'LongDashDot',
color: 'purple',
value: $average,
width: 1
},{
id: 'goal',
label: {
text: 'goal'
},
dashStyle: 'Dot',
color: 'green',
value: $examCountGoal,
width: 1
}],
title: {
text: 'Exams'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
data: $series_data
}]
});
});
//-->
</script>
END;
}
// PGY based on current user,
// '%' = all sections
// '%' = all types
// '' = all notes
// startDate = thisJulyFirst()
$data = getOverallCountArray(getLoginUserPGY() - 1, '%', '%', '', thisJulyFirst()->format('Y-m-d'), nextJuneThirty()->format('Y-m-d'));
echoYouVSClassGraphJS($data);
makeDIV('projected', '750px', '400px'); // part of CapicornLib
?>