-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmaint.php
More file actions
227 lines (202 loc) · 7.85 KB
/
maint.php
File metadata and controls
227 lines (202 loc) · 7.85 KB
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
<?php
require_once "../config.php";
use \Tsugi\Grades\GradeUtil;
require_once "peer_util.php";
use \Tsugi\Core\LTIX;
// Sanity checks
$LAUNCH = LTIX::requireData();
if ( ! $USER->instructor ) die("Requires instructor");
$p = $CFG->dbprefix;
// No Buffering
$OUTPUT->noBuffer();
// Grab our link_id
$link_id = $LINK->id;
$assn = loadAssignment();
$assn_json = null;
$assn_id = false;
if ( $assn === false ) {
die("This peer-graded assignment is not yet configured");
} else {
$assn_json = json_decode(upgradeSubmission($assn['json']));
$assn_id = $assn['assn_id'];
}
if ( isset($_POST['restartReGrade']) ) {
$lstmt = $PDOX->queryDie(
"UPDATE {$p}peer_submit SET regrade=NULL
WHERE assn_id = :AID",
array(":AID" => $assn_id)
);
$msg = $lstmt->rowcount() . " Records reset.";
$_SESSION["success"] = $msg;
header("Location: ".addSession('maint.php'));
return;
}
if ( isset($_POST['catchupInstructor']) ) {
$lstmt = $PDOX->queryDie(
"UPDATE {$p}peer_submit SET inst_points=:IP
WHERE assn_id = :AID",
array(":IP" => $assn_json->instructorpoints, ":AID" => $assn_id)
);
$msg = $lstmt->rowcount() . " Records changed.";
$_SESSION["success"] = $msg;
header("Location: ".addSession('maint.php'));
return;
}
if ( isset($_POST['reGradePeer']) ) {
$OUTPUT->header();
echo($OUTPUT->togglePreScript());
echo("</head><body>\n");
session_write_close();
$stmt = $PDOX->queryDie(
"SELECT submit_id, S.user_id AS user_id, R.result_id AS result_id,
grade, sourcedid, result_url, service_key, displayname, email
FROM {$CFG->dbprefix}peer_submit AS S
JOIN {$CFG->dbprefix}peer_assn AS A
ON S.assn_id = A.assn_id
JOIN {$CFG->dbprefix}lti_result AS R
ON S.user_id = R.user_id AND A.link_id = R.link_id
JOIN {$CFG->dbprefix}lti_user AS U
ON R.user_id = U.user_id
LEFT JOIN {$CFG->dbprefix}lti_service AS X
ON R.service_id = X.service_id
WHERE S.assn_id = :AID AND regrade IS NULL",
array(":AID" => $assn_id)
);
$unchanged = 0;
$changed = 0;
$fail = 0;
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
$computed_grade = computeGrade($assn_id, $assn_json, $row['user_id']);
$s2 = $PDOX->queryDie(
"UPDATE {$CFG->dbprefix}peer_submit SET regrade=1
WHERE submit_id = :SID",
array(":SID" => $row['submit_id'])
);
if ( $row['grade'] >= $computed_grade ) {
echo(htmlentities($row['displayname'] ?? '').' ('.htmlentities($row['email'] ?? '').') ');
if ( $row['grade'] > $computed_grade ) {
echo('grade='.$row['grade'].' computed='.$computed_grade." (unchanged)<br/>\n");
} else {
echo('grade='.$row['grade']." (matched)<br/>\n");
}
$unchanged++;
continue;
}
$s2 = $PDOX->queryDie(
"UPDATE {$CFG->dbprefix}lti_result
SET grade=:GRA, updated_at=NOW()
WHERE result_id = :RID",
array(":GRA" => $computed_grade, ":RID" => $row['result_id'])
);
// Send the grade to the server
$status = LTIX::gradeSend($computed_grade, $row); // This is the slow bit
if ( $status === true ) {
echo(htmlentities($row['displayname'] ?? '').' ('.htmlentities($row['email'] ?? '').') ');
echo("Grade $computed_grade submitted to server<br/>\n");
$changed++;
} else {
echo('<pre class="alert alert-danger">'."\n");
$msg = "result_id=".$row['result_id']."\n".
"grade=".$row['grade']." computed_grade=".$computed_grade."\n".
"error=".$status;
echo_log("Problem Sending Grade: ".session_id()."\n".$msg."\n".
"result_url=".$row['result_url'].
" service_key=".$row['service_key']." sourcedid=".$row['sourcedid']);
echo("</pre>\n");
$OUTPUT->togglePre("Error sending grade",$LastPOXGradeResponse);
flush();
echo("Problem sending grade ".$status."<br/>\n");
$fail++;
continue;
}
flush();
}
echo("<p>Run complete unchanged=$unchanged changed=$changed send failure=$fail</p>\n");
echo('<script type="text/javascript"> alert("Recompute Grades Complete"); </script>');
return;
}
$menu = new \Tsugi\UI\MenuSet();
$menu->addLeft(__('Back'), 'index.php');
// View
$OUTPUT->header();
?>
<script type="text/javascript">
function showFrame() {
document.getElementById('iframediv').style.display = "block";
}
</script>
<?php
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
$OUTPUT->flashMessages();
$iframeurl = addSession($CFG->getCurrentUrl().'?link_id=' . $link_id);
?>
<div>
<form style="display: inline" method="post">
<button name="catchupInstructor" class="btn btn-warning">Catch Up Instructor Points</button>
</form>
<form style="display: inline" method="post">
<button name="restartReGrade" class="btn btn-warning">Restart Re-Grade</button>
</form>
<form style="display: inline" method="post" target="my_iframe" action="<?php echo($iframeurl); ?>">
<button name="reGradePeer" onclick="showFrame();" class="btn btn-warning">Re-Compute Peer Grades</button>
</form>
<p>These are maintenance tools make sure you know how to use them.
<ul>
<li><b>Catch Up Instructor Points</b> If the instructor points have changed (currently
<?= $assn_json->instructorpoints ?>) you can set all of the submissions to have the new
instructor point value. This allows you to catch up with instructor grading if
you turn it on after submissions are already in progress.
</li>
<li><b>Re-Compute Peer Grades</b> Loops through all peer-graded submissions
and re-computes the effective grade, checking to see if the local grade
is correct. If there is a mis-match, the local grade is updated
and the new grade is sent to the server. This process can be stopped
and restarted as it marks entries once they have been regraded.
</li>
<li><b>Restart Re-Grades</b> Clears the "regraded" flag for all subissions so that the
next <b>Re-Compute Peer Grades</b> starts from the beginning.
</li>
</ul>
<pre>
Context: <?php echo($CONTEXT->id);
if ( isset($CONTEXT->title) ) echo(' '.htmlentities($CONTEXT->title)) ; ?>
Link id: <?php echo($link_id);
if ( isset($LINK->title) ) echo(' '.htmlentities($LINK->title)) ; ?>
</pre>
<p><b>Remaining Regrades:</b> <span id="total"></span>
<img id="totspinner" src="<?php echo($OUTPUT->getSpinnerUrl()); ?>" style="display:none">
</p>
<div id="iframediv" style="display:none">
<p>Depending on buffering - output in this iframe may take a while to appear.
The number above will update as the job progreses.
Once the output starts, make sure to scroll to the bottom to see the current activity.
If you want to abort this job, navigate away using "Exit".
This job may take so long it times out. If it times out you can restart it
and it willpick up where it left off.
</p>
<iframe name="my_iframe" id="my_iframe" width="98%" height="600px" style="border: 1px black solid">
</iframe>
</div>
<?php
$OUTPUT->footerStart();
?>
<script type="text/javascript">
$UPDATE_INTERVAL = false;
function updateNumbers() {
window.console && console.log('Calling updateNumbers');
$.ajaxSetup({ cache: false }); // For IE...
$.getJSON('<?php echo(addSession($CFG->getCurrentUrlFolder().'/maintcount.php')); ?>',
function(data) {
if ( $UPDATE_INTERVAL === false ) $UPDATE_INTERVAL = setInterval(updateNumbers,10000);
window.console && console.log(data);
$('#totspinner').hide();
oldtotal = $('#total').text();
$('#total').text(data.total);
if ( oldtotal.length > 1 && oldtotal != data.total ) $('#totspinner').show();
});
}
updateNumbers();
</script>
<?php
$OUTPUT->footerEnd();