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

Commit 42071d2

Browse files
committed
Sketch out DAG grader
1 parent 4e346cd commit 42071d2

4 files changed

Lines changed: 57 additions & 14 deletions

File tree

runestone/parsons/js/dagGrader.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import LineBasedGrader from "./lineGrader";
2+
3+
export default class DAGGrader extends LineBasedGrader {
4+
5+
inverseLISIndices(arr) {
6+
throw new Error("LIS algorithm for DAG grader not yet implemented.")
7+
}
8+
9+
checkCorrectOrdering(solutionLines, answerLines) {
10+
let isCorrectOrder = true;
11+
this.correctLines = 0;
12+
this.solutionLength = solutionLines.length;
13+
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 {
18+
this.correctLines += 1;
19+
}
20+
}
21+
return isCorrectOrder
22+
}
23+
24+
}

runestone/parsons/js/lineGrader.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class LineBasedGrader {
1+
export default class DAGGrader {
22
constructor(problem) {
33
this.problem = problem;
44
}
@@ -55,6 +55,8 @@ export default class LineBasedGrader {
5555
this.incorrectIndents = 0;
5656
var solutionLines = problem.solution;
5757
var answerLines = problem.answerLines();
58+
console.log(solutionLines)
59+
console.log(answerLines)
5860
var i;
5961
var state;
6062
this.percentLines =
@@ -72,17 +74,7 @@ export default class LineBasedGrader {
7274
// Determine whether the code **that is there** is in the correct order
7375
// If there is too much or too little code this only matters for
7476
// calculating a percentage score.
75-
let isCorrectOrder = true;
76-
this.correctLines = 0;
77-
this.solutionLength = solutionLines.length;
78-
let loopLimit = Math.min(solutionLines.length, answerLines.length);
79-
for (i = 0; i < loopLimit; i++) {
80-
if (answerLines[i].text !== solutionLines[i].text) {
81-
isCorrectOrder = false;
82-
} else {
83-
this.correctLines += 1;
84-
}
85-
}
77+
let isCorrectOrder = this.checkCorrectOrdering(solutionLines, answerLines)
8678

8779
// Determine whether blocks are indented correctly
8880
this.indentLeft = [];
@@ -110,9 +102,26 @@ export default class LineBasedGrader {
110102
}
111103
this.calculatePercent();
112104
this.graderState = state;
105+
106+
console.log(state)
113107
return state;
114108
}
115109

110+
checkCorrectOrdering(solutionLines, answerLines) {
111+
let isCorrectOrder = true;
112+
this.correctLines = 0;
113+
this.solutionLength = solutionLines.length;
114+
let loopLimit = Math.min(solutionLines.length, answerLines.length);
115+
for (i = 0; i < loopLimit; i++) {
116+
if (answerLines[i].text !== solutionLines[i].text) {
117+
isCorrectOrder = false;
118+
} else {
119+
this.correctLines += 1;
120+
}
121+
}
122+
return isCorrectOrder
123+
}
124+
116125
calculatePercent() {
117126
let numLines = this.percentLines * 0.2;
118127
let lines = this.problem.answerLines().length;

runestone/parsons/js/parsons.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import "./prettify.js";
2828
import "../css/parsons.css";
2929
import "../css/prettify.css";
3030
import LineBasedGrader from "./lineGrader";
31+
import DAGGrader from "./dagGrader";
3132
import ParsonsLine from "./parsonsLine";
3233
import ParsonsBlock from "./parsonsBlock";
3334

@@ -76,7 +77,7 @@ export default class Parsons extends RunestoneBase {
7677
// }
7778
// }
7879
this.initializeOptions();
79-
this.grader = new LineBasedGrader(this);
80+
this.grader = this.options.grader === "dag" ? new DAGGrader(this) : new LineBasedGrader(this);
8081
this.grader.showfeedback = this.showfeedback;
8182
var fulltext = $(this.origElem).html();
8283
this.blockIndex = 0;
@@ -101,7 +102,9 @@ export default class Parsons extends RunestoneBase {
101102
var noindent = $(this.origElem).data("noindent");
102103
var adaptive = $(this.origElem).data("adaptive");
103104
var numbered = $(this.origElem).data("numbered");
105+
var grader = $(this.origElem).data("grader");
104106
options["numbered"] = numbered;
107+
options["grader"] = grader;
105108
if (maxdist !== undefined) {
106109
options["maxdist"] = maxdist;
107110
}

runestone/parsons/parsons.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def setup(app):
4141

4242
TEMPLATE_END = """
4343
</div>
44-
<pre class="parsonsblocks" data-question_label="%(question_label)s" %(adaptive)s %(maxdist)s %(order)s %(noindent)s %(language)s %(numbered)s %(optional)s style="visibility: hidden;">
44+
<pre class="parsonsblocks" data-question_label="%(question_label)s" %(adaptive)s %(maxdist)s %(order)s %(noindent)s %(language)s %(grader)s %(numbered)s %(optional)s style="visibility: hidden;">
4545
%(code)s
4646
</pre>
4747
</div>
@@ -125,6 +125,7 @@ def findmax(alist):
125125
"noindent": directives.flag,
126126
"adaptive": directives.flag,
127127
"numbered": directives.unchanged,
128+
"grader": directives.unchanged
128129
}
129130
)
130131
has_content = True
@@ -199,6 +200,12 @@ def findmax(alist):
199200
)
200201
else:
201202
self.options["language"] = ""
203+
if "grader" in self.options:
204+
self.options["grader"] = (
205+
' data-grader="' + self.options["grader"] + '"'
206+
)
207+
else:
208+
self.options["grader"] = ""
202209

203210
if "-----" in self.content:
204211
index = self.content.index("-----")

0 commit comments

Comments
 (0)