Example #1
0
def simuluj():
    form = MyForm1()
    name = session.get("newname")
    druh = session.get("newdruh")
    vstup = session.get("newvstup")
    input_symbols = session.get("newinput_symbols")
    cas = session.get("cas")
    counter = session.get("counter")

    counter +=1
    session["counter"] = counter
    if druh == "ntm":
        if counter == 0:
            df,list_of_table,stroj, list_of_tape, final = table.table(name,vstup,druh)
            session['new_final'] = final
        else:
            final = session.get('new_final')
            df,list_of_table,stroj, list_of_tape = table.ntm_table_final(name,vstup,final)     
    elif druh == "xtm":
        df,list_of_table,stroj, list_of_tape, length = table.table(name,vstup,druh)
    else:
        df,list_of_table,stroj, list_of_tape = table.table(name,vstup,druh)

    if counter < len(list_of_table)-1:
        dff = list_of_table[counter]
        dff = dff.set_table_attributes('border="1" class="dataframe table table-hover table-bordered"')
        dff = dff.set_precision(3)
        df_tape = list_of_tape[counter]

        if druh == "xtm":
            dfz = []
            for i in range (length):
                dfz.append(list_of_tape[counter*length+i])
            if length == 2:
                return render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html() ,data = dff)
            elif length == 3:
                return render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html(), dataframe2= dfz[2].to_html(),data = dff)
            elif length == 4:
                return render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html(), dataframe2= dfz[2].to_html(), dataframe3= dfz[3].to_html(),data = dff)
            elif length == 5:
                z[5] = render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html(), dataframe2= dfz[2].to_html(), dataframe3= dfz[3].to_html(),dataframe4 = dfz[4].to_html(),data = dff)
            elif length == 6:
                z[6] = render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html(), dataframe2= dfz[2].to_html(), dataframe3= dfz[3].to_html(),dataframe4 = dfz[4].to_html(), dataframe5 = dfz[5].to_html(),data = dff)
            elif length == 7:
                z[7] = render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = dfz[0].to_html(),dataframe1 = dfz[1].to_html(), dataframe2= dfz[2].to_html(), dataframe3= dfz[3].to_html(),dataframe4 = dfz[4].to_html(), dataframe5 = dfz[5].to_html(), dataframe6 = dfz[6].to_html(),data = dff)
        else:
            return render_template("simuluj.html",content = cas,form=form,data1 = input_symbols,dataframe = df_tape.to_html(classes=["table-bordered", "table-striped", "table-hover"]), data = dff)
    else:
        return redirect(url_for('main.simulacia',vstup=vstup,druh = druh,name = name ))
Example #2
0
def simulacia(vstup, druh, name):
    form = TmachineForm()
    form.opts.query = Tmachine.query.filter(Tmachine.id >= 1)
    name = session.get("newname")
    druh = session.get("newdruh")
    vstup = session.get("newvstup")
    input_symbols = session.get("newinput_symbols")

    if druh == "ntm":
        if counter.value == 0:
            df, list_of_table, stroj, list_of_tape, final = table.table(
                name, vstup, druh)
            session['new_final'] = final
        else:
            final = session.get('new_final')
            df, list_of_table, stroj, list_of_tape = table.ntm_table_final(
                name, vstup, final)

    elif druh == "xtm":
        df, list_of_table, stroj, list_of_tape, length = table.table(
            name, vstup, druh)
    else:
        df, list_of_table, stroj, list_of_tape = table.table(name, vstup, druh)

    if request.method == 'POST':
        if form.validate_on_submit() and form.submit.data:
            name = "tm" + str(form.opts.data.id)
            druh = form.opts.data.tm_d_n_x
            return redirect(url_for('vstup', name=name, druh=druh))
        elif request.form.get('Krok vpred') == 'Krok vpred':
            if counter.value < len(list_of_table) - 1:
                with counter.get_lock():
                    counter.value += 1
        elif request.form.get('Krok späť') == 'Krok späť':
            if counter.value > 0:
                with counter.get_lock():
                    counter.value -= 1
        elif request.form.get('Vstup') == 'Zapíš na pásku':
            vstup = request.form.get('vstup')
            name = session.get("newname")
            druh = session.get("newdruh")
            vs = True
            df, input_symbols, input_symbols_dict = table_df.table(name, druh)
            for i in vstup:
                if i not in input_symbols_dict:
                    vs = False
            if vs and vstup != "":
                session["newvstup"] = vstup
                with counter.get_lock():
                    counter.value = 0
                return redirect(
                    url_for('simulacia', vstup=vstup, druh=druh, name=name))
            else:
                success_message = ("vstup: (") + vstup + (
                    ") nie je zo vstupnej abecedy: ") + input_symbols
                if vstup == "":
                    success_message = (
                        "vstup je prázdny, zadajte vstupné slovo zo vstupnej abecedy: "
                    ) + input_symbols
                flash(success_message)
                return redirect(url_for('vstup', name=name, druh=druh))
        elif request.form.get('Simulácia') == 'Simulácia':
            with counter.get_lock():
                counter.value -= 1
            try:
                cas = int(request.form.get('cas'))
                session["cas"] = cas
            except ValueError:
                cas = None
                success_message = ('Časové oneskorenie musí byť celé číslo')
                flash(success_message)
            if cas:
                return redirect(url_for('simuluj'))
            else:
                return redirect(
                    url_for('simulacia', vstup=vstup, druh=druh, name=name))

    if counter.value == len(list_of_table) - 1:
        if stroj:
            success_message = ('Turingov stroj akceptuje vstup: ' + vstup)
        else:
            success_message = ('Turingov stroj zamieta vstup: ' + vstup)
        flash(success_message)

    dff = list_of_table[counter.value]
    dff = dff.set_table_attributes(
        'border="1" class="dataframe table table-hover table-bordered"')
    dff = dff.set_precision(3)
    df_tape = list_of_tape[counter.value]

    if druh == "xtm":
        dfz = []
        for i in range(length):
            dfz.append(list_of_tape[counter.value * length + i])
        if length == 2:
            return render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   data=dff)
        elif length == 3:
            return render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   dataframe2=dfz[2].to_html(),
                                   data=dff)
        elif length == 4:
            return render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   dataframe2=dfz[2].to_html(),
                                   dataframe3=dfz[3].to_html(),
                                   data=dff)
        elif length == 5:
            z[5] = render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   dataframe2=dfz[2].to_html(),
                                   dataframe3=dfz[3].to_html(),
                                   dataframe4=dfz[4].to_html(),
                                   data=dff)
        elif length == 6:
            z[6] = render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   dataframe2=dfz[2].to_html(),
                                   dataframe3=dfz[3].to_html(),
                                   dataframe4=dfz[4].to_html(),
                                   dataframe5=dfz[5].to_html(),
                                   data=dff)
        elif length == 7:
            z[7] = render_template("simulacia.html",
                                   form=form,
                                   data1=input_symbols,
                                   dataframe=dfz[0].to_html(),
                                   dataframe1=dfz[1].to_html(),
                                   dataframe2=dfz[2].to_html(),
                                   dataframe3=dfz[3].to_html(),
                                   dataframe4=dfz[4].to_html(),
                                   dataframe5=dfz[5].to_html(),
                                   dataframe6=dfz[6].to_html(),
                                   data=dff)
    else:
        return render_template(
            "simulacia.html",
            form=form,
            data1=input_symbols,
            dataframe=df_tape.to_html(
                classes=["table-bordered", "table-striped", "table-hover"]),
            data=dff)
Example #3
0
def first():
    if request.method == 'GET': 
        first_col = table.table()
        return jsonify({'first':first_col})