forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolt_map.php
469 lines (427 loc) · 11.8 KB
/
bolt_map.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// actions:
// (none)
// if have a snapshot, show start/end
// show form to get new snapshot
// snap_action
// make new snapshot and go to...
// map
// show a map;
// show form to set or change filter or breakdown
//
// columns:
// name
// type
// breakdown category (if using breakdown)
// nviews (as number)
// outcome (as color-coded bar graph: green=next, yellow=back, red=none)
// time (bar graph of log(t))
// score (bar graph)
//
// what's shown:
// lessons: nviews, outcome, time
// exercise: nviews, outcome, time, score
// exercise answer: nviews, outcome, time
// exercise set: score
//
// When breakdown is used, each of above has N lines
// Total, followed by each breakdown category
require_once("../inc/bolt_util_ops.inc");
require_once("../inc/bolt_db.inc");
require_once("../inc/bolt_cat.inc");
require_once("../inc/bolt.inc");
require_once("../inc/bolt_snap.inc");
// the following are to minimize argument passing
$snap = null;
$course_id = 0;
$top_unit = null;
$filter = null;
$filter_cat = null;
$breakdown = null;
$breakdown_cat = null;
function show_snap_form() {
global $course_id;
admin_page_head("Data snapshot");
$s = read_map_snapshot($course_id);
if ($s) {
$end = date_str($s->time);
echo "
A data snapshot exists for the $s->dur days prior to $end.
";
show_button(
"bolt_map.php?action=map&course_id=$course_id",
"Use this snapshot",
"Use this snapshot"
);
} else {
echo "There is currently no snapshot.";
}
echo "
<form action=bolt_map.php>
<input type=hidden name=action value=snap_action>
<input type=hidden name=course_id value=$course_id>
Create a new snapshot using data from the last
<input name=dur value=7> days.
<input type=submit value=OK>
</form>
";
admin_page_tail();
}
function snap_action() {
global $course_id;
global $top_unit;
$dur = get_int('dur');
$s = write_map_snapshot($course_id, $dur);
show_map();
}
function spaces($level) {
$x = "";
for ($i=0; $i<$level; $i++) {
$x .= " ";
}
return $x;
}
// filter arrays of anything that has a user_id field
// (view, xset_result, question)
//
function filter_array($array) {
global $snap, $filter, $filter_cat, $breakdown, $breakdown_cat;
if (!$filter && !$breakdown) return $array;
$x = array();
foreach ($array as $y) {
if (!array_key_exists($y->user_id, $snap->users)) continue;
$u = $snap->users[$y->user_id];
if ($filter && $filter->categorize($u) != $filter_cat) {
continue;
}
if ($breakdown && $breakdown_cat) {
if ($breakdown->categorize($u) != $breakdown_cat) {
continue;
}
}
$x[] = $y;
}
return $x;
}
function avg_score($array) {
$sum = 0;
$n = count($array);
if ($n ==0) return 0;
foreach ($array as $a) {
$sum += $a->score;
}
return $sum/count($array);
}
function avg_time($views) {
$sum = 0;
$n = 0;
foreach ($views as $v) {
if ($v->start_time && $v->end_time) {
$sum += $v->end_time - $v->start_time;
$n++;
}
}
if ($n ==0) return 0;
return $sum/$n;
}
function outcomes($views) {
$x = array();
$x[0] = 0;
$x[1] = 0;
$x[2] = 0;
foreach ($views as $v) {
switch ($v->action) {
case BOLT_ACTION_NONE: $x[0]++; break;
case BOLT_ACTION_NEXT: $x[1]++; break;
case BOLT_ACTION_SUBMIT: $x[1]++; break;
default: $x[2]++; break;
}
}
return $x;
}
function get_nquestions($unit, $mode) {
global $snap;
if (array_key_exists($unit->name, $snap->questions)) {
$a = filter_array($snap->questions[$unit->name]);
$n = 0;
foreach ($a as $q) {
if ($q->mode == $mode) $n++;
}
return $n;
}
return 0;
}
function get_views($unit, $mode) {
global $snap;
$y = array();
if (array_key_exists($unit->name, $snap->views)) {
$a = filter_array($snap->views[$unit->name]);
foreach ($a as $x) {
if ($x->mode == $mode) $y[] = $x;
}
}
return $y;
}
function get_results($unit) {
global $snap;
if (array_key_exists($unit->name, $snap->results)) {
return filter_array($snap->results[$unit->name]);
}
return array();
}
function get_xset_results($unit) {
global $snap;
if (array_key_exists($unit->name, $snap->xset_results)) {
return filter_array($snap->xset_results[$unit->name]);
}
return array();
}
function class_name($class) {
switch ($class) {
case "BoltSequence": return "sequence";
case "BoltSelect": return "select";
case "BoltLesson": return "lesson";
case "BoltExercise": return "exercise";
case "BoltExerciseSet": return "exercise set";
case "BoltRandom": return "random";
}
}
$rownum = 0;
function show_unit_row($unit, $class, $level, $is_answer) {
global $breakdown, $breakdown_cat;
global $rownum, $course_id;
$a = $is_answer?" (answer)":"";
$j = ($rownum++)%2;
echo "<tr class=row$j>";
if ($breakdown && $breakdown_cat) {
echo "
<td><br></td>
<td><br></td>
";
} else {
$c = class_name($class);
echo "
<td><b>".spaces($level)."$unit->name</b></td>
<td>$c $a</td>
";
}
if ($breakdown) {
if ($breakdown_cat) {
echo "<td>$breakdown_cat</td>\n";
} else {
echo "<td>Total</td>\n";
}
}
switch ($class) {
case "BoltLesson":
$mode = BOLT_MODE_LESSON;
$views = get_views($unit, $mode);
$n = count($views);
$out = outcomes($views);
$t = avg_time($views);
echo "<td>$n</td>";
$n = get_nquestions($unit, $mode);
if ($n) {
echo "<td><a href=bolt_map.php?action=questions&course_id=$course_id&name=$unit->name&mode=$mode".filter_url().">$n</a></td>\n";
} else {
echo "<td>0</td>\n";
}
echo outcome_graph($out, 200);
echo empty_cell();
echo time_graph($t, 200);
break;
case "BoltExercise":
$mode = $is_answer?BOLT_MODE_ANSWER:BOLT_MODE_SHOW;
$views = get_views($unit, $mode);
$n = count($views);
$out = outcomes($views);
$t = avg_time($views);
echo "<td>$n</td>";
$n = get_nquestions($unit, $mode);
if ($n) {
echo "<td><a href=bolt_map.php?action=questions&course_id=$course_id&name=$unit->name&mode=$mode>$n</a></td>\n";
} else {
echo "<td>0</td>\n";
}
echo outcome_graph($out, 200);
if ($is_answer) {
echo empty_cell();
} else {
$results = get_results($unit);
$score = avg_score($results);
echo score_graph($score, 200);
}
echo time_graph($t, 200);
break;
case "BoltExerciseSet":
$xr = get_xset_results($unit);
$n = count($xr);
echo "<td>$n</td>";
echo empty_cell();
echo empty_cell();
$score = avg_score($xr);
echo score_graph($score, 200);
echo empty_cell();
break;
default:
echo empty_cell();
echo empty_cell();
echo empty_cell();
echo empty_cell();
echo empty_cell();
}
echo "</tr>\n";
}
function breakdown_class($class) {
switch ($class) {
case "BoltLesson":
case "BoltExercise":
case "BoltExerciseSet":
return true;
}
return false;
}
function show_unit($unit, $level) {
global $snap, $filter, $filter_cat, $breakdown, $breakdown_cat;
$class = get_class($unit);
$breakdown_cat = null;
show_unit_row($unit, $class, $level, false);
if ($breakdown && breakdown_class($class)) {
foreach ($breakdown->categories() as $c) {
$breakdown_cat = $c;
show_unit_row($unit, $class, $level, false);
}
}
// if exercise, show answer page views
//
if ($class == "BoltExercise") {
$breakdown_cat = null;
show_unit_row($unit, $class, $level, true);
if ($breakdown) {
foreach ($breakdown->categories() as $c) {
$breakdown_cat = $c;
show_unit_row($unit, $class, $level, true);
}
}
}
}
function show_unit_recurse($unit, $level) {
show_unit($unit, $level);
if ($unit->is_item) return;
foreach ($unit->units as $u) {
show_unit_recurse($u, $level+1);
}
}
function show_map() {
global $snap, $course_id, $top_unit, $filter, $filter_cat, $breakdown;
global $course;
get_filters_from_form();
admin_page_head("Course map for '$course->name'");
bolt_style();
$snap = read_map_snapshot($course_id);
start_table();
echo "
<tr>
<th>Name</th>
<th>Type</th>
";
if ($breakdown) {
echo "<th>Group</th>";
}
echo "
<th>Views</th>
<th>Questions</th>
<th>Outcome<br>
<span class=green>Next</span>
<span class=yellow>Back</span>
<span class=red>None</span>
</th>
<th>Score</th>
<th>Time</th>
</tr>
";
show_unit_recurse($top_unit, 0);
echo "
</table>
<form action=bolt_map.php>
<input type=hidden name=action value=map>
<input type=hidden name=course_id value=$course_id>
<table width=600><tr><td valign=top>
";
filter_form($filter?$filter->name():"", $filter_cat);
echo "</td><td valign=top>";
breakdown_form($breakdown?$breakdown->name():"");
echo "
</td></tr></table>
<p>
<input type=submit value=OK>
</form>
";
admin_page_tail();
}
function show_questions() {
global $course_id;
$name = get_str('name');
$mode = get_int('mode');
get_filters_from_form();
$snap = read_map_snapshot($course_id);
$qs = $snap->questions[$name];
admin_page_head("Questions about $name");
start_table();
echo "<tr>
<th>When</th>
<th>Who</th>
<th>Question</th>
</tr>
";
foreach ($qs as $q) {
if ($q->mode != $mode) continue;
$user = $snap->users[$q->user_id];
echo "<tr>
<td>".time_str($q->create_time)."</td>
<td><a href=student>$user->name</td>
<td>$q->question</td>
</tr>
";
}
end_table();
admin_page_tail();
}
$course_id = get_int('course_id');
$course = BoltCourse::lookup_id($course_id);
if (!$course) error_page("no course");
$top_unit = require_once($course->doc_file());
$action = get_str('action', true);
switch ($action) {
case "":
show_snap_form();
break;
case "snap_action":
snap_action();
break;
case "map":
show_map();
break;
case "questions":
show_questions();
break;
default:
error_page("Unknown action $action");
}
?>