Beispiel #1
0
def index():
    form = InputForm()
    if form.validate_on_submit():
        flash('Requested for handles {} {}'.format(form.fst_handle.data,
                                                   form.snd_handle.data))
        return redirect(url_for('index'))
    return render_template('index.html', title='Home', form=form)
Beispiel #2
0
def input():
    form = InputForm()
    if form.validate_on_submit():
        #flash('Wage requested: {}, City 1: {}, City 2: {}'.format(
            #form.wage.data, form.city1.data, form.city2.data))
        return redirect(url_for('result'))
    return render_template(input.html, form = form)
Beispiel #3
0
def inputMahasiswa():
    form = InputForm()
    if form.validate_on_submit():
        mahasiswa = Mahasiswa(nama=form.nama.data,
                              nim=form.nim.data,
                              senin_a=form.senin_a.data + ('11'),
                              senin_b=form.senin_b.data + ('12'),
                              senin_d=form.senin_d.data + ('13'),
                              senin_e=form.senin_e.data + ('14'),
                              selasa_a=form.selasa_a.data + ('21'),
                              selasa_b=form.selasa_b.data + ('22'),
                              selasa_d=form.selasa_d.data + ('23'),
                              selasa_e=form.selasa_e.data + ('24'),
                              rabu_a=form.rabu_a.data + ('31'),
                              rabu_b=form.rabu_b.data + ('32'),
                              rabu_d=form.rabu_d.data + ('33'),
                              rabu_e=form.rabu_e.data + ('34'),
                              kamis_a=form.kamis_a.data + ('41'),
                              kamis_b=form.kamis_b.data + ('42'),
                              kamis_d=form.kamis_d.data + ('43'),
                              kamis_e=form.kamis_e.data + ('44'),
                              jumat_a=form.jumat_a.data + ('51'),
                              jumat_b=form.jumat_b.data + ('52'),
                              jumat_d=form.jumat_d.data + ('53'),
                              jumat_f=form.jumat_f.data + ('54'))
        db.session.add(mahasiswa)
        db.session.commit()
        flash('Congratulations, data sudah masuk!')
        return redirect(url_for('inputMahasiswa'))
    return render_template('inputMahasiswa.html',
                           title='Input Jadwal Mahasiswa',
                           form=form)
Beispiel #4
0
def input():
    form = InputForm()
    return(render_template('input.html', title='Cop?', form=form))
    if form.validate_on_submit():
        data = form['userinput']
        return(redirect(url_for('input')))
    return(render_template('input.html', title='What u tryna cop?', form=form))
Beispiel #5
0
def form_page():
    form = InputForm()
    input_word = form.data['input_word']
    if form.validate_on_submit():
        result = closest_match(input_word)
        flash(result, 'info')
    return render_template('form.html', title='Did you mean?', form=form)
Beispiel #6
0
def ajax():
    form = InputForm()
    if form.validate_on_submit():
        x = form.x.data
        y = form.y.data
        result = str(np.lcm(x, y))  # calculate & parse to string for jsonify

        return jsonify(result=result)
    return jsonify(result=form.errors)
Beispiel #7
0
def Wiki():
    form = InputForm()
    if form.validate_on_submit():
        entry = Entry(entry_text=form.entry.data,
                      entry_title=form.entry_title.data,
                      author=User.query.get(current_user.id))
        db.session.add(entry)
        db.session.commit()
    return render_template('wiki.html', form=form)
