Ejemplo n.º 1
0
def index():

    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        # If the form is submitted and validated, store all the
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        # Preprocess data
        data = preprocess(session)

        # Get model outputs
        pred = predict(data)

        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['pred'] = pred

        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Ejemplo n.º 2
0
def commerce():
    form = DataForm()
    if form.validate_on_submit():
        if request.method == "POST":
            Test(form)
        return redirect(url_for('skillcert')) 
    return render_template('commerce.html',title='Commerce',form=form)
Ejemplo n.º 3
0
def humanities():
    form = DataForm()
    if form.validate_on_submit():
        if request.method == "POST":
            Test(form)
        return redirect(url_for('skillcert'))
    return render_template('humanities.html',title='Humanities',form=form)
Ejemplo n.º 4
0
def getData():
    dataForm = DataForm()
    if dataForm.validate_on_submit():
        page = requests.get(
            'https://www.nbastuffer.com/2019-2020-nba-player-stats/')
        data = BeautifulSoup(page.content, 'html.parser')
        html = [i for i in list(data.children)][3]
        tr_list = html.find_all('tr')[1:]
        session['data'] = cleanData(tr_list, dataForm.search.data)
        flash("Retrieved Data Successfully", "success")
        return redirect(url_for('index', data=session.get('data')))
Ejemplo n.º 5
0
def index():
    form = DataForm()
    execution_time = 0
    if form.validate_on_submit():
        start_time = time.time()
        rpn.clear()
        rpn.push(form.equation_field.data)
        form.result_field.data = rpn.get_status()
        form.errors_field.data = rpn.errors
        execution_time = time.time() - start_time
    return render_template('index.html',
                           execution_time=execution_time,
                           title=u'RPN калькулятор',
                           form=form)
Ejemplo n.º 6
0
def pollData(sesh_id):
    header = "Polling Data"
    form = DataForm()

    sesh = Session.query.filter_by(session_id=sesh_id).first()
    poll = sesh.poll

    question = poll.question

    total_count = poll.a_num + poll.b_num + poll.c_num + poll.d_num

    a_perc = 0
    b_perc = 0
    c_perc = 0
    d_perc = 0

    if poll.a_num > 0:
        a_perc = round((poll.a_num / total_count) * 100, 2)
    if poll.b_num > 0:
        b_perc = round((poll.b_num / total_count) * 100, 2)
    if poll.c_num > 0:
        c_perc = round((poll.c_num / total_count) * 100, 2)
    if poll.d_num > 0:
        d_perc = round((poll.d_num / total_count) * 100, 2)

    data = [(poll.a, a_perc), (poll.b, b_perc), (poll.c, c_perc),
            (poll.d, d_perc)]

    if form.validate_on_submit():
        # To close the poll we need to end the session and delete the poll from
        # the database.
        if form.close.data:

            db.session.delete(poll)
            db.session.commit()
            db.session.delete(sesh)
            db.session.commit()

            flash("Polling closed! Thanks for hosting your poll!")
            return redirect('/home')
        else:
            return redirect('/pollData/' + sesh.session_id)

    return render_template('data.html',
                           title='Data',
                           header=header,
                           question=question,
                           data=data,
                           form=form)
Ejemplo n.º 7
0
def home():
    form = DataForm()
    error = False

    if form.validate_on_submit():
        # Use these for input checking
        title = form.title.data
        description = form.description.data
        preds = classify_movie(title, description, model=model, verbose=False)
        error = True

        for pred in preds:
            flash(pred)

    return render_template('index.html', error=error, form=form)
Ejemplo n.º 8
0
def index():

    """
    We grab the form defined in `forms.py`. 
    If the form is submitted (and passes the validators) 
    then we grab all the values entered by the user and 
    display them. 
    """

    form = DataForm()
    
    if form.validate_on_submit():

        # If the form is submitted then store all the inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value
        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Ejemplo n.º 9
0
def index():

    """
    We grab the form defined in `forms.py`. 
    If the form is submitted (and passes the validators) 
    then we grab all the values entered by the user and 
    predict. 
    """


    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        # If the form is submitted and validated, store all the 
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        session['csrf_token'] = ''
        # Get additional user data
        user_info = request.headers.get('User-Agent')
        white = "\033[1;37;40m"
        print("\033[1;32;40m Preprocess  \n",white)
        # Preprocess data
        print(f"Pre preprocess: {session}")
        data = preprocess(session)
        print(f"Post preprocess: {data}")
        print("\033[1;32;40m Predict  \n",white)
        # Get model outputs 
        pred = predict(data)
        print("\033[1;32;40m Postprocess  \n",white)
        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['user_info'] = user_info
        session['pred'] = pred


        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Ejemplo n.º 10
0
def calculate():
    form = DataForm()
    if form.validate_on_submit():
        expression = form.data['expression']
        user = form.data['user_name']
        first_number, second_number, action = calc.parse_expression(expression)
        alchemy_action = session.AlchemyActions()
        calculator = calc.Calculator(first_number, second_number, action)
        result = calculator.calculate()
        user_id = alchemy_action.user_id(user)
        if alchemy_action.user_in_table(user):
            alchemy_action.update_counter(user)
        else:
            user_to_table = db.Users(user, 1)
            alchemy_action.add_user(user_to_table)
        to_res = db.Results(first_number, action, second_number, result,
                            user_id)
        alchemy_action.add_res(to_res)
        return redirect('/calculate')
    return render_template('calculate.html', title='Sign In', form=form)
Ejemplo n.º 11
0
def index():
    """
    We grab the form defined in `forms.py`.
    If the form is submitted (and passes the validators)
    then we grab all the values entered by the user and
    predict.
    """

    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        session.clear()
        # If the form is submitted and validated, store all the
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        # Get additional user data
        user_info = request.headers.get('User-Agent')

        # Preprocess data
        data = preprocess(session)

        # Get model outputs
        pred = predict(data)

        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['user_info'] = user_info
        session['pred'] = pred

        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Ejemplo n.º 12
0
def success():
    form = DataForm()
    email = form.email.data
    height = form.height.data

    if form.validate_on_submit():
        if Data.query.filter_by(email=email).first():
            flash('Validation errors')
            form.email.errors.append('Email address already exists.')
            return render_template('home.html', form=form)

        data = Data(email=email, height=height)
        db.session.add(data)
        db.session.commit()

        average_height = db.session.query(func.avg(Data.height)).scalar()
        average_height = round(average_height, 1)
        people_count = db.session.query(Data).count()

        text_body = render_template('/email/height_mail.txt',
                                    height=height,
                                    average_height=average_height,
                                    people_count=people_count)
        html_body = render_template('/email/height_mail.html',
                                    height=height,
                                    average_height=average_height,
                                    people_count=people_count)
        send_email(subject="Height data",
                   recipients=[email],
                   text_body=text_body,
                   html_body=html_body)

        return render_template('success.html')
    else:
        flash('Validation errors')
        return render_template('home.html', form=form)