Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
micro Parsons: fix grading for raw blocks
  • Loading branch information
zihan21206 committed May 10, 2023
commit 8d212165fd99420e725a07ce6077cd1bcf940bef
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"handsontable": "7.2.2",
"jexcel": "^3.9.1",
"jquery-ui": "1.10.4",
"micro-parsons": "https://github.com/amy21206/micro-parsons-element/releases/download/v0.1.5/micro-parsons-0.1.5.tgz",
"micro-parsons": "https://github.com/amy21206/micro-parsons-element/releases/download/v0.1.6/micro-parsons-0.1.6.tgz",
"select2": "^4.1.0-rc.0",
"sql.js": "1.5.0",
"vega-embed": "3.14.0",
Expand Down
31 changes: 25 additions & 6 deletions runestone/hparsons/js/BlockFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ export default class BlockFeedback extends HParsonsFeedback {
this.solved = false;
// TODO: not sure what is the best way to do this
this.grader = new BlockBasedGrader();
let solutionBlocks = [];
let solutionContent = [];
for (let i = 0; i < this.hparsons.blockAnswer.length; ++i) {
solutionBlocks.push(this.hparsons.originalBlocks[this.hparsons.blockAnswer[i]]);
if (this.hparsons.renderRaw) {
// if rendering raw (html): answer is text content instead of the original string
solutionContent.push(this.getContentFromRawString(this.hparsons.originalBlocks[this.hparsons.blockAnswer[i]]));
} else {
solutionContent.push(this.hparsons.originalBlocks[this.hparsons.blockAnswer[i]]);
}
}
this.solution = solutionBlocks;
this.grader.solution = solutionBlocks;
this.solution = solutionContent;
this.grader.solution = solutionContent;
this.answerArea = this.hparsons.hparsonsInput.querySelector('.drop-area');
}

Expand Down Expand Up @@ -57,7 +62,14 @@ export default class BlockFeedback extends HParsonsFeedback {
if (!this.solved) {
this.checkCount++;
this.clearFeedback();
this.grader.answer = this.hparsons.hparsonsInput.getParsonsTextArray();
if (this.hparsons.renderRaw) {
// when rendering raw: the answer is actually the text content.
this.grader.answer = this.hparsons.hparsonsInput.getParsonsTextArray().map((blockHTML) => {
return this.getContentFromRawString(blockHTML);
});
} else {
this.grader.answer = this.hparsons.hparsonsInput.getParsonsTextArray();
}
this.grade = this.grader.grade();
if (this.grade == "correct") {
$(this.hparsons.runButton).prop("disabled", true);
Expand Down Expand Up @@ -101,7 +113,9 @@ export default class BlockFeedback extends HParsonsFeedback {
var notInSolution = [];
for (let i = 0; i < answerBlocks.length; i++) {
var block = answerBlocks[i];
var index = this.solution.indexOf(block.textContent);
var index = this.hparsons.renderRaw ?
this.solution.indexOf(this.getContentFromRawString(block.innerHTML))
: this.solution.indexOf(block.textContent);
if (index == -1) {
notInSolution.push(block);
} else {
Expand All @@ -122,6 +136,11 @@ export default class BlockFeedback extends HParsonsFeedback {
feedbackArea.html($.i18n("msg_parson_wrong_order"));
}
}

getContentFromRawString(html) {
let doc = new DOMParser().parseFromString(html, "text/html");
return doc.body.textContent;
}

// Feedback UI for Block-based Feedback
clearFeedback() {
Expand Down