diff --git a/server/app/views.py b/server/app/views.py index 2e1bbe1..d7f6e87 100644 --- a/server/app/views.py +++ b/server/app/views.py @@ -4,6 +4,7 @@ from .tools.quiz import compile_results, evaluate_answers, render_questions from flask import Blueprint, jsonify, request +import numpy views = Blueprint( name='views', @@ -23,6 +24,43 @@ def _submit(): new_entry.add() return jsonify(results) -@views.route('/results/') -def _results(): - pass \ No newline at end of file +@views.route('/count/') +def _count(): + return jsonify(len(Entry.query.all())) + +@views.route('/playbooks/') +def _playbooks(): + playbooks = dict.fromkeys(load('playbooks.json'), 0) + for entry in Entry.query.all(): + for _playbook in entry.results['playbooks']: playbooks[_playbook] += 1 + return playbooks + +@views.route('/answers/') +def _answers(): + answers = {} + for entry in Entry.query.all(): + for index, answer in enumerate(entry.answers): + if index not in answers: answers[index] = { } + if type(answer) is list: + for option in answer: + if option not in answers[index]: answers[index][option] = 0 + answers[index][option] += 1 + else: + if answer not in answers[index]: answers[index][answer] = 0 + answers[index][answer] += 1 + return list(answers.values()) + +@views.route('/scores/') +def _scores(): + playbooks = { playbook: list() for playbook in load('playbooks.json') } + for playbook, scores in playbooks.items(): + for entry in Entry.query.all(): + score = entry.results['all_playbooks'][playbook] + percentage_score = 100 * score/entry.results['max_score'] + scores.append(percentage_score) + output = { playbook: dict() for playbook in playbooks } + for playbook, scores in playbooks.items(): + output[playbook]['mean'] = numpy.mean(scores) + output[playbook]['median'] = numpy.median(scores) + output[playbook]['standard_deviation'] = numpy.std(scores) + return output \ No newline at end of file