Commit 0f5aad35 authored by Kateřina Sloupová's avatar Kateřina Sloupová
Browse files

comments and cleanup

parent b8cdb4a5
Loading
Loading
Loading
Loading
Loading

evalweb.sh

0 → 100644
+3 −0
Original line number Original line Diff line number Diff line
export PYTHONPATH=$PWD
export FLASK_APP=evalweb
flask run
+1 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ def create_app(test_config=None):
        pass
        pass


    @app.route('/')
    @app.route('/')
    # initial page is compare mode
    def index():
    def index():
        return redirect(url_for('eval.compare'))
        return redirect(url_for('eval.compare'))


+11 −9
Original line number Original line Diff line number Diff line
from flask import Blueprint, render_template, request
from flask import Blueprint, render_template, request
from flask_wtf import FlaskForm
from flask_wtf import FlaskForm
from wtforms import RadioField
from wtforms import RadioField
import sys
sys.path.append('~/eval')
from evalweb.web_checker import WebChecker, Language
from evalweb.web_checker import WebChecker, Language
from evalweb.examples import examples, convert_examples
from evalweb.examples import examples, convert_examples




bp = Blueprint('eval', __name__, url_prefix='/')
bp = Blueprint('eval', __name__, url_prefix='/')


# radiobuttons: student task
tasks = {'DFA': 'DFA',
tasks = {'DFA': 'DFA',
         'TOT': 'Totální DFA',
         'TOT': 'Totální DFA',
         'MIN': 'Minimální DFA',
         'MIN': 'Minimální DFA',
@@ -17,6 +16,7 @@ tasks = {'DFA': 'DFA',
         'GRA': 'Regulární gramatika',
         'GRA': 'Regulární gramatika',
         'REG': 'Regulární výraz'}
         'REG': 'Regulární výraz'}


# radiobuttons: conversion possibilities
convs = {'DFA': 'DFA',
convs = {'DFA': 'DFA',
         'TOT': 'Totální DFA',
         'TOT': 'Totální DFA',
         'MIN': 'Minimální DFA',
         'MIN': 'Minimální DFA',
@@ -24,16 +24,17 @@ convs = {'DFA': 'DFA',
         'NFA': 'NFA bez ε-kroků',
         'NFA': 'NFA bez ε-kroků',
         'GRA': 'Regulární gramatika'}
         'GRA': 'Regulární gramatika'}


# radiobuttons: teacher input/formalism to convert
types = {'DFA': 'DFA',
types = {'DFA': 'DFA',
         'EFA': 'NFA (s ε-kroky)',
         'EFA': 'NFA (s ε-kroky)',
         'GRA': 'Regulární gramatika',
         'GRA': 'Regulární gramatika',
         'REG': 'Regulární výraz'}
         'REG': 'Regulární výraz'}




# forms from variants above
class TypeForm(FlaskForm):
class TypeForm(FlaskForm):
    make = RadioField('Typ', choices=list(types.items()), default='DFA', coerce=str)
    make = RadioField('Typ', choices=list(types.items()), default='DFA', coerce=str)



class TaskForm(FlaskForm):
class TaskForm(FlaskForm):
    make = RadioField('Task', choices=list(tasks.items()), default='DFA', coerce=str)
    make = RadioField('Task', choices=list(tasks.items()), default='DFA', coerce=str)


@@ -45,10 +46,10 @@ class ConvertForm(FlaskForm):
def compare():
def compare():
    student_form = TaskForm(prefix='student_form')
    student_form = TaskForm(prefix='student_form')
    teacher_form = TypeForm(prefix='teacher_form')
    teacher_form = TypeForm(prefix='teacher_form')
    student_area = ""
    student_area = ""  # areas remembers user input or replace it with examples
    teacher_area = ""
    teacher_area = ""


    if request.method == 'POST' and 'submit_button' in request.form:
    if request.method == 'POST' and 'submit_button' in request.form:  # submit action
        teacher_type = teacher_form.make.data
        teacher_type = teacher_form.make.data
        teacher_string = request.form['teacher_string']
        teacher_string = request.form['teacher_string']
        student_type = student_form.make.data
        student_type = student_form.make.data
@@ -62,19 +63,19 @@ def compare():
            return render_template('parsing_error.html', error=result)
            return render_template('parsing_error.html', error=result)


        extra_word_ce, missing_word_ce, inf = None, None, None
        extra_word_ce, missing_word_ce, inf = None, None, None
        if not result and checker.eq is not None:
        if not result and checker.eq is not None:  # languages aren't equivalent
            extra_word_ce = checker.eq.left_counterexample
            extra_word_ce = checker.eq.left_counterexample
            missing_word_ce = checker.eq.right_counterexample
            missing_word_ce = checker.eq.right_counterexample
            inf = checker.eq.inf
            inf = checker.eq.inf


        return render_template('result_compare.html', compare=True, ok=result,
        return render_template('result_compare.html', compare=True, ok=result, inf=inf,
                               inf=inf, task_solved=checker.task_solved, alphabets=checker.alphabets,
                               task_solved=checker.task_solved, alphabets=checker.alphabets,
                               extra_word_ce=extra_word_ce, missing_word_ce=missing_word_ce,
                               extra_word_ce=extra_word_ce, missing_word_ce=missing_word_ce,
                               is_task=checker.is_task, img_src=checker.img_src,
                               is_task=checker.is_task, img_src=checker.img_src,
                               teacher=checker.teacher, student=checker.student)
                               teacher=checker.teacher, student=checker.student)


    if request.method == 'POST' and 'example_button' in request.form:
    if request.method == 'POST' and 'example_button' in request.form:
        teacher_type = teacher_form.make.data
        teacher_type = teacher_form.make.data  # of which types examples should be
        student_type = student_form.make.data
        student_type = student_form.make.data
        if (teacher_type, student_type) in examples:
        if (teacher_type, student_type) in examples:
            teacher_area, student_area = examples[(teacher_type, student_type)]
            teacher_area, student_area = examples[(teacher_type, student_type)]
@@ -83,6 +84,7 @@ def compare():
                           student_area=student_area, teacher_area=teacher_area)
                           student_area=student_area, teacher_area=teacher_area)




# analogical to compare, only with just one input formalism
@bp.route('/convert', methods=('GET', 'POST'))
@bp.route('/convert', methods=('GET', 'POST'))
def convert():
def convert():
    student_form = TypeForm(prefix='student_form')
    student_form = TypeForm(prefix='student_form')
+10.7 KiB
Loading image diff...
+0 −1
Original line number Original line Diff line number Diff line
@@ -4,7 +4,6 @@
  <h1>{% block title %}Porovnání formalismů{% endblock %}</h1>
  <h1>{% block title %}Porovnání formalismů{% endblock %}</h1>
{% endblock %}
{% endblock %}



{% block content %}
{% block content %}


  <form method="post">
  <form method="post">
Loading