Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
8ba1370b
Commit
8ba1370b
authored
Feb 15, 2021
by
Vladimír Štill
Browse files
evalweb: Improve error handling in compare
parent
deee3a75
Pipeline
#66942
passed with stage
in 55 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
evalweb/evalweb.py
View file @
8ba1370b
...
...
@@ -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
...
...
evalweb/templates/compare.html
View file @
8ba1370b
...
...
@@ -15,7 +15,13 @@
<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>
<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,7 +29,13 @@
<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>
<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>
...
...
evalweb/templates/parsing_error.html
deleted
100644 → 0
View file @
deee3a75
{% 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 %}
evalweb/web_checker.py
View file @
8ba1370b
...
...
@@ -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
:
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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment