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

Commit 0fcbebe

Browse files
committed
cleanup function calls
1 parent e98ebad commit 0fcbebe

3 files changed

Lines changed: 11 additions & 23 deletions

File tree

runestone/parsons/js/dagGrader.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import LineBasedGrader from "./lineGrader";
22
import { DiGraph } from "jsnetworkx/node/classes";
33
import { hasPath } from "jsnetworkx/node/algorithms/shortestPaths/generic";
44

5-
function graphToNX(answerBlocks) {
5+
function graphToNX(answerLines) {
66
var graph = new DiGraph();
7-
for (let block of answerBlocks) {
8-
let line = block.lines[0]; // FIXME assume each block only has one line, won't work with adaptivity
7+
for (let line of answerLines) {
98
graph.addNode(line.tag);
109
for (let line2 of line.depends) {
1110
// the depends graph lists the *incoming* edges of a node
@@ -48,9 +47,13 @@ function allSubsets(arr) {
4847
export default class DAGGrader extends LineBasedGrader {
4948

5049

51-
inverseLISIndices(answerBlocks, solution) {
50+
inverseLISIndices(arr) {
5251
// For more details and a proof of the correctness of the algorithm, see the paper: https://arxiv.org/abs/2204.04196
53-
let graph = graphToNX(answerBlocks);
52+
53+
var solution = this.problem.solution;
54+
var answerLines = this.problem.answerLines();
55+
56+
let graph = graphToNX(answerLines);
5457
console.log(allSubsets([1,2,3]))
5558

5659
let seen = new Set();
@@ -96,7 +99,7 @@ export default class DAGGrader extends LineBasedGrader {
9699

97100
// TODO implement the algorithm properly for the DAG grader so that it is the shortest edit distance
98101
// to ANY of the correct solutions instead of just to the model solution
99-
return super.inverseLISIndices(answerBlocks, solution)
102+
return super.inverseLISIndices(arr)
100103
}
101104

102105
checkCorrectOrdering(solutionLines, answerLines) {

runestone/parsons/js/lineGrader.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@ export default class LineBasedGrader {
44
}
55
// Use a LIS (Longest Increasing Subsequence) algorithm to return the indexes
66
// that are not part of that subsequence.
7-
inverseLISIndices(answerBlocks, solution) {
8-
var inSolution = [];
9-
var inSolutionIndexes = [];
10-
var notInSolution = [];
11-
for (let i = 0; i < answerBlocks.length; i++) {
12-
var block = answerBlocks[i];
13-
var index = solution.indexOf(block.lines[0]);
14-
if (index == -1) {
15-
notInSolution.push(block);
16-
} else {
17-
inSolution.push(block);
18-
inSolutionIndexes.push(index);
19-
}
20-
}
21-
let arr = inSolutionIndexes;
22-
7+
inverseLISIndices(arr) {
238
// Get all subsequences
249
var allSubsequences = [];
2510
for (var i = 0; i < arr.length; i++) {

runestone/parsons/js/parsons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ export default class Parsons extends RunestoneBase {
14241424
inSolutionIndexes.push(index);
14251425
}
14261426
}
1427-
var lisIndexes = this.grader.inverseLISIndices(this.answerBlocks(), this.solution);
1427+
var lisIndexes = this.grader.inverseLISIndices(inSolutionIndexes);
14281428
for (let i = 0; i < lisIndexes.length; i++) {
14291429
notInSolution.push(inSolution[lisIndexes[i]]);
14301430
}

0 commit comments

Comments
 (0)