Beispiel #1
0
def index():

    if request.method == 'GET':
        return render_template('index.html', params=None)

    if request.method == 'POST':
        if request.form['action'] == 'make':
            form = InputForm(request.form)
            if form.validate():
                params = {
                    'minstr': form.data['minstr'],
                    'start_date': form.data['start_date'].strftime('%Y-%m-%d'),
                    'finish_date':
                    form.data['finish_date'].strftime('%Y-%m-%d')
                }
                unique_incidents = get_query_results('query_1.sql', params)
                chart_data = get_query_results('query_2.sql', params)
                incidents_by_persons = get_query_results('query_3.sql', params)
                incidents_by_roads = get_query_results('query_4.sql', params)

                labels = [x['Caption'] for x in chart_data]
                values = [x['ver'] for x in chart_data]
                return render_template(
                    'index.html',
                    unique_incidents=unique_incidents,
                    labels=labels,
                    values=values,
                    incidents_by_persons=incidents_by_persons,
                    incidents_by_roads=incidents_by_roads,
                    params=params)
            else:
                errors = form.errors
                return render_template('error.html', errors=errors)
Beispiel #2
0
def blast():
    form = InputForm()
    title = "Blast - "
    try:
        with open('content/blast_page.md', encoding='utf-8') as c:
            name = get_title(c)
            next(c)
            c = c.read()
    except Exception:
        abort(404)
    if request.method == 'POST':
        sequence = request.form.get('id_sequences')
        file = request.form.get('id_file_text')
        function = request.form.get('job')
        print(file)
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('blast.html',
                                   content=to_md(c),
                                   name=name,
                                   form=form,
                                   title=title,
                                   description="")
        elif sequence == "" and file == "":
            flash('You need to at least have one input.')
            return render_template('blast.html',
                                   content=to_md(c),
                                   name=name,
                                   form=form,
                                   title=title,
                                   description="")
        elif sequence != "" and file != "":
            flash('You can only have one input.')
            return render_template('blast.html',
                                   content=to_md(c),
                                   name=name,
                                   form=form,
                                   title=title,
                                   description="")
        else:
            if sequence != "" and file == "":
                query = sequence
            elif sequence == '' and file != '':
                query = file
            if function == 'blastp':
                records = blastp(query)
            elif function == 'blastx':
                records = blastx(query)
            return render_template('result_blastp.html',
                                   records=records,
                                   title=title,
                                   description="")

    elif request.method == 'GET':
        return render_template('blast.html',
                               content=to_md(c),
                               name=name,
                               form=form,
                               title=title,
                               description="")
Beispiel #3
0
def input():
    form = InputForm(request.form)
    if request.method == 'POST' and form.validate():
        output = test_function(form.input1.data, form.input2.data)
        return render_template("output.html", output=output, title='Output')
    else:
        flash('Please enter a valid value', 'danger')
        return render_template("input.html", form=form, title='Input')
Beispiel #4
0
def translate():
  form = InputForm(request.form)

  if form.validate():
    writer = WriteLike(request.values.get('style'))
    output_text = writer.style_convert_string(request.values.get('input_text'))

    return jsonify( {'output': output_text} )
  
  return jsonify( {'errors': form.errors})
Beispiel #5
0
def translate():
    form = InputForm(request.form)

    if form.validate():
        writer = WriteLike(request.values.get('style'))
        output_text = writer.style_convert_string(
            request.values.get('input_text'))

        return jsonify({'output': output_text})

    return jsonify({'errors': form.errors})
Beispiel #6
0
def load():
	form = InputForm()
	if request.method == 'POST':
		if form.validate() == False:
			flash ('Invalid entry.')
			return render_template("load.html", form = form)
		else: 
			newitem = Item(form.item.data)
			db.session.add(newitem)
			db.session.commit()
			flash ('Added' + " " + '"' + form.item.data + '"' + " to the swotpad.")
			return redirect('/load')	
	elif request.method == 'GET':
		return render_template("load.html", form = form)
