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)
def addSubmission(course_id, assignment_id=None, student_id=None): """display add assignment form""" addSubmissionForm = SubmissionForm() # if you are adding a submission but you need a list of students who # haven't submitted db_conn = db_pool.getconn() dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor) if not student_id: # set the students dropdown # get all students dict_cur.execute( f'SELECT student.student_id, student.first_name, ' f'student.last_name ' f'FROM student ' f'INNER JOIN student_course ' f'ON student.student_id = student_course.student_id ' f'WHERE student_course.course_id = {course_id};') choices = [(row['student_id'], row['first_name'], row['last_name']) for row in dict_cur] # get students who have already submitted because we want to omit them dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor) dict_cur.execute(f''' SELECT student.student_id, student.first_name, student.last_name, student_course.course_id FROM submission INNER JOIN student_submission ON student_submission.submission_id = submission.submission_id INNER JOIN student ON student.student_id = student_submission.student_id INNER JOIN student_course ON student.student_id = student_course.student_id INNER JOIN course ON student_course.course_id = course.course_id INNER JOIN assignment ON submission.assignment = assignment.assignment_id WHERE assignment.assignment_id = {assignment_id} AND student_course.course_id = {course_id}; ''') students_already_submitted = [ (row['student_id'], row['first_name'], row['last_name']) for row in dict_cur] # omit students who have already submitted addSubmissionForm.students = list( set(choices) - set(students_already_submitted)) dict_cur.close() db_pool.putconn(db_conn) return render_template( 'addsubmission.html', submission_form=addSubmissionForm, course_id=course_id, assignment_id=assignment_id, student_id=student_id)
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)
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)
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')
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)
def index(): form = SubmissionForm() if request.method == 'POST': selectedValue = request.form.get('operator') new_num1 = request.form['number'] new_num2 = request.form['number2'] if form.validate() == False: return redirect(url_for('result', selectedValue="error")) else: response = make_response( redirect(url_for('result', selectedValue=selectedValue))) response.set_cookie('num1', new_num1) response.set_cookie('num2', new_num2) return response elif request.method == 'GET': return render_template('index.html', title='Home', form=form)
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)
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)
def saveEditSubmission(submission_id, course_id, item_id, redirect_option): """process submission form""" form = SubmissionForm(request.form) submission = {} if request.method == 'POST' and form.validate(): submission['submitted'] = request.form['sub_time'] submission['grade'] = request.form['grade'] db_conn = db_pool.getconn() cursor = db_conn.cursor() cursor.execute( f"UPDATE submission SET grade = %s, submitted = %s " f"WHERE submission_id = %s; ", (submission['grade'], submission['submitted'], submission_id)) db_conn.commit() cursor.close() db_pool.putconn(db_conn) if redirect_option == "student": return redirect( url_for( 'student', student_id=item_id, course_id=course_id)) elif redirect_option == "assignment": return redirect( url_for( 'assignment', assignment_id=item_id, course_id=course_id)) else: return redirect( url_for( 'view_course', course_id=course_id))
def index(request): if request.method == "POST": form = SubmissionForm(request.POST, request.FILES) print(form) if form.is_valid(): form.save() return redirect("submission-success") else: form = SubmissionForm() context = { 'title': 'Submission form', 'form': form } return render(request, "home.html", context=context)
def editSubmission(submission_id, course_id, item_id, redirect_option): """display edit submission form""" db_conn = db_pool.getconn() dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor) dict_cur.execute( f'''SELECT * FROM submission WHERE submission_id = {submission_id}''') submission = dict_cur.fetchone() dict_cur.close() db_pool.putconn(db_conn) editSubmissionForm = SubmissionForm() return render_template( 'editsubmission.html', editSubmissionForm=editSubmissionForm, submission=submission, course_id=course_id, item_id=item_id, redirect_option=redirect_option)