def index():
    form = InputForm()
    if form.validate_on_submit():
        attacker, defender = units_from_form(form)
        options = options_from_form(form)
        outcomes = calc.calculate(attacker, defender, options, test=False)
        defaults = form

        checkboxes = defaultdict(lambda: "")
        for opt in options.keys():
            checkboxes[opt] = "checked" if options[opt] else ""

        hidden = defaultdict(lambda: False)
        for opt in options.keys():
            if "hide" in opt:
                if "att_" in opt and not options["att_faction"].lower().split(
                        "-")[0] in opt:
                    hidden[opt] = True
                if "def_" in opt and not options["def_faction"].lower().split(
                        "-")[0] in opt:
                    hidden[opt] = True

        boxes = html_generator.make_boxes(checkboxes, hidden)

        return render_template('index.html',
                               outcomes=outcomes,
                               form=form,
                               defaults=defaults,
                               checkboxes=checkboxes,
                               boxes=boxes)
    else:
        print("in else")
        flash_errors(form)

    outcomes = [0, 0, 0]
    defaults = defaultdict(lambda: {"data": "0"})

    checkboxes = defaultdict(lambda: "")
    checkboxes["att_riskdirecthit"] = "checked"
    checkboxes["def_riskdirecthit"] = "checked"

    hidden = defaultdict(lambda: False)
    for opt in options_list():
        if "hide" in opt:
            hidden[opt] = True

    boxes = html_generator.make_boxes(checkboxes, hidden)

    return render_template('index.html',
                           outcomes=outcomes,
                           form=form,
                           defaults=defaults,
                           checkboxes=checkboxes,
                           boxes=boxes)
Beispiel #9
0
def grecha():
    form = InputForm()
    global za_grechu
    cena = get_grechka()
    if form.validate_on_submit():
        summa_grechku = ((form.var2.data * form.var1.data) * form.var3.data)
        kilkist_pachok = summa_grechku / 400
        cena_za_vse = kilkist_pachok * cena
        za_grechu = cena_za_vse
        flash(' ціна : {}, кількість пачок на місяць: {} '.format(
            cena_za_vse, kilkist_pachok))
    return render_template('home.html', form=form, cena=cena, title='Grecha')
Beispiel #10
0
def index():
    # flash('input')
    form = InputForm()
    if form.validate_on_submit():
        # do xx xhere to sql
        data = db.insertion(form, mydb)
        flash('SUCCESS! We recorded following infomation:')
        for i in (data):
            if i != '':
                flash(i)

    return render_template('input.html', title='3 In', form=form)
Beispiel #11
0
def index():
    form = InputForm()
    err = False
    if form.validate_on_submit():
        result = algo.search(form.folder.data, form.keyword.data,
                             form.algo.data, TEST_FOLDER)
        return render_template('index.html',
                               title='String Matcher - 13518030',
                               form=form,
                               result=result,
                               keyword=form.keyword.data)
    return render_template('index.html',
                           title='String Matcher - 13518030',
                           form=form)
Beispiel #12
0
def calculate():
    form = InputForm()

    if form.validate_on_submit(
    ):  # need to insert the CSRF field in the HTML form
        flash("you have succesfully calculated")
        a = form.input_a_number.data
        b = a + 1
        return render_template(
            'calculate.html', form=form, output=b
        )  # these specified variables are the only variables go into the html file
    else:
        flash(f"the input number is {form.input_a_number.data}")
        return render_template('calculate.html', form=form)
Beispiel #13
0
def index():
    form = InputForm()
    if form.validate_on_submit():
        user_search = Search(user_id=current_user.id,
                             keyword=form.keyword.data, limit=form.limit.data)
        db.session.add(user_search)
        db.session.commit()
        keyword = form.keyword.data
        limit = form.limit.data
        flash("Search complete!")
        return redirect(url_for('results', name=keyword, limit=limit))
    page = request.args.get('page', 1, type=int)
    searches = current_user.followed_searches().paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=searches.next_num) \
        if searches.has_next else None
    prev_url = url_for('index', page=searches.prev_num) \
        if searches.has_prev else None
    return render_template('index.html', title='Home', form=form,
                           searches=searches.items, next_url=next_url,
                           prev_url=prev_url)
