Added question parser for analysis

This commit is contained in:
Vivek Santayana 2023-03-05 00:31:33 +00:00
parent 179a608089
commit a56358b8dd
2 changed files with 23 additions and 0 deletions

View File

@ -1,6 +1,7 @@
from ..models import Dataset, Test from ..models import Dataset, Test
from ..tools.data import analyse, check_dataset_exists, check_test_exists from ..tools.data import analyse, check_dataset_exists, check_test_exists
from ..tools.logs import write from ..tools.logs import write
from ..tools.data import parse_questions
from flask import Blueprint, jsonify, render_template, request from flask import Blueprint, jsonify, render_template, request
from flask.helpers import abort, flash, redirect, url_for from flask.helpers import abort, flash, redirect, url_for

View File

@ -146,3 +146,25 @@ def analyse(subject:Union[Dataset,Test]) -> dict:
output['scores']['median'] = median(scores_raw) output['scores']['median'] = median(scores_raw)
output['scores']['stdev'] = stdev(scores_raw, output['scores']['mean']) if len(scores_raw) > 1 else None output['scores']['stdev'] = stdev(scores_raw, output['scores']['mean']) if len(scores_raw) > 1 else None
return output 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