-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-distance.js
74 lines (63 loc) · 2.18 KB
/
edit-distance.js
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
// Copy paste this first into inspect element console.
/*
* Returns the the index of the rubric item to be selected. If the edit distance
* is 0, the DISTANCE_ITEMS[0]'th rubric item will be returned. If the edit
* distance is 1, the DISTANCE_ITEMS[1]'th item will be returned, etc. If the
* edit distance is too great, INCORRECT will be returned.
*/
function score() {
const DISTANCE_ITEMS = [0, 1];
const INCORRECT = 2;
const SOL = [false, false, true, true, true, false, false, false, false, true, false, false, false, false];
const checkboxes = Array.from(document.querySelectorAll("[id^='question_'] input[type='checkbox']"))
const marked = checkboxes.map((e) => e.checked);
let editDistance = 0;
for (let i = 0; i < SOL.length; i++) {
if (SOL[i] !== marked[i]) {
editDistance++;
}
}
let ret;
if (editDistance < DISTANCE_ITEMS.length) {
ret = DISTANCE_ITEMS[editDistance];
} else {
ret = INCORRECT;
}
return ret;
}
// Run score() on console to see if it produces the correct grade.
// Next, copy paste this into the console.
/*
* Grades the current submission based on the return value of score().
*/
function grade() {
let scoredRubric = score();
if (scoredRubric != null) {
let rubric = document.querySelectorAll('.rubricItem--key');
rubric[scoredRubric].click();
}
}
// Run grade() on console to see if the correct choice is selected.
// If it works, paste this input into the console to start the autograding
// procedure.
/*
* Starts the autograding by polling for changes in the href of the window.
* When it changes, we have successfully loaded the next submission, so we
* grade and then hit the "Next Ungraded" button again.
*/
{
let href = window.location.href;
let nextGraded = document.querySelector('[title="Shortcut: Z"]')
setInterval(() => {
/* Wait for updated URL. */
if (href != window.location.href) {
href = window.location.href;
/* Grade the submission. */
grade();
/* Go to next ungraded. */
nextGraded.click();
}
}, 50);
grade();
nextGraded.click();
}