Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
fja
eval
Commits
45064bc4
Commit
45064bc4
authored
Jul 08, 2020
by
Kateřina Sloupová
Browse files
add support for images in feedback
parent
a86fef06
Changes
2
Hide whitespace changes
Inline
Side-by-side
evalweb/templates/result_compare.html
View file @
45064bc4
...
...
@@ -13,18 +13,25 @@
{% else %} nesprávné řešení.
{% endif %}
</h2><br>
{{ task_solved }}
<br>
{% if ok %} Jazyky popisované oběma formalismy jsou ekvivalentní.
{% else %} {% if extra_word_ce or missing_word_ce %}
Jazyky popisované oběma formalismy nejsou ekvivalentní.
{% endif %}
{% if alphabets != "" %}{{ alphabets }}
<br><br>
{% endif %}
{% if task_solved == "" %}
Odpověď splňuje požadavky kladené na formalismus.
{% else %}
Odpověď
<b>
nesplňuje požadavky
</b>
kladené na formalismus. {{ task_solved }}
{% endif %}
<br>
{% if extra_word_ce or missing_word_ce or alphabets != "" %}
Jazyky popisované oběma formalismy
<b>
nejsou ekvivalentní
</b>
.
{% else %}
Jazyky popisované oběma formalismy jsou ekvivalentní.
{% endif %}
</div><br>
<div>
<div
style=
"float:left;"
><label
for=
"teacher_string"
><h3
style=
"text-align:center"
>
Jazyk zadání
</h3></label>
<div
style=
"width:400px;"
name=
"teacher_string"
id=
"teacher_string"
>
<b>
Charakteristika:
</b>
{{ teacher.
inf
}}
<br><br>
<b>
Charakteristika:
</b>
{{ teacher.
sizename
}}
<br><br>
<b>
Příklad slova z jazyka:
</b>
{{ teacher.example }}
<br><br>
<b>
Původní popis:
</b>
<br>
{{ teacher.task }}: {{ teacher.string }}
<br><br>
...
...
@@ -36,7 +43,7 @@
<div
style=
"float:right;"
><label
for=
"student_string"
><h3
style=
"text-align:center"
>
Jazyk mého řešení
</h3></label>
<div
style=
"width:400px;"
name=
"student_string"
id=
"student_string"
>
<b>
Charakteristika:
</b>
{{ student.
inf
}}
<br><br>
<b>
Charakteristika:
</b>
{{ student.
sizename
}}
<br><br>
<b>
Příklad slova z jazyka:
</b>
{{ student.example }}
<br><br>
<b>
Původní popis:
</b>
<br>
{{ student.task }}: {{ student.string }}
<br><br>
...
...
@@ -49,6 +56,8 @@
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><hr>
<p>
<h3>
Porovnání jazyků
</h3>
<img
style=
"float:left; margin:10px 30px;"
src=
"static/img/{{ img_src }}.png"
alt=
"{{ img_src }}"
><br>
{% if not ok and (extra_word_ce or missing_word_ce) %}
{% if extra_word_ce %}
Příklad slova, které je ve studentově řešení a není v zadaném jazyce: {{ extra_word_ce }}
...
...
@@ -72,7 +81,7 @@
{% endif %}
</p>
<br><br>
<br><br>
<br><br><br>
<h3>
Vygenerovaný řetězec pro odpovědník
</h3>
{{ is_task }}
{% endblock %}
\ No newline at end of file
evalweb/web_checker.py
View file @
45064bc4
import
lib.reg
as
reg
from
lib.parsing.parser
import
Parser
,
ParsingError
import
signal
from
lib.checker
import
transform
,
dfa_transform
,
nfa_transform
,
check_task
,
check_alphabets
,
check_empty
from
lib.checker
import
transform
,
dfa_transform
,
nfa_transform
,
check_task
,
check_alphabets
from
enum
import
Enum
import
enum
class
Size
(
Enum
):
Empty
=
enum
.
auto
()
Finite
=
enum
.
auto
()
Infinite
=
enum
.
auto
()
Universal
=
enum
.
auto
()
class
Language
():
def
__init__
(
self
,
string
:
str
,
task
:
str
):
...
...
@@ -9,8 +18,9 @@ class Language():
self
.
task
=
task
self
.
dfa
=
None
self
.
minimal
=
None
self
.
inf
=
"prázdný"
self
.
example
=
""
self
.
size
=
None
self
.
sizename
=
None
self
.
example
=
None
self
.
gen_lang_html
()
def
gen_lang_html
(
self
):
...
...
@@ -19,52 +29,77 @@ class Language():
self
.
minimal
=
parser
.
dfa_to_str
(
dfa
.
minimize
().
canonize
())
empty
=
dfa
.
is_empty
()
if
empty
.
inf
is
not
None
:
self
.
inf
=
"nekonečný"
if
empty
.
inf
else
"konečný"
if
empty
:
size
=
Size
.
Empty
else
:
self
.
example
=
empty
.
counterexample
self
.
dfa
=
parser
.
dfa_to_str
(
dfa
.
canonize
())
if
not
empty
.
inf
:
size
=
Size
.
Finite
else
:
size
=
Size
.
Infinite
if
dfa
.
is_universal
():
size
=
Size
.
Universal
name
=
{
"Empty"
:
"prázdný"
,
"Finite"
:
"konečný"
,
"Infinite"
:
"nekonečný"
,
"Universal"
:
"univerzální"
}
self
.
size
=
size
self
.
sizename
=
name
[
size
.
name
]
self
.
dfa
=
dfa
def
gen_is_task
(
self
,
task
:
str
)
->
str
:
teacher
=
"NFA"
if
self
.
task
==
"EFA"
else
self
.
task
return
f
"
{
teacher
}
-
{
task
}
-N:
{
self
.
dfa
}
"
parser
=
Parser
()
dfa
=
parser
.
dfa_to_str
(
self
.
dfa
.
canonize
())
return
f
"
{
teacher
}
-
{
task
}
-N:
{
dfa
}
"
class
WebChecker
()
:
class
WebChecker
:
def
__init__
(
self
,
student_string
:
str
,
task
:
str
):
self
.
student_string
=
student_string
self
.
task
=
task
self
.
task_solved
=
""
self
.
alphabets
=
""
self
.
eq
=
None
self
.
ok
=
False
self
.
teacher
=
None
self
.
student
=
None
self
.
is_task
=
None
self
.
img_src
=
"disjunction"
def
dfa_task
(
self
,
teacher_type
,
teacher_string
,
task
,
student_string
):
try
:
teacher
=
Language
(
string
=
teacher_string
,
task
=
teacher_type
)
student
=
Language
(
string
=
student_string
,
task
=
self
.
task
)
student_solution
=
transform
(
student_string
,
task
)
student_dfa
=
dfa_transform
(
student_string
,
task
)
teacher_dfa
=
dfa_transform
(
teacher_string
,
teacher_type
)
except
ParsingError
as
ex
:
except
ParsingError
as
ex
:
# Parsing error, don't continue
return
(
ex
.
args
)
if
teacher_dfa
.
is_empty
()
and
student_dfa
.
is_empty
():
self
.
ok
=
True
return
""
alphabets
=
check_alphabets
(
student_alpha
=
student_dfa
.
characters
,
teacher_alpha
=
teacher_dfa
.
characters
,
task
=
task
)
if
alphabets
!=
""
:
return
alphabets
self
.
teacher
=
teacher
self
.
student
=
student
self
.
is_task
=
teacher
.
gen_is_task
(
task
=
self
.
task
)
task_solved
=
""
if
isinstance
(
student_solution
,
reg
.
DFA
)
or
isinstance
(
student_solution
,
reg
.
NFA
):
task_solved
=
check_task
(
student_solution
,
task
)
# "Odpověď splňuje požadovaný formalismus."
self
.
task_solved
=
check_task
(
student_solution
,
task
)
self
.
eq
=
reg
.
DFA
.
is_equivalent
(
student_dfa
,
teacher_dfa
)
if
teacher
.
size
==
Size
.
Empty
and
student
.
size
==
Size
.
Empty
:
return
True
alphabets
=
check_alphabets
(
student_alpha
=
student
.
dfa
.
characters
,
teacher_alpha
=
teacher
.
dfa
.
characters
,
task
=
task
)
if
alphabets
!=
""
:
self
.
alphabets
=
alphabets
return
False
if
task_solved
==
""
and
self
.
eq
:
self
.
ok
=
True
self
.
eq
=
reg
.
DFA
.
is_equivalent
(
student
.
dfa
,
teacher
.
dfa
)
# self.img_src = self.picture(self.eq.inf is None)
if
self
.
task_solved
==
""
and
self
.
eq
.
inf
is
None
:
return
True
return
False
return
task_solved
def
compare
(
self
,
teacher_string
:
str
,
teacher_type
:
str
):
#signal.alarm(50) #
...
...
@@ -105,13 +140,34 @@ class WebChecker():
if
self
.
task
==
"GRA"
:
return
parser
.
reggrammar_to_str
(
nfa
.
nfa_to_reggrammar
().
eliminate_useless
())
if
self
.
task
==
"REG"
:
return
self
.
student_string
if
student_type
==
"REG"
else
\
"Tohle není pěkný typ převodu. Nechcete si místo regulárního výrazu vybrat něco jiného?"
#return parser.regex_to_str(automaton.nfa_to_regex())
except
ParsingError
as
ex
:
return
(
"Chyba při parsování."
)
except
Exception
as
ex
:
print
(
"Error inside of web checker:"
,
ex
.
args
)
\ No newline at end of file
print
(
"Error inside of web checker:"
,
ex
.
args
)
def
relation
(
self
,
eq
:
bool
)
->
str
:
# TODO test
if
not
eq
:
if
self
.
eq
.
left_counterexample
is
not
None
:
# extra word
if
self
.
eq
.
left_counterexample
is
not
None
:
# missing word
intersection
=
reg
.
DFA
.
intersection
(
self
.
student
.
dfa
,
self
.
teacher
.
dfa
)
if
intersection
.
is_empty
():
# disjunction
return
"disjunction"
else
:
return
"intersection"
else
:
# teacher is subset of student
picture
=
"t_in_s"
else
:
# student is subset of teacher
picture
=
"s_in_t"
else
:
picture
=
"eq"
if
self
.
teacher
.
size
==
Size
.
Empty
or
self
.
student
.
size
==
Size
.
Universal
:
picture
+=
"_empty"
elif
self
.
teacher
.
size
==
Size
.
Universal
or
self
.
student
.
size
==
Size
.
Universal
:
picture
+=
"_universal"
return
picture
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