Added submission processing
This commit is contained in:
29
server/app/tools/quiz.py
Normal file
29
server/app/tools/quiz.py
Normal file
@ -0,0 +1,29 @@
|
||||
from .data import load
|
||||
|
||||
def evaluate_answers(answers:list) -> dict:
|
||||
playbooks = load('playbooks.json')
|
||||
questions = load('questions.json')
|
||||
scores = dict.fromkeys(playbooks,0)
|
||||
for index, answer in enumerate(answers):
|
||||
question = questions[index]
|
||||
if type(answer) is list:
|
||||
answer = answer[0:question['select']]
|
||||
for _answer in answer:
|
||||
for match in question['answers'][int(_answer)]['matches']: scores[match] += 1
|
||||
else:
|
||||
for match in question['answers'][int(answer)]['matches']: scores[match] += 1
|
||||
return scores
|
||||
|
||||
def compile_results(results:dict) -> dict:
|
||||
output = {
|
||||
'all_playbooks': results.copy(),
|
||||
'playbooks': [ ],
|
||||
'score': max(results.values()),
|
||||
'max_score': 0
|
||||
}
|
||||
for question in load('questions.json'):
|
||||
output['max_score'] += question.pop('max', 1)
|
||||
playbooks = load('playbooks.json')
|
||||
for playbook, score in results.items():
|
||||
if score == output['score']: output['playbooks'].append({playbook: playbooks[playbook].copy()})
|
||||
return output
|
Reference in New Issue
Block a user