Added all API features
This commit is contained in:
parent
4b0f63f124
commit
c6b656cbee
@ -4,6 +4,7 @@ from .tools.quiz import compile_results, evaluate_answers, render_questions
|
|||||||
|
|
||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, jsonify, request
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
views = Blueprint(
|
views = Blueprint(
|
||||||
name='views',
|
name='views',
|
||||||
@ -23,6 +24,43 @@ def _submit():
|
|||||||
new_entry.add()
|
new_entry.add()
|
||||||
return jsonify(results)
|
return jsonify(results)
|
||||||
|
|
||||||
@views.route('/results/')
|
@views.route('/count/')
|
||||||
def _results():
|
def _count():
|
||||||
pass
|
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
|
Loading…
Reference in New Issue
Block a user