Added analysis UI
This commit is contained in:
@@ -3,7 +3,7 @@ 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 import Blueprint, render_template, request, jsonify
|
||||
from flask.helpers import abort, flash, redirect, url_for
|
||||
from flask_login import login_required
|
||||
|
||||
@@ -19,10 +19,33 @@ analysis = Blueprint(
|
||||
@check_dataset_exists
|
||||
@check_test_exists
|
||||
def _analysis():
|
||||
_tests = Test.query.all()
|
||||
try:
|
||||
_tests = Test.query.all()
|
||||
_datasets = Dataset.query.all()
|
||||
except Exception as exception:
|
||||
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
|
||||
return abort(500)
|
||||
tests = [ test for test in _tests if test.entries ]
|
||||
_datasets = Dataset.query.all()
|
||||
datasets = [ dataset for dataset in _datasets if dataset.entries ]
|
||||
if request.method == 'POST':
|
||||
selection = request.get_json()
|
||||
if selection['class'] == 'test':
|
||||
try:
|
||||
test = Test.query.filter_by(id=selection['id']).first()
|
||||
except Exception as exception:
|
||||
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
|
||||
return abort(500)
|
||||
if not test: return jsonify({'error': 'Invalid entry ID.'}), 404
|
||||
return url_for('analysis._test', id=selection['id']), 200
|
||||
if selection['class'] == 'dataset':
|
||||
try:
|
||||
dataset = Dataset.query.filter_by(id=selection['id']).first()
|
||||
except Exception as exception:
|
||||
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
|
||||
return abort(500)
|
||||
if not dataset: return jsonify({'error': 'Invalid entry ID.'}), 404
|
||||
return url_for('analysis._dataset', id=selection['id']), 200
|
||||
return jsonify({'error': 'Invalid entry ID.'}), 404
|
||||
return render_template('/analysis/index.html', tests=tests, datasets=datasets)
|
||||
|
||||
@analysis.route('/test/<string:id>')
|
||||
@@ -41,8 +64,7 @@ def _test(id:str=None):
|
||||
if not test:
|
||||
flash('Invalid exam.', 'error')
|
||||
return redirect(url_for('analysis._analysis'))
|
||||
return jsonify(analyse(test))
|
||||
return render_template('/analysis/analysis.html', analysis=None, text='Exam')
|
||||
return render_template('/analysis/analysis.html', analysis=analyse(test), subject=test.get_code(), type='exam', dataset=test.dataset, questions=parse_questions(test.dataset.get_data()))
|
||||
|
||||
@analysis.route('/dataset/<string:id>')
|
||||
@analysis.route('/dataset/')
|
||||
@@ -60,4 +82,4 @@ def _dataset(id:str=None):
|
||||
if not dataset:
|
||||
flash('Invalid dataset.', 'error')
|
||||
return redirect(url_for('analysis._analysis'))
|
||||
return jsonify(analyse(dataset))
|
||||
return render_template('/analysis/analysis.html', analysis=analyse(dataset), subject=dataset.get_name(), type='dataset', dataset=dataset, questions=parse_questions(dataset.get_data()))
|
Reference in New Issue
Block a user