forked from tiyd-python-2015-05/movie-recommendations
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.py
64 lines (49 loc) · 1.87 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, url_for, render_template
import recommend as r
app = Flask(__name__)
db = r.DataBase(movies_file=r.MOVIES,
ratings_file=r.RATINGS)
db.calculate_similarities()
users = sorted([i for i in db.users], key=int)
# @app.route('/')
# def hello_world():
# return 'Hello World! ' + url_for('hello')
@app.route('/')
def index():
"""Display landing page"""
user = '1'
top_n = db.top_n(n=20, min_n=5, user=None)
return render_template('index.html', user=user, db=db, users=users,
top_n=top_n)
# @app.route('/hello')
# def hello():
# return 'Hello World'
@app.route('/user/<user>')
def show_user_profile(user): # db=db):
"""Show the user profile for user"""
db.users[user].sort_ratings()
pop = db.recommend(user, n=20, mode='dumb', num_users=5)
rec = db.recommend(user, n=20, mode='simple', num_users=5)
# print('Your favorite movies:\n', '*'*40)
favs = db.users[user].my_favorites(
n=500) # db.translate(db.users[user].my_favorites(n=500), fn=db.get_title)
# print('Your recommended movies:\n', '*'*40)
recs = rec # recs = db.translate(rec, fn=db.get_title) # TODO: Add decorator for translate?
sim = db.similar(user, n=10, min_matches=3)
return render_template('user.html', user=user, db=db, favs=favs, pop=pop,
recs=recs, users=users, sim=sim)
@app.route('/movie/<movie>')
def show_movie(movie): # db=db):
"""Show the movie profile movie"""
return render_template('movie.html', db=db, movie=movie)
# @app.route('/post/<int:post_id>')
# def show_post(post_id):
# # show the post with the given id, the id is an integer
# return 'Post %d' % post_id
#
# @app.route('/bla')
# def blabla():
# bla = 'blah..blah...'
# return render_template('template.html', bla=bla)
if __name__ == '__main__':
app.run(debug=True)