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

Commit 8ed241d

Browse files
committed
Even better WW integration
1 parent 103cbe4 commit 8ed241d

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

runestone/webwork/js/webwork.js

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class WebWork extends RunestoneBase {
1111
this.multipleanswers = false;
1212
this.divid = opts.orig.id;
1313
this.correct = null;
14+
this.optional = false;
1415
this.answerList = [];
1516
this.correctList = [];
1617
this.question = null;
@@ -69,8 +70,43 @@ class WebWork extends RunestoneBase {
6970
);
7071
}
7172

73+
processCurrentAnswers(data) {
74+
let correctCount = 0;
75+
let qCount = 0;
76+
let actString = "check:";
77+
this.answerObj = {}
78+
this.lastAnswerRaw = data;
79+
80+
for (let k of Object.keys(data.rh_result.answers)) {
81+
qCount += 1;
82+
if (data.rh_result.answers[k].score == 1) {
83+
correctCount += 1;
84+
}
85+
this.answerObj[k] = `${data.rh_result.answers[k].original_student_ans}`
86+
actString += `actual:${data.rh_result.answers[k].original_student_ans}:expected:${data.rh_result.answers[k].correct_value}:`;
87+
}
88+
let pct = correctCount / qCount;
89+
// If this.percent is set, then runestonebase will transmit it as part of
90+
// the logBookEvent API.
91+
this.percent = pct;
92+
this.actString = actString + `correct:${correctCount}:count:${qCount}:pct:${pct}`;
93+
if (pct == 1.0) {
94+
this.correct = true;
95+
} else {
96+
this.correct = false;
97+
}
98+
99+
}
100+
72101
async logCurrentAnswer(sid) {
73-
// todo
102+
this.logBookEvent({
103+
event: "webwork",
104+
div_id: this.divid, //todo unmangle problemid
105+
act: this.actString,
106+
correct: this.correct,
107+
answer: JSON.stringify(this.answerObj),
108+
});
109+
74110
}
75111

76112
checkCurrentAnswer() {
@@ -79,39 +115,19 @@ class WebWork extends RunestoneBase {
79115

80116
}
81117

82-
// TODO - it would be better if we can get rid of this, and use the runestone object corresponding to the webwork question to make the logging calls. Or this could be a tiny wrapper because we can look up the object using inputs_ref.problemUUID.replace("-ww-rs","")
83-
let rb = new WebWork({orig:{id:"fakeww-ww-rs"}});
84118

119+
//
120+
// These are functions that get called in response to webwork generated events.
121+
// submitting the work, or showing an answer.
85122
function logWebWork(e, data) {
86-
var correct = false;
87-
let correctCount = 0;
88-
let qCount = 0;
89-
let actString = "check:";
90-
let answerObj = {}
91-
for (let k of Object.keys(data.rh_result.answers).sort()) {
92-
qCount += 1;
93-
if (data.rh_result.answers[k].score == 1) {
94-
correctCount += 1;
95-
}
96-
answerObj[k] = `${data.rh_result.answers[k].original_student_ans}`
97-
actString += `actual:${data.rh_result.answers[k].original_student_ans}:expected:${data.rh_result.answers[k].correct_value}:`;
98-
}
99-
let pct = correctCount / qCount;
100-
actString += `correct:${correctCount}:count:${qCount}:pct:${pct}`;
101-
if (pct == 1.0) {
102-
correct = true;
103-
}
104-
rb.logBookEvent({
105-
event: "webwork",
106-
div_id: data.inputs_ref.problemUUID.replace("-ww-rs",""), //todo unmangle problemid
107-
act: actString,
108-
correct: correct,
109-
answer: JSON.stringify(answerObj),
110-
});
123+
let wwObj = wwList[data.inputs_ref.problemUUID.replace("-ww-rs","")]
124+
wwObj.processCurrentAnswers(data);
125+
wwObj.logCurrentAnswer();
111126
}
112127

113128
function logShowCorrect(e, data) {
114-
rb.logBookEvent({
129+
let wwObj = wwList[data.inputs_ref.problemUUID.replace("-ww-rs","")]
130+
wwObj.logBookEvent({
115131
event: "webwork",
116132
div_id: data.inputs_ref.problemUUID,
117133
act: "show",

0 commit comments

Comments
 (0)