Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 8a45b7b

Browse files
committed
First iteration of DAG checker working
1 parent 42071d2 commit 8a45b7b

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

runestone/parsons/js/dagGrader.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@ import LineBasedGrader from "./lineGrader";
33
export default class DAGGrader extends LineBasedGrader {
44

55
inverseLISIndices(arr) {
6-
throw new Error("LIS algorithm for DAG grader not yet implemented.")
6+
// TODO implement this properly for the DAG grader so that it is the shortest edit distance
7+
// to ANY of the correct solutions instead of just to the model solution
8+
return super.inverseLISIndices(arr)
79
}
810

911
checkCorrectOrdering(solutionLines, answerLines) {
12+
let seen = new Set();
1013
let isCorrectOrder = true;
1114
this.correctLines = 0;
1215
this.solutionLength = solutionLines.length;
1316
let loopLimit = Math.min(solutionLines.length, answerLines.length);
14-
for (i = 0; i < loopLimit; i++) {
15-
if (answerLines[i].text !== solutionLines[i].text) {
16-
isCorrectOrder = false;
17-
} else {
17+
for (let i = 0; i < loopLimit; i++) {
18+
let line = answerLines[i];
19+
for (let j = 0; j < line.depends.length; j++) {
20+
if (!seen.has(line.depends[j])) {
21+
isCorrectOrder = false;
22+
}
23+
}
24+
if (isCorrectOrder) {
1825
this.correctLines += 1;
1926
}
27+
seen.add(line.tag)
2028
}
2129
return isCorrectOrder
2230
}

runestone/parsons/js/lineGrader.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class DAGGrader {
1+
export default class LineBasedGrader {
22
constructor(problem) {
33
this.problem = problem;
44
}
@@ -55,8 +55,6 @@ export default class DAGGrader {
5555
this.incorrectIndents = 0;
5656
var solutionLines = problem.solution;
5757
var answerLines = problem.answerLines();
58-
console.log(solutionLines)
59-
console.log(answerLines)
6058
var i;
6159
var state;
6260
this.percentLines =
@@ -79,6 +77,7 @@ export default class DAGGrader {
7977
// Determine whether blocks are indented correctly
8078
this.indentLeft = [];
8179
this.indentRight = [];
80+
let loopLimit = Math.min(solutionLines.length, answerLines.length);
8281
for (i = 0; i < loopLimit; i++) {
8382
if (answerLines[i].viewIndent() < solutionLines[i].indent) {
8483
this.indentRight.push(answerLines[i]);
@@ -103,7 +102,6 @@ export default class DAGGrader {
103102
this.calculatePercent();
104103
this.graderState = state;
105104

106-
console.log(state)
107105
return state;
108106
}
109107

@@ -112,7 +110,7 @@ export default class DAGGrader {
112110
this.correctLines = 0;
113111
this.solutionLength = solutionLines.length;
114112
let loopLimit = Math.min(solutionLines.length, answerLines.length);
115-
for (i = 0; i < loopLimit; i++) {
113+
for (let i = 0; i < loopLimit; i++) {
116114
if (answerLines[i].text !== solutionLines[i].text) {
117115
isCorrectOrder = false;
118116
} else {

runestone/parsons/js/parsons.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ export default class Parsons extends RunestoneBase {
285285
var options = {};
286286
var distractIndex;
287287
var distractHelptext = "";
288+
var tagIndex;
289+
var tag;
290+
var dependsIndex;
291+
var depends = [];
288292
if (textBlock.includes("#paired:")) {
289293
distractIndex = textBlock.indexOf("#paired:");
290294
distractHelptext = textBlock
@@ -297,9 +301,17 @@ export default class Parsons extends RunestoneBase {
297301
.substring(distractIndex + 12, textBlock.length)
298302
.trim();
299303
textBlock = textBlock.substring(0, distractIndex + 11);
304+
305+
// TODO make this parsing more robust after finalizing the syntax
306+
} else if (textBlock.includes("#tag:")) {
307+
tagIndex = textBlock.indexOf("#tag:");
308+
tag = textBlock.substring(tagIndex + 5, tagIndex + 6);
309+
dependsIndex = textBlock.indexOf(";depends:");
310+
let dependsString = textBlock.substring(dependsIndex + 9, textBlock.indexOf(";", dependsIndex + 9));
311+
depends = dependsString.length > 0 ? dependsString.split(",") : [];
300312
}
301313
textBlock = textBlock.replace(
302-
/#(paired|distractor)/,
314+
/#(paired|distractor|tag:[0-9]+;depends:[0-9,]*;)/,
303315
function (mystring, arg1) {
304316
options[arg1] = true;
305317
return "";
@@ -325,6 +337,10 @@ export default class Parsons extends RunestoneBase {
325337
} else {
326338
line.distractor = false;
327339
line.paired = false;
340+
if (this.options.grader === "dag") {
341+
line.tag = tag;
342+
line.depends = depends;
343+
}
328344
solution.push(line);
329345
}
330346
if ($.inArray(line.indent, indents) == -1) {

0 commit comments

Comments
 (0)