Skip to content

Commit

Permalink
v2.11.0: also display questions in evaluation results (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienjoly committed May 29, 2018
1 parent da1292e commit 063b2e8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "js-test",
"version": "2.10.1",
"version": "2.11.0",
"description": "Exercise/exam software for evaluating JavaScript students' progress",
"repository": {
"type": "git",
Expand Down
24 changes: 22 additions & 2 deletions public/scripts/CodeEvaluatorGeneric.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function getVariantByStudentId (id, variants) {
var partLength = 10;
while (divident.length > partLength) {
var part = divident.substring(0, partLength);
divident = (part % divisor) + divident.substring(partLength);
divident = (part % divisor) + divident.substring(partLength);
}
return divident % divisor;
};
Expand Down Expand Up @@ -133,12 +133,28 @@ function makeCodeEvaluator(jailed, async, codeGradingOptions) {
return this.tests.length * COEF;
};

CodeEvaluator.prototype.evaluateAnswers = function(answers, callback) {
CodeEvaluator.prototype.evaluateAnswersEx = function(params, callback) {
var _this = this;
params = params || {};
var answers = params.answers;
var renderedQuestions = params.renderedQuestions;
function runExEval(exEval, callback) {
var variantNumber = getVariantByStudentId(answers._uid, exEval.variants);
var evalTest = exEval.testVariants[variantNumber];
console.log('\n------------- EXERCISE:', exEval.id, '(variant:', variantNumber + ') -------------\n');

if (renderedQuestions) {
var question = renderedQuestions
.find(q => q.id === exEval.id)
.mdVariants[variantNumber]
.replace(/<!--(.*?)-->/g, '')
.trim();
console.log([
'// QUESTION:',
question,
].join('\n\n') + '\n');
}

runTest(evalTest, answers[exEval.id], function(err, scoreArray) {
var pts = (scoreArray.reduce(sum) / scoreArray.length)
console.log('\n// -> EXERCISE POINTS:', pts * COEF + ' / ' + COEF);
Expand All @@ -157,6 +173,10 @@ function makeCodeEvaluator(jailed, async, codeGradingOptions) {
});
};

CodeEvaluator.prototype.evaluateAnswers = function(answers, callback) {
return this.evaluateAnswersEx({ answers: answers }, callback);
};

return CodeEvaluator;

};
Expand Down
27 changes: 24 additions & 3 deletions src/StudentEvaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ var converters = {
return function (studentAnswers, callback) {
console.log('\n - code evaluation:');
setConsolePrefix(' | ');
evaluator.evaluateAnswers(studentAnswers, function(err, res) {
var evalParams = {
renderedQuestions: rendered.questions,
answers: studentAnswers
};
evaluator.evaluateAnswersEx(evalParams, function(err, res) {
setConsolePrefix();
console.log('\n => code score:', res.score, '/', res.length, 'pts');
callback(err, res);
Expand All @@ -66,9 +70,26 @@ var converters = {
console.log('\n - quizz answers:');
setConsolePrefix(' | ');
var res = evaluator.evaluateAnswers(studentAnswers);
res.log.map(function(q){
console.log(q.questionId, ':', q.answer, '(solution: ' + q.solution + ') =>', q.points, 'pts');

var summary = res.log.map(function(q){
// display questions and choices
var question = rendered.questions.find(qu => qu.id === q.questionId);
console.log([
'\n------------- EXERCISE: ' + q.questionId + ' -------------',
question.md.replace(/<!--(.*?)-->/g, '').trim(),
question.choices.map(choice => {
var icon = choice.name == q.solution
? (q.answer == q.solution ? '✅' : '👉')
: (q.answer == choice.name ? '❌' : '- ');
return icon + ' ' + choice.text;
}).join('\n'),
].join('\n\n'));
// return line of summary for this question
return [ q.questionId, ':', q.answer, '(solution: ' + q.solution + ') =>', q.points, 'pts' ].join(' ');
});

console.log('\n------------- SUMMARY -------------\n');
console.log(summary.join('\n'));
setConsolePrefix();
console.log('\n => quizz score:', res.score, '/', res.length, 'pts');
callback(null, res);
Expand Down

0 comments on commit 063b2e8

Please sign in to comment.