Ejemplo n.º 1
0
def index():
    df = load(wwwdir + '/app/data.gz')
    sorted_movies = df.count(axis=1).sort_values(
        ascending=False).index.tolist()[:100]
    random.shuffle(sorted_movies)

    form = SubmissionForm()
    movies = zip(sorted_movies[:20], form.radio)
    if form.validate_on_submit():

        tempfile.tempdir = wwwdir + '/app/static'
        tmpdir = tempfile.mkdtemp()
        session['tmpdir'] = tmpdir

        new_user = dict()
        for i, j in enumerate(sorted_movies[:20]):
            if form.radio[i].data == 'NA':
                new_user[j] = np.nan
            else:
                new_user[j] = float(form.radio[i].data)
        df['me'] = pd.Series(new_user)
        p = run_collaborative_filtering(df, int(form.nfeatures.data),
                                        float(form.lamb.data),
                                        int(form.maxiter.data))
        predictions = p['me'].sort_values(ascending=False).index[:100]
        dump(predictions, tmpdir + '/predictions.pkl')
        return redirect('/results')
    return render_template('index.html', form=form, movies=movies)
Ejemplo n.º 2
0
def index():
    form = SubmissionForm()
    if form.validate_on_submit():
        clf = load('clf.gz')
        text = form.text.data
        print(text)
        prediction = clf.predict([text])
        if prediction[0] == 1:
            flash('SPAM')
        else:
            flash('HAM')
    return render_template('index.html', form=form)
Ejemplo n.º 3
0
def add_submission():
    form = SubmissionForm()
    if form.validate_on_submit():
        submission = Submission(sentence=form.sentence.data,
                                is_good=form.is_good.data,
                                author=current_user)
        db.session.add(submission)
        db.session.commit()
        flash('Thank you, add another or train our model!!')
        return redirect(url_for('add_submission'))
    return render_template('add_submission.html',
                           title='Add Submission',
                           form=form)
Ejemplo n.º 4
0
def submitpage():
    if current_user.is_authenticated:
        form = SubmissionForm()
        if form.validate_on_submit():
            flash('Topic {} has been submitted.'.format(form.title.data))
            new_title = form.title.data
            new_text = form.text.data
            p = Post(title=new_title, body=new_text)
            db.session.add(p)
            db.session.commit()
            return redirect(url_for('index'))
        return render_template('submit.html',
                               title='Submit New Entry',
                               form=form)
    return render_template('notloggedin.html')
Ejemplo n.º 5
0
def index():
    permitted_languages = [("C", "C (gcc 4.8.1)"), ("CPP", "C++ (g++ 4.8.1)"), ("CSHARP", "C#"), \
                ("CLOJURE", "Clojure (clojure 1.1.0)"), ("CSS", "CSS"), ("HASKELL", "Haskell (ghc 7.4.1)"), \
                ("JAVA", "Java (openjdk 1.7.0_09)"), ("JAVASCRIPT", "JavaScript"), ("OBJECTIVEC", "Objective-C (clang 3.3)"), \
                ("PERL", "Perl (perl 5.14.2)"), ("PHP", "PHP (php 5.3.10)"), ("PYTHON", "Python (python 2.7.3)"), \
                ("R", "R (RScript 2.14.1)"), ("RUBY", "Ruby (ruby 2.1.1)"), ("RUST", "Rust (rustc 1.4.0)"), ("SCALA", "Scala (scalac 2.9.1)")
    ]

    form = SubmissionForm()
    form.language.choices = permitted_languages

    if form.validate_on_submit():
        global source
        source = form.source_code.data
        global cust_input
        cust_input = form.custom_input.data
        global language
        language = form.language.data
        if form.compile_code.data:
            return redirect(url_for('compile'))
        elif form.run_code.data:
            return redirect(url_for('run'))
        elif form.save_code.data:
            if not (current_user.is_authenticated):
                global temp_source_code
                temp_source_code = source
                flash('You need to login first')
                return redirect(url_for('login'))
            else:
                user = User.query.filter_by(
                    username=current_user.username).first()
                code = SaveCode(source_code=source, coder=user)
                flash('Saved')
                db.session.add(code)
                db.session.commit()

    if request.method == 'GET' and temp_source_code:
        form.source_code.data = temp_source_code
        if hasattr(current_user, 'username'):
            user = User.query.filter_by(username=current_user.username).first()
            code = SaveCode(source_code=temp_source_code, coder=user)
            db.session.add(code)
            db.session.commit()
            flash("Saved")
        temp_source_code = ''

    return render_template('index.html', form=form)
Ejemplo n.º 6
0
def index():
    form = SubmissionForm()
    if form.validate_on_submit():
        new_text = form.text.data
        new_delimiter = form.delimiter.data
        new_operationname = form.operationname.data
        if new_operationname == 'wordcount':
            return redirect(
                url_for('results',
                        operationname=new_operationname,
                        text=new_text,
                        delimiter=new_delimiter))
        if new_operationname == 'charactercount':
            return redirect(
                url_for('results',
                        operationname=new_operationname,
                        text=new_text))
        if new_operationname == 'mostfrequent5':
            return redirect(
                url_for('results',
                        operationname=new_operationname,
                        text=new_text))
    return render_template('index.html', title='Home', form=form)
Ejemplo n.º 7
0
def index():
    form = SubmissionForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            fn = form.submission_file.data.filename
            cat = fn.split('.', 1)[0]
            if cat in categories:
                filename = pycode.save(form.submission_file.data,
                                       folder=secure_filename(
                                           current_user.username))
                new_submission = Submission(filename=filename,
                                            comment=str(form.comment.data),
                                            user_id=current_user.id,
                                            category=cat)
                db.session.add(new_submission)
                db.session.commit()
                flash('Bestand ingeleverd en aan queue toegevoegd.')
            else:
                flash(
                    'Filename {fn} impliceert opdracht {cat}. Deze categorie bestaat niet!'
                    .format(fn=fn, cat=cat))

            return redirect(url_for('index'))
        else:
            flash('ERROR: Er ging iets mis. Het bestand is NIET ingeleverd.',
                  'error')
    queued_submissions = current_user.ungraded_submissions().all()

    results = best_submissions(current_user)
    score = total_score(current_user)

    return render_template("index.html",
                           title='Home Page',
                           form=form,
                           queued_submissions=queued_submissions,
                           results=results,
                           score=score)