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']
}
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:

View File

@ -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 += `<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}>
<label for="q${current_question}-${i}" class="form-check-label">${options[i]}</label>
<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][1]}</label>
</div>`;
}
$question_options.html(options_output);