diff --git a/ref-test/app/analysis/views.py b/ref-test/app/analysis/views.py index 6473581..c5234dd 100644 --- a/ref-test/app/analysis/views.py +++ b/ref-test/app/analysis/views.py @@ -1,6 +1,7 @@ from ..models import Dataset, Test from ..tools.data import analyse, check_dataset_exists, check_test_exists from ..tools.logs import write +from ..tools.data import parse_questions from flask import Blueprint, jsonify, render_template, request from flask.helpers import abort, flash, redirect, url_for diff --git a/ref-test/app/tools/data.py b/ref-test/app/tools/data.py index a1660ab..af41acc 100644 --- a/ref-test/app/tools/data.py +++ b/ref-test/app/tools/data.py @@ -145,4 +145,26 @@ def analyse(subject:Union[Dataset,Test]) -> dict: output['scores']['mean'] = mean(scores_raw) output['scores']['median'] = median(scores_raw) output['scores']['stdev'] = stdev(scores_raw, output['scores']['mean']) if len(scores_raw) > 1 else None + return output + +def parse_questions(dataset:list): + output = [] + for block in dataset: + if block['type'] == 'question': + question = { + 'q_no': block['q_no'], + 'tags': block['tags'], + 'correct': block['correct'] + } + question['options'] = [*enumerate(block['options'])] + output.append(question) + elif block['type'] == 'block': + for _question in block['questions']: + question = { + 'q_no': _question['q_no'], + 'tags': _question['tags'], + 'correct': _question['correct'] + } + question['options'] = [*enumerate(_question['options'])] + output.append(question) return output \ No newline at end of file