Added a whole lot of views.
Finished quiz API views Finished question generator and answer eval
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from ..data import data as data_dir
|
||||
|
||||
import json
|
||||
from random import shuffle
|
||||
|
||||
def load(filename:str):
|
||||
with open(f'./{data_dir}/{filename}') as file:
|
||||
@@ -7,4 +9,26 @@ def load(filename:str):
|
||||
|
||||
def save(data:dict, filename:str):
|
||||
with open(f'./{data_dir}/{filename}', 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
def check_is_json(file):
|
||||
if not '.' in file.filename or not file.filename.rsplit('.',1)[-1] == 'json': return False
|
||||
return True
|
||||
|
||||
def validate_json(file):
|
||||
file.stream.seek(0)
|
||||
data = json.loads(file.read())
|
||||
if not type(data) is list: return False
|
||||
|
||||
def randomise_list(list:list):
|
||||
_list = list.copy()
|
||||
shuffle(_list)
|
||||
return(_list)
|
||||
|
||||
def get_tag_list(dataset:list):
|
||||
output = []
|
||||
for block in dataset:
|
||||
if block['type'] == 'question': output = list(set(output) | set(block['tags']))
|
||||
if block['type'] == 'block':
|
||||
for question in block['questions']: output = list(set(output) | set(question['tags']))
|
||||
return output
|
Reference in New Issue
Block a user