Changed answer option object semantics to indices

Evaluating answer should no longer require string matching
Answers evaluated based on matching index value integers
This commit is contained in:
Vivek Santayana 2021-12-08 12:49:32 +00:00
parent 0059ec5270
commit c2d7dc7fe2
2 changed files with 9 additions and 13 deletions

View File

@ -96,7 +96,7 @@ def generate_questions(dataset:dict):
'text': block['text'] 'text': block['text']
} }
if block['q_type'] == 'Multiple Choice': if block['q_type'] == 'Multiple Choice':
question['options'] = randomise_list(block['options']) question['options'] = randomise_list([*enumerate(block['options'])])
else: else:
question['options'] = block['options'].copy() question['options'] = block['options'].copy()
output.append(question) output.append(question)
@ -111,7 +111,7 @@ def generate_questions(dataset:dict):
'text': _question['text'] 'text': _question['text']
} }
if _question['q_type'] == 'Multiple Choice': if _question['q_type'] == 'Multiple Choice':
question['options'] = randomise_list(_question['options']) question['options'] = randomise_list([*enumerate(_question['options'])])
else: else:
question['options'] = _question['options'].copy() question['options'] = _question['options'].copy()
output.append(question) output.append(question)
@ -126,11 +126,8 @@ def evaluate_answers(dataset: dict, answers: dict):
max += 1 max += 1
q_no = block['q_no'] q_no = block['q_no']
if str(q_no) in answers: if str(q_no) in answers:
correct = block['correct'] submitted_answer = int(answers[str(q_no)])
correct_answer = block['options'][correct] if submitted_answer == block['correct']:
submitted_answer = answers[str(q_no)]
submitted_answer = submitted_answer.replace('', '‘').replace('', '’').replace('', '—')
if submitted_answer == correct_answer:
score += 1 score += 1
for tag in block['tags']: for tag in block['tags']:
if tag not in tags: if tag not in tags:
@ -155,9 +152,8 @@ def evaluate_answers(dataset: dict, answers: dict):
max += 1 max += 1
q_no = question['q_no'] q_no = question['q_no']
if str(q_no) in answers: if str(q_no) in answers:
correct = question['correct'] submitted_answer = int(answers[str(q_no)])
correct_answer = question['options'][correct] if submitted_answer == question['correct']:
if answers[str(q_no)] == correct_answer:
score += 1 score += 1
for tag in question['tags']: for tag in question['tags']:
if tag not in tags: if tag not in tags:

View File

@ -364,13 +364,13 @@ function render_question() {
for (let i = 0; i < options.length; i ++) { for (let i = 0; i < options.length; i ++) {
var add_checked = '' var add_checked = ''
if (q_no in answers) { if (q_no in answers) {
if (answers[q_no] == options[i]) { if (answers[q_no] == options[i][0]) {
add_checked = 'checked'; add_checked = 'checked';
} }
} }
options_output += `<div class="form-check"> options_output += `<div class="form-check">
<input type="radio" class="form-check-input quiz-option" id="q${current_question}-${i}" name="${q_no}" value="${options[i]}" ${add_checked}> <input type="radio" class="form-check-input quiz-option" id="q${current_question}-${i}" name="${q_no}" value="${options[i][0]}" ${add_checked}>
<label for="q${current_question}-${i}" class="form-check-label">${options[i]}</label> <label for="q${current_question}-${i}" class="form-check-label">${options[i][1]}</label>
</div>`; </div>`;
} }
$question_options.html(options_output); $question_options.html(options_output);