-
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 - Terah Bruce #53
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,15 @@ | ||
{ | ||
"python.testing.unittestArgs": [ | ||
"-v", | ||
"-s", | ||
"./tests", | ||
"-p", | ||
"*test.py" | ||
], | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.nosetestsEnabled": false, | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
def create_movie(movie_title, genre, rating): | ||
if movie_title == None: | ||
return None | ||
elif genre == None: | ||
return None | ||
elif rating == None: | ||
return None | ||
else: | ||
movie = {"title": movie_title, | ||
"genre": genre, | ||
"rating": rating} | ||
return movie | ||
|
||
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, movie_title): | ||
# print("****** before execution *****") | ||
# print(user_data) | ||
watchlist = user_data["watchlist"] | ||
for i in range(len(watchlist)): | ||
if watchlist[i]["title"] == movie_title: | ||
movie = watchlist[i] | ||
add_to_watched(user_data, movie) | ||
#remove from watchlist | ||
watchlist.remove(movie) | ||
return user_data | ||
else: | ||
return user_data | ||
|
||
def get_watched_avg_rating(user_data): | ||
watchedlist = user_data["watched"] | ||
ratings = [] | ||
if len(watchedlist) == 0: | ||
return 0.0 | ||
else: | ||
for i in range(len(watchedlist)): | ||
ratings.append(watchedlist[i]["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.
|
||
ratings_sum = 0 | ||
for i in ratings: | ||
ratings_sum = ratings_sum + i | ||
average = ratings_sum/len(ratings) | ||
print(average) | ||
return average | ||
|
||
def get_most_watched_genre(user_data): | ||
genres = {} | ||
watchedlist = user_data["watched"] | ||
if len(watchedlist) == 0: | ||
return None | ||
else: | ||
for i in range(len(watchedlist)): | ||
if watchedlist[i]["genre"] not in genres: | ||
genres[watchedlist[i]["genre"]] = 1 | ||
else: | ||
genres[watchedlist[i]["genre"]] += 1 | ||
sort_genres = sorted(genres.items(), key=lambda x: x[1], reverse=True) | ||
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 could you find the maximum if you didn't have access this function? |
||
return sort_genres[0][0] | ||
|
||
def get_unique_watched(user_data): | ||
userwatched = user_data["watched"] | ||
friendswatched = user_data["friends"] | ||
unique_watched = [] | ||
friendtitlelist = [] | ||
for friend in friendswatched: | ||
watched = friend["watched"] | ||
for title in watched: | ||
friendtitlelist.append(title["title"]) | ||
for title in userwatched: | ||
if title["title"] not in friendtitlelist: | ||
unique_watched.append(title) | ||
return unique_watched | ||
|
||
def get_friends_unique_watched(user_data): | ||
userwatched = user_data["watched"] | ||
friendswatched = user_data["friends"] | ||
userlist = [] | ||
unique_watched = [] | ||
for title in userwatched: | ||
userlist.append(title["title"]) | ||
for friend in friendswatched: | ||
watched = friend["watched"] | ||
for title in watched: | ||
if title["title"] not in userlist: | ||
if title not in unique_watched: | ||
Comment on lines
+91
to
+92
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 style of chained if statements can be combined into one by |
||
unique_watched.append(title) | ||
print(unique_watched) | ||
return unique_watched | ||
|
||
|
||
def get_available_recs(user_data): | ||
user_hosts_list = user_data["subscriptions"] | ||
user_watched_list = user_data["watched"] | ||
friends_dictkey_watched_list_of_dicts = user_data["friends"] | ||
users_list_of_watched_titles = [] | ||
recommendations = [] | ||
for title in user_watched_list: | ||
users_list_of_watched_titles.append(title["title"]) | ||
Comment on lines
+104
to
+105
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 section of code is doing the same thing as lines 86 & 87 above, making this a great candidate for a helper function. Whenever the same code chunk is showing up multiple places consider pulling it out into a helper function. |
||
for friend in friends_dictkey_watched_list_of_dicts: | ||
friends_watched_list_of_dicts = friend["watched"] | ||
for movie in friends_watched_list_of_dicts: | ||
if movie["title"] not in users_list_of_watched_titles: | ||
if movie["host"] in user_hosts_list: | ||
if movie not in recommendations: | ||
recommendations.append(movie) | ||
|
||
return recommendations | ||
|
||
|
||
def get_new_rec_by_genre(user_data): | ||
most_watched_genre = get_most_watched_genre(user_data) | ||
user_watched_list = user_data["watched"] | ||
friends_dictkey_watched_list_of_dicts = user_data["friends"] | ||
users_list_of_watched_titles = [] | ||
recommendations = [] | ||
for title in user_watched_list: | ||
users_list_of_watched_titles.append(title["title"]) | ||
for friend in friends_dictkey_watched_list_of_dicts: | ||
friends_watched_list_of_dicts = friend["watched"] | ||
for movie in friends_watched_list_of_dicts: | ||
if movie["title"] not in users_list_of_watched_titles: | ||
if movie["genre"] is most_watched_genre: | ||
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. In this conditional statement use |
||
if movie not in recommendations: | ||
recommendations.append(movie) | ||
print(recommendations) | ||
return recommendations | ||
|
||
def get_rec_from_favorites(user_data): | ||
#creating variables for easier access to nested data | ||
user_fave_dictkey_list_of_dicts = user_data["favorites"] | ||
friends_dictkey_watched_list_of_dicts = user_data["friends"] | ||
friends_list_of_watched_titles = [] | ||
recommendations = [] | ||
|
||
#putting titles into list for easier sorting/comparison. | ||
for friend in friends_dictkey_watched_list_of_dicts: | ||
friends_watched_list_of_dicts = friend["watched"] | ||
for movie in friends_watched_list_of_dicts: | ||
friends_list_of_watched_titles.append(movie["title"]) | ||
#comparing movies in user favorites to friends watched movies | ||
for movie in user_fave_dictkey_list_of_dicts: | ||
#checking if movies in users faves are not in friends watched | ||
if movie["title"] not in friends_list_of_watched_titles: | ||
recommendations.append(movie) | ||
print(recommendations) | ||
return recommendations |
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.
Consider using the
for movie in watchlist
style for loop here.