Beispiel #14
0
def irisapp():
    form = InputForm()
    if form.validate_on_submit():
        data = {"Inputs": {"input1":[{'Sepal-Length': form.sepallength.data,
                                      'Sepal-Width': form.sepalwidth.data,
                                      'Petal-Length': form.petallength.data,
                                      'Petal-width': form.petalwidth.data,
                                      'Class': "Iris-setosa",
                                      'Class-Type': "1",}]},"GlobalParameters":  {}}

        body = str.encode(json.dumps(data))
        headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
        req = urllib.request.Request(url, body, headers)

        try:
            response = urllib.request.urlopen(req)
            result = response.read()
        except urllib.error.HTTPError as error:
            print("The request failed with status code: " + str(error.code))

            # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
            print(error.info())
            print(json.loads(error.read().decode("utf8", 'ignore')))

        text = result.decode("utf-8").split(',')

        probs = {"Iris-Setosa":float(text[6].split('"')[5]),
                 "Iris-Versicolor":float(text[7].split('"')[5]),\
                 "Iris-Virginica":float(text[8].split('"')[5])}

        print(probs)
        print("Predicted Iris type:",max(probs.items(), key=operator.itemgetter(1))[0])

        flash("Predicted Iris type: {}".format(max(probs.items(), key=operator.itemgetter(1))[0]), 'prediction')

        for flowertype in probs:
            flash("{} probability: {}".format(flowertype,probs[flowertype]), 'probability')

        return redirect(url_for('irisapp'))
    return render_template('iris-app.html', title='Sign In', form=form)
Beispiel #15
0
def index():
    form = InputForm()
    if form.validate_on_submit():
        filename = mktemp()
        form.images.data.save(filename)
        unzip_path = os.path.join(app.root_path, f'../tmp/images/')
        converted_path = os.path.join(app.root_path, f'../tmp/converted/')
        unzip(filename, unzip_path)

        if os.path.isdir(converted_path):
            rmtree(converted_path)
        os.mkdir(converted_path)
        res = ai(os.listdir(unzip_path), unzip_path, converted_path)
        with open(os.path.join(converted_path, 'data.json'), 'w') as f:
            f.write(json.dumps(res))
        # filename2 = mktemp()
        # form.audios.data.save(filename2)
        # unzip(filename2, os.path.join(app.root_path, f'../tmp/audios/'))
        return redirect('/game')
    else:
        return render_template('load_page.html',
                               title="Hurt your friend",
                               form=form,
                               image='happy')
