-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scissors - Laurel O #67
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.nosetestsEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
def create_movie(title, genre, rating): | ||
movie_dict = {"title": title, "genre": genre, "rating": rating} | ||
if None in movie_dict.values(): | ||
return None | ||
else: | ||
return movie_dict | ||
|
||
def add_to_watched(user_data, movie): | ||
user_data["watched"].append(movie) | ||
return user_data | ||
|
||
def add_to_watchlist(user_data, movie): | ||
user_data["watchlist"].append(movie) | ||
return user_data | ||
|
||
def watch_movie(user_data, title): | ||
for movie in user_data["watchlist"]: | ||
if movie["title"] == title: | ||
user_data["watchlist"].remove(movie) | ||
user_data["watched"].append(movie) | ||
return user_data | ||
|
||
def list_com_fun(user_data_user_data_key, value): | ||
list_com = [v for i in user_data_user_data_key for k,v in i.items() \ | ||
if v == i[value]] | ||
return list_com | ||
|
||
def get_watched_avg_rating(user_data): | ||
list_dic = user_data["watched"] | ||
avg_rating = 0.0 | ||
if len(list_dic) > 0: | ||
rating_list = [v for i in list_dic for k,v in i.items() if k=="rating"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
avg_rating = sum(rating_list) / len(rating_list) | ||
return avg_rating | ||
else: | ||
return avg_rating | ||
|
||
def get_most_watched_genre(user_data): | ||
genres = list_com_fun(user_data["watched"], "genre") | ||
if genres == []: | ||
return None | ||
return max(genres) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you solve this if you didn't have access to the max function? |
||
|
||
def get_unique_watched(user_data): | ||
answer = [] | ||
user = list_com_fun(user_data["watched"], "title") | ||
friend1 = list_com_fun(user_data["friends"][0]["watched"] , "title") | ||
friend2 = list_com_fun(user_data["friends"][1]["watched"] ,"title") | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function will pass the tests because they only have 2 friends, how would this function need to change to be generalized to a friend list of any size? |
||
friend_movies = friend1 + friend2 | ||
unique = [x for x in user if x not in friend_movies] | ||
for v in unique: | ||
movie = {"title":v} | ||
movie_copy = movie.copy() | ||
answer.append(movie_copy) | ||
return answer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests for this function use a simplified version of the movie dictionary. However, our original definition of a movie was that a movie has a title, rating and genre. How could you create a list of the original movie dictionaries using the Note: movie.copy() is not needed here. |
||
|
||
def get_friends_unique_watched(user_data): | ||
answer = [] | ||
user = list_com_fun(user_data["watched"],"title") | ||
friend1 = list_com_fun(user_data["friends"][0]["watched"],"title") | ||
friend2 = list_com_fun(user_data["friends"][1]["watched"] ,"title") | ||
friend_movies = friend1 + friend2 | ||
unique = [x for x in friend_movies if x not in user] | ||
unique = set(unique) | ||
for v in unique: | ||
movie = {"title":v} | ||
movie_copy = movie.copy() | ||
answer.append(movie_copy) | ||
return answer | ||
|
||
def get_available_recs(user_data): | ||
user_sub = user_data["subscriptions"] | ||
friend_sub = [i for i in user_data["friends"][0]["watched"] and \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function has the same limitation as get_unique_watched and get_friends_unique_watched. How could you account for an unknown number of friends? |
||
user_data["friends"][1]["watched"] for k,v in i.items() if k=="host"] | ||
rec_host = [i for i in friend_sub for v in i.values() if v in user_sub] | ||
return rec_host | ||
|
||
def get_new_rec_by_genre(user_data): | ||
fav_genre = get_most_watched_genre(user_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of a helper function! |
||
rec_movies = [movie for friend in user_data["friends"] for movie \ | ||
in friend["watched"] if movie["genre"]== fav_genre] | ||
return rec_movies | ||
|
||
def get_rec_from_favorites(user_data): | ||
rec_fav_movies = [movie for movie in user_data["favorites"] if movie not in \ | ||
(i for friend in user_data["friends"] for i in friend["watched"])] | ||
return rec_fav_movies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable names can greatly improve code readability.
When using list comprehension, simpler is often more readable:
list_com = [i[value] for i in user_data_user_data_key]
. For readability I recommend avoiding double loops in list comprehension (sometimes they are unavoidable, but they are much harder to read).compare this function to (please ignore tab error):