From 8680c73e863de8c3a055747228080abfc8f0a540 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Wed, 8 Dec 2021 12:49:32 +0000 Subject: [PATCH] Changed answer option object semantics to indices Evaluating answer should no longer require string matching Answers evaluated based on matching index value integers --- ref-test/common/data_tools.py | 16 ++++++---------- ref-test/quiz/static/js/quiz.js | 6 +++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ref-test/common/data_tools.py b/ref-test/common/data_tools.py index d406e7b..8a3a9ef 100644 --- a/ref-test/common/data_tools.py +++ b/ref-test/common/data_tools.py @@ -96,7 +96,7 @@ def generate_questions(dataset:dict): 'text': block['text'] } if block['q_type'] == 'Multiple Choice': - question['options'] = randomise_list(block['options']) + question['options'] = randomise_list([*enumerate(block['options'])]) else: question['options'] = block['options'].copy() output.append(question) @@ -111,7 +111,7 @@ def generate_questions(dataset:dict): 'text': _question['text'] } if _question['q_type'] == 'Multiple Choice': - question['options'] = randomise_list(_question['options']) + question['options'] = randomise_list([*enumerate(_question['options'])]) else: question['options'] = _question['options'].copy() output.append(question) @@ -126,11 +126,8 @@ def evaluate_answers(dataset: dict, answers: dict): max += 1 q_no = block['q_no'] if str(q_no) in answers: - correct = block['correct'] - correct_answer = block['options'][correct] - submitted_answer = answers[str(q_no)] - submitted_answer = submitted_answer.replace('‘', '‘').replace('’', '’').replace('—', '—') - if submitted_answer == correct_answer: + submitted_answer = int(answers[str(q_no)]) + if submitted_answer == block['correct']: score += 1 for tag in block['tags']: if tag not in tags: @@ -155,9 +152,8 @@ def evaluate_answers(dataset: dict, answers: dict): max += 1 q_no = question['q_no'] if str(q_no) in answers: - correct = question['correct'] - correct_answer = question['options'][correct] - if answers[str(q_no)] == correct_answer: + submitted_answer = int(answers[str(q_no)]) + if submitted_answer == question['correct']: score += 1 for tag in question['tags']: if tag not in tags: diff --git a/ref-test/quiz/static/js/quiz.js b/ref-test/quiz/static/js/quiz.js index 7101631..42c4161 100644 --- a/ref-test/quiz/static/js/quiz.js +++ b/ref-test/quiz/static/js/quiz.js @@ -364,13 +364,13 @@ function render_question() { for (let i = 0; i < options.length; i ++) { var add_checked = '' if (q_no in answers) { - if (answers[q_no] == options[i]) { + if (answers[q_no] == options[i][0]) { add_checked = 'checked'; } } options_output += `
- - + +
`; } $question_options.html(options_output);