Beispiel #16
0
def containrize():
    form = InputForm()
    if form.add.data:
        form.pkg_asked.append_entry()
        return render_template('containrize.html',
                               title='Containrize',
                               form=form,
                               show_adv=True)
    # elif form.pkg_asked:
    #     for item in form.pkg_asked:
    #         if item.form.delete.data:
    #             form.pkg_asked.entries.remove(item)
    #             break
    print(form.validate_on_submit())

    if form.validate_on_submit():

        # TODO: support for DOI or other libraries
        # if form.doi.data:
        #     task = build_image.apply_async(kwargs={'current_user_id': current_user.id,
        #                                            'doi': form.doi.data,
        #                                            'name': form.name.data,
        #                                            'preprocess': form.fix_code.data,
        #                                            'dataverse_key': os.environ.get('DATAVERSE_KEY')})
        # else:
        # create directories if they don't exists yet
        if not os.path.exists(app.instance_path):
            os.makedirs(app.instance_path)
        if not os.path.exists(os.path.join(app.instance_path, 'r_datasets')):
            os.makedirs(os.path.join(app.instance_path, 'r_datasets'))
        if not os.path.exists(os.path.join(app.instance_path, 'py_datasets')):
            os.makedirs(os.path.join(app.instance_path, 'py_datasets'))
        if not os.path.exists(os.path.join(app.instance_path, 'temp')):
            os.makedirs(os.path.join(app.instance_path, 'temp'))
        else:
            shutil.rmtree(os.path.join(app.instance_path, 'temp'))
            os.makedirs(os.path.join(app.instance_path, 'temp'))

        print("MARK1")
        print(form.zip_file)
        if form.zip_file.data:
            zip_file = form.zip_file.data
            filename = secure_filename(zip_file.filename)
            if form.language.data == "Python":
                zipfile_path = os.path.join(app.instance_path, 'py_datasets',
                                            filename)
            else:
                zipfile_path = os.path.join(app.instance_path, 'r_datasets',
                                            filename)
            zip_file.save(zipfile_path)

            multi = 0
            bool_dir = False

            with zipfile.ZipFile(zipfile_path) as myzip:
                namelist = myzip.infolist()
                for i in namelist:
                    arr = i.filename.split('/')
                    arr = list(filter(lambda x: x != '', arr))
                    if (len(arr) == 1):
                        multi = multi + 1
                        if (i.is_dir()):
                            bool_dir = True

                # zipList = list(zipfile.Path(myzip).iterdir())
                if (multi != 1 or not (bool_dir)):
                    f_name = filename[:(filename.index('.'))]
                    os.makedirs(
                        os.path.join(app.instance_path, 'py_datasets', f_name))
                    myzip.extractall(
                        os.path.join(app.instance_path, 'py_datasets', f_name))
                    os.remove(zipfile_path)
                    z = zipfile.ZipFile(
                        os.path.join(app.instance_path, 'py_datasets',
                                     filename), 'w')
                    p = os.path.join(app.instance_path, 'py_datasets', f_name)
                    for root, dirs, files in os.walk(p):
                        for file in files:
                            z.write(
                                os.path.join(root, file),
                                os.path.relpath(os.path.join(root, file),
                                                os.path.join(p, '..')))
                    z.close()
                    shutil.rmtree(os.path.join(app.instance_path,
                                               'py_datasets', f_name),
                                  ignore_errors=True)
        else:
            filename = secure_filename(form.name.data + '.zip')
            if form.language.data == "Python":
                zipfile_path = os.path.join(app.instance_path, 'py_datasets',
                                            form.name.data + ".zip")
            else:
                zipfile_path = os.path.join(app.instance_path, 'r_datasets',
                                            form.name.data + ".zip")
            zip_file = zipfile.ZipFile(zipfile_path, "w")
            file_list = request.files.getlist('set_file')
            os.makedirs(os.path.join(app.instance_path, 'temp',
                                     form.name.data))
            for f in file_list:
                f.save(
                    os.path.join(app.instance_path, 'temp', form.name.data,
                                 f.filename))
            pth = os.path.join(app.instance_path, 'temp', form.name.data)
            for root, dirs, files in os.walk(pth):
                for file in files:
                    zip_file.write(
                        os.path.join(pth, file),
                        os.path.relpath(os.path.join(root, file),
                                        os.path.join(pth, '..')))
            zip_file.close()
        print("MARK2")
        json_input = {
            'user_id': current_user.id,
            'zipfile_path': zipfile_path,
            'name': form.name.data,
            "language": form.language.data,
            'need_prepro': form.fix_code.data,
            'extended_lib': form.extended_lib.data,
            'adv_opt': None
        }
        json_ad_input = {
            'cmd': form.command_line.data,
            'sample_output': form.sample_output.data,
            'code_btw': form.code_btw.data,
            'prov': form.provenance.data
        }
        for value in json_ad_input.values():
            if value is not None:
                json_input["adv_opt"] = json_ad_input
                break
        # covert the user package into json format
        user_pkgs_list = []
        if form.pkg_asked.data:
            for entry in form.pkg_asked.data:
                print(entry)
                temp = {
                    "pkg_name": entry['package_name'],
                    "PypI_name": entry['pypI_name']
                }
                user_pkgs_list.append(temp)
        user_pkgs_total = str({"pkg": user_pkgs_list}).replace('\'', '\"')
        print(str(user_pkgs_total))
        # TODO: The backend function will be called here
        print("lang" + form.language.data)
        if form.language.data == "R":
            task = build_image.apply_async(
                kwargs={
                    'zip_file': filename,
                    'current_user_id': current_user.id,
                    'name': form.name.data,
                    'preprocess': form.fix_code.data
                })
        else:
            task = start_raas.apply_async(
                kwargs={
                    'language': form.language.data,
                    'zip_file': filename,
                    'current_user_id': current_user.id,
                    'name': form.name.data,
                    'preprocess': form.fix_code.data,
                    'user_pkgs': user_pkgs_total,
                    'run_instr': form.command_line.data
                })

        session['task_id'] = task.id
        return redirect(url_for('build_status'))
    print("MARK3")
    return render_template('containrize.html',
                           title='Containrize',
                           form=form,
                           show_adv=False)
