Commit 8ba1370b authored by Vladimír Štill's avatar Vladimír Štill
Browse files

evalweb: Improve error handling in compare

parent deee3a75
Pipeline #66942 passed with stage
in 55 seconds
......@@ -2,8 +2,9 @@ from flask import Blueprint, render_template, request
from flask_wtf import FlaskForm # type: ignore
from wtforms import RadioField # type: ignore
from lib.parsing.parser import ParsingError
from evalweb.web_checker import WebChecker, Language
from evalweb.web_checker import WebChecker, Language, CompositeException
from evalweb.examples import examples, convert_examples
from typing import Optional
bp = Blueprint('eval', __name__, url_prefix='/reg')
......@@ -64,15 +65,31 @@ def compare() -> str:
teacher_area = teacher_string
if student_string == "" or teacher_string == "":
return render_template('parsing_error.html',
error="Nebyl zadán vstupní formalismus.")
def ifempty(arg: str) -> Optional[str]:
if arg == "":
return "Nebyl zadán vstupní formalismus."
return None
return render_template('compare.html',
error_asgn=ifempty(teacher_string),
error_sol=ifempty(student_string),
student_form=student_form,
teacher_form=teacher_form,
student_area=student_area,
teacher_area=teacher_area)
checker = WebChecker(student_string=student_string, task=student_type)
try:
result = checker.compare(teacher_string=teacher_string,
teacher_type=teacher_type)
except ParsingError as ex:
return render_template('parsing_error.html', error=str(ex))
except CompositeException as ex:
return render_template('compare.html',
error_asgn=ex.exceptions[0],
error_sol=ex.exceptions[1],
student_form=student_form,
teacher_form=teacher_form,
student_area=student_area,
teacher_area=teacher_area)
extra_word_ce, missing_word_ce, inf = None, None, None
if not result and checker.eq is not None: # languages not equivalent
......
......@@ -14,8 +14,14 @@
<input type="submit" name="example_button" value="Vlož příklady ke zvoleným typům">
<label for="teacher_string">Zadání</label>
<div>
<div style="width:400px; float:right;">
<textarea style="width:400px;" name="teacher_string" id="teacher_string">{{ teacher_area }}</textarea></div>
<div style="width:400px; float:right;">
<textarea style="width:400px;" name="teacher_string" id="teacher_string">{{ teacher_area }}</textarea>
{% if error_asgn is defined and error_asgn %}
<div class="error">
{{error_asgn}}
</div>
{% endif %}
</div>
{{ teacher_form.hidden_tag() }}
<div style="float:left;">{{ teacher_form.make(style="list-style:none") }}</div>
</div>
......@@ -23,8 +29,14 @@
<label for="student_string">Řešení</label><br>
<div>
<div style="width:400px; float:right;">
<textarea style="width:400px;" name="student_string" id="student_string">{{ student_area }}</textarea></div>
{{ student_form.hidden_tag() }}
<textarea style="width:400px;" name="student_string" id="student_string">{{ student_area }}</textarea>
{% if error_sol is defined and error_sol %}
<div class="error">
{{error_sol}}
</div>
{% endif %}
</div>
{{ student_form.hidden_tag() }}
<div style="float:left;">{{ student_form.make(style="list-style:none") }}</div>
</div>
......
{% extends 'base.html' %}
{% block header %}
<h1>Výsledek</h1>
{% endblock %}
{% block content %}
<br>Vstupní formalismus nebyl správně zadán, nastala chyba při parsování.<br><br>
{{ error }}
{% endblock %}
......@@ -51,6 +51,12 @@ class Language: # contains information about formalism and its language
return f"{teacher}-{task}:{dfa}"
class CompositeException(Exception):
def __init__(self, *args: Optional[Exception]) -> None:
self.exceptions = args
super().__init__()
class WebChecker:
def __init__(self, student_string: str, task: str) -> None:
self.student_string = student_string
......@@ -67,8 +73,18 @@ class WebChecker:
# nearly equivalent to dfa_task in fja_checker (for IS ROPOTs)
def dfa_task(self, teacher_type: str, teacher_string: str,
task: str, student_string: str) -> bool:
teacher = Language(string=teacher_string, task=teacher_type)
student = Language(string=student_string, task=self.task)
error_teach = None
try:
teacher = Language(string=teacher_string, task=teacher_type)
except ParsingError as ex:
error_teach = ex
try:
student = Language(string=student_string, task=self.task)
except ParsingError as ex:
raise CompositeException(error_teach, ex)
if error_teach:
raise CompositeException(error_teach, None)
# only for task checking
student_solution = transform(student_string, task)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment