-
Notifications
You must be signed in to change notification settings - Fork 2
/
sheet.php
executable file
·72 lines (56 loc) · 2.05 KB
/
sheet.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
<?php
header('Content-Type: text/plain');
require_once "tools.php";
if (!$isstaff) {
http_response_code(403);
die('staff use only');
}
function showOne($qid) {
$qobj = qparse($qid);
if ($qobj['due'] > time() || $qobj['keyless']) return;
$outof = 0; foreach($qobj['q'] as $mq) foreach($mq['q'] as $q) $outof += $q['points'];
echo "compid,Quiz $qid [$outof],comments\n";
foreach(glob("log/$qid/*.log") as $j=>$logname) {
$student = pathinfo($logname, PATHINFO_FILENAME);
if (!preg_match('/^[a-z]*[0-9][a-z]*$/', $student)) continue; // needed?
$score = grade($qobj, $student)*$outof;
echo "$student,$score,\n";
}
}
function showAll() {
$took = array();
$qids = array();
$section = (isset($_GET['section'])) ? $_GET['section'] : FALSE;
if ($section) $smap = json_decode(file_get_contents('sections.json'), true);
echo "compid";
foreach(glob("questions/*.md") as $i=>$fname) {
$qid = pathinfo($fname, PATHINFO_FILENAME);
$qobj = qparse($qid);
if ($qobj['due'] > time() || $qobj['keyless']) continue;
$qids[] = $qid;
$outof = 0; foreach($qobj['q'] as $mq) foreach($mq['q'] as $q) $outof += $q['points'];
$worth[$qid] = $outof;
echo ",Quiz $qid [$outof]";
foreach(glob("log/$qid/*.log") as $j=>$logname) {
$student = pathinfo($logname, PATHINFO_FILENAME);
if ($section && $smap[$student] != $section) continue;
if (!preg_match('/^[a-z]*[0-9][a-z]*$/', $student)) continue; // needed?
if (!array_key_exists($student, $took)) $took[$student] = array();
$sid = $student;
$took[$sid][$qid] = grade($qobj, $student)*$outof;
}
}
foreach($took as $compid=>$scores) {
echo "\n$compid";
foreach($qids as $qid) {
echo ",".(isset($scores[$qid])? $scores[$qid] : 0);
}
}
echo "\n";
}
if (array_key_exists('quiz', $_GET)) {
showOne($_GET['quiz']);
} else {
showAll();
}
?>