Beispiel #17
0
def newjob():
    form_input = InputForm()
    if form_input.validate_on_submit():
        #print("===2===")
        # Wird nach dem Submit unten bei ===1=== nochmal aufgerufen!
        # Pruefe, ob form_input.date_start.data und form_input.time_start.data
        # in der Tinydb bereits vorkommen!
        dtstr = form_input.date_start.data + "T" + form_input.time_start.data + ":00"
        msg = json.dumps({"cmd": "date-exists", "date": dtstr})
        logger.info("queue_c_to_s.put: {}".format(msg))
        if conf.IPC_FLAG: queue_c_to_s.put(msg)
        exists = queue_s_to_c.get()  # True or False
        logger.info("queue_s_to_c.get: {}".format(exists))
        if not exists:
            crts = ""
            if form_input.platz_1.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_2.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_3.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_4.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_5.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_6.data:
                crts = crts + "*"
            else:
                crts = crts + "."
            if form_input.platz_7.data:
                crts = crts + "*"
            else:
                crts = crts + "."

            js = json.dumps({
                "status": "active",
                "start": dtstr,
                "duration": int(form_input.time_dauer.data),
                "courts": crts,
                "cycle": form_input.zyklus_zeit.data
            })

            msg = '{"cmd": "store-job", "job": ' + js + '}'
            logger.info('routes.py newjob/: {}'.format(msg))

            if conf.IPC_FLAG:
                queue_c_to_s.put(msg)
                resp = queue_s_to_c.get()  # ok

        else:
            flash("Der Auftrag existiert bereits")
        return redirect(url_for('jobs'))

    #print("===1===")
    return render_template('newjob.html',
                           title='Neuer Job',
                           form_input=form_input)
Beispiel #18
0
def input():
    form = InputForm()
    if form.validate_on_submit():
        return redirect(url_for('process', text=form.text.data))
    return render_template('input.html', title='Input', form=form)
Beispiel #19
0
def index():
    form = InputForm()
    if form.validate_on_submit():
        # Get inputs from form
        attacker, defender = units_from_form(form)
        options = options_from_form(form)

        try:
            outcomes = calc.calculate(attacker, defender, options, test=False)
        except:
            error_print(attacker, defender, options)
            flash("Sorry, something went wrong in the calculation :(")
            outcomes = [0, 0, 0]
            traceback.print_exc()

        # Determine which checkboxes should remain checked
        checkboxes = defaultdict(lambda: "")
        for opt in options.keys():
            checkboxes[opt] = "checked" if options[opt] else ""

        # Determine which options should be hidden
        hidden = defaultdict(lambda: False)
        for opt in options.keys():
            if "hide" in opt:
                if "att_" in opt and not options["att_faction"].lower().split(
                        "-")[0] in opt:
                    hidden[opt] = True
                if "def_" in opt and not options["def_faction"].lower().split(
                        "-")[0] in opt:
                    hidden[opt] = True
        boxes = html_generator.make_boxes(checkboxes, hidden)

        # Remember numbers that were filled in
        defaults = form

        return render_template('index.html',
                               outcomes=outcomes,
                               form=form,
                               defaults=defaults,
                               checkboxes=checkboxes,
                               boxes=boxes)
    else:
        flash_errors(form)

    outcomes = [0, 0, 0]
    defaults = defaultdict(lambda: {"data": "0"})

    checkboxes = defaultdict(lambda: "")
    checkboxes["att_riskdirecthit"] = "checked"
    checkboxes["def_riskdirecthit"] = "checked"

    hidden = defaultdict(lambda: False)
    for opt in options_list():
        if "hide" in opt:
            hidden[opt] = True

    boxes = html_generator.make_boxes(checkboxes, hidden)

    return render_template('index.html',
                           outcomes=outcomes,
                           form=form,
                           defaults=defaults,
                           checkboxes=checkboxes,
                           boxes=boxes)