Made randomising of question order optional
This commit is contained in:
parent
a1289da09c
commit
179a608089
@ -10,9 +10,10 @@ from functools import wraps
|
||||
def parse_test_code(code):
|
||||
return code.replace('—', '').lower()
|
||||
|
||||
def generate_questions(dataset:list):
|
||||
def generate_questions(dataset:list, randomise:bool=True):
|
||||
output = []
|
||||
for block in randomise_list(dataset):
|
||||
question_dataset = randomise_list(dataset) if randomise else dataset
|
||||
for block in question_dataset:
|
||||
if block['type'] == 'question':
|
||||
question = {
|
||||
'type': 'question',
|
||||
@ -20,11 +21,12 @@ def generate_questions(dataset:list):
|
||||
'question_header': '',
|
||||
'text': block['text']
|
||||
}
|
||||
if block['q_type'] == 'Multiple Choice': question['options'] = randomise_list([*enumerate(block['options'])])
|
||||
if block['q_type'] == 'Multiple Choice' and randomise: question['options'] = randomise_list([*enumerate(block['options'])])
|
||||
else: question['options'] = [*enumerate(block['options'])]
|
||||
output.append(question)
|
||||
elif block['type'] == 'block':
|
||||
for key, _question in enumerate(randomise_list(block['questions'])):
|
||||
block_questions = randomise_list(block['questions']) if randomise else block['questions']
|
||||
for key, _question in enumerate(block_questions):
|
||||
question = {
|
||||
'type': 'block',
|
||||
'q_no': _question['q_no'],
|
||||
@ -33,7 +35,7 @@ def generate_questions(dataset:list):
|
||||
'block_q_no': key,
|
||||
'text': _question['text']
|
||||
}
|
||||
if _question['q_type'] == 'Multiple Choice': question['options'] = randomise_list([*enumerate(_question['options'])])
|
||||
if _question['q_type'] == 'Multiple Choice' and randomise: question['options'] = randomise_list([*enumerate(_question['options'])])
|
||||
else: question['options'] = [*enumerate(_question['options'])]
|
||||
output.append(question)
|
||||
return output
|
||||
|
Loading…
Reference in New Issue
Block a user