-
Notifications
You must be signed in to change notification settings - Fork 2
/
archimedes_hook.php
135 lines (113 loc) · 4.46 KB
/
archimedes_hook.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
<?php
header('Content-Type: text/plain');
/**
* This file is specifically to help convert from this tool
* to the hybrid rubrics of https://github.com/tychonievich/archimedes
* It does not do the full job, just enough to make my draft hooks work.
* Full integration may be added at a future time.
*/
require_once "tools.php";
if (!$isstaff) {
http_response_code(403);
die('staff use only');
}
/** Return an array of the form
*
* {slug:{user:[{"ratio":1,"weight":2,"name":"Question 8"},...],...},...}
*
* if given a first argument that is true, adds user:false for each user who ever viewed any quiz
*/
function all_grades($pad = FALSE, &$rubric=FALSE) {
$quizzes = array();
if ($pad) $everyone = array();
foreach(glob("questions/*.md") as $i=>$fname) {
$qid = pathinfo($fname, PATHINFO_FILENAME);
$qobj = qparse($qid);
if ($qobj['due'] > time() || $qobj['keyless']) continue;
$quizzes[$qid] = array();
foreach(glob("log/$qid/*.log") as $j=>$logname) {
$sid = pathinfo($logname, PATHINFO_FILENAME);
if ($pad) $everyone[$sid] = true;
$quizzes[$qid][$sid] = array();
$sobj = aparse($qobj, $sid);
grade($qobj, $sobj);
$qnum = 0;
if ($rubric !== FALSE && !isset($rubric[$qid])) $hr = array();
else $hr = False;
foreach($qobj['q'] as $mq) foreach($mq['q'] as $q) {
$qnum += 1;
// grade always sets ['score'], even if student skipped the question, unless the question is ungradeable (dropped, image, text with no key, etc)
if (!isset($sobj[$q['slug']]['score'])) $weight = 0;
else $weight = $q['points'];
$ratio = $weight ? $sobj[$q['slug']]['score'] / $weight : 1;
$name = "Question $qnum (worth $weight pt)";
if ($hr !== FALSE) $hr[] = array(
'name'=>$name,
'weight'=>$weight,
);
$quizzes[$qid][$sid][] =
array(
'ratio'=> $ratio,
'weight'=>$weight,
'name'=>$name,
);
}
if ($hr !== FALSE) $rubric[$qid] = $hr;
}
}
if ($pad) {
foreach($quizzes as $k=>&$val)
foreach($everyone as $uid=>$true)
if (!isset($val[$uid])) $val[$uid] = false;
}
return $quizzes;
}
/** Experimental and dangerous: creates, and overrides if present, "$prefix$slug/$user/.grade" */
function post_grades($prefix, $special=array()) {
global $metadata;
$rubrics = array();
foreach(all_grades(true, $rubrics) as $qid => $users) {
if (qparse($qid)['keyless']) continue;
if (isset($special[$qid]) && !$special[$qid]) continue;
$dir = "$prefix$qid/";
$qname = "$metadata[quizname] $qid";
if (isset($special[$qid])) {
$dir = dirname($prefix)."/$special[$qid]/";
$qname = "$special[$qid]";
}
file_put_contents_recursive("$dir.rubric", json_encode(array(
"kind"=>"hybrid",
"late-penalty"=>1,
"auto-weight"=>0,
"human"=>$rubrics[$qid],
)));
foreach($users as $user=>$human) {
//if ($user != 'lat7h') continue;
if ($human === false ) {
file_put_contents_recursive("$dir$user/.grade", '{"kind":"percentage","ratio":0,"comments":"did not take '.$qname.'"}');
} else {
file_put_contents_recursive("$dir$user/.grade",
json_encode(array(
"kind"=>"hybrid",
"auto"=>1,
"auto-late"=>1,
"late-penalty"=>1,
"auto-weight"=>0,
"human"=>$human,
"comments"=>"see the quizzing site for details",
)));
}
}
}
}
if (php_sapi_name() == "cli") { // command line
// record as grades
post_grades("../uploads/Quiz", array('exam2'=>'Exam2', 'labs'=>false));
} else if (basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) {
// display
header('Content-Type: text/plain; charset=utf-8');
echo json_encode(all_grades(), JSON_PRETTY);
} else {
// show nothing, just define the functions
}
?>