Beispiel #7
0
def fetch():
    form = InputForm()
    if request.method == 'POST':
        if not form.validate():
            return render_template('test.html', form=form)
        else:
            register_no = form.register_no.data
            dob = datetime.datetime.strptime(str(form.dob.data), '%Y-%m-%d').strftime('%d-%m-%Y')
            # # return "Form posted {0} {1}".format(register_no, dob)
            # # fetch_details(register_no, dob)
            # s = Scrapper(register_no, dob)
            # json_data = s.get_json()
            # return render_template('test.html', form=form, data=json_data)

            return render_template('test.html', form=form, valid=True)
    elif request.method == 'GET':
        return render_template('test.html', form=form)
def index():

    form = InputForm()

    if request.method == 'POST':

        valid = True
        category_weight_dict = {}

        # parse custom_weight_dict
        if form.custom_weight_dict.data.strip() != "":
            try:
                custom_lists = form.custom_weight_dict.data.split(";")
                for ls in custom_lists:
                    list_name, values_string = ls.split(":")
                    values_list_string = values_string.split(",")
                    values_list = [
                        float(value.strip()) for value in values_list_string
                    ]
                    category_weight_dict[list_name.strip()] = values_list

            except:
                print("Error parsing custom weight dictionary")
                valid = False
        print("category_weight_dict:", category_weight_dict)
        if form.validate():

            # retrieve file names and upload data to the server
            origin_file = request.files['origin_file']
            origin_filename = secure_filename(origin_file.filename)
            origin_file.save(os.path.join(INPUTS_FOLDER, origin_filename))
            destination_file = request.files['destination_file']
            destination_filename = secure_filename(destination_file.filename)
            destination_file.save(
                os.path.join(INPUTS_FOLDER, destination_filename))

            # create a dictionary associating field names used in the health code to the
            # fields in the data specified by the user
            matrix_origin_field_mapping = {
                "idx": form.origin_unique_id_field.data,
                "lat": form.origin_latitude_field.data,
                "lon": form.origin_longitude_field.data
            }

            destination_target_field = form.destination_target_field.data
            if form.coverage_measures_checkbox.data is False:
                destination_target_field = ""

            matrix_destination_field_mapping = {
                "idx": form.destination_unique_id_field.data,
                "lat": form.destination_latitude_field.data,
                "lon": form.destination_longitude_field.data
            }

            model_origin_field_mapping = {
                "idx": form.origin_unique_id_field.data,
                "lat": form.origin_latitude_field.data,
                "lon": form.origin_longitude_field.data,
                "population": form.origin_population_field.data
            }

            model_destination_field_mapping = {
                "idx": form.destination_unique_id_field.data,
                "lat": form.destination_latitude_field.data,
                "lon": form.destination_longitude_field.data,
                "capacity": form.destination_target_field.data,
                "category": form.destination_category_field.data
            }

            if form.coverage_measures_checkbox.data is False:
                model_origin_field_mapping["population"] = "skip"
                model_destination_field_mapping["capacity"] = "skip"

            # update file paths to those on the server
            origin_filename = os.path.join(INPUTS_FOLDER, origin_filename)
            destination_filename = os.path.join(INPUTS_FOLDER,
                                                destination_filename)
            categories = form.destination_categories.data
            for x in form.destination_categories:
                print(x)
            maximum_travel_time = int(request.form["maximumTimeSlider"]) * 60
            print("yaaas")
            print(float(request.form["epsilonValueSlider"]))
            # execute health code
            output_files = run_health_code(
                form.access_measures_checkbox.data,
                form.coverage_measures_checkbox.data,
                form.travel_mode.data,
                maximum_travel_time,
                origin_filename,
                matrix_origin_field_mapping,
                destination_filename,
                matrix_destination_field_mapping,
                model_origin_field_mapping,
                model_destination_field_mapping,
                decay_function=form.decay_function.data,
                epsilon=float(request.form["epsilonValueSlider"]),
                walk_speed=float(request.form["walkSpeedSlider"]) * 1.6,
                category_weight_dict=category_weight_dict,
                categories=categories)

            return download_results(output_files)

        else:
            print(form.errors)
            return render_template('index.html', form=form)

    elif request.method == 'GET':

        if form.validate_on_submit:
            print('index GET validated')
            return render_template("index.html", form=form)
        else:
            print("index GET didn't validate")
            return render_template('about.html', form=form)