From c4cb7a95f59099153f51a7fc12a8c0fe47658874 Mon Sep 17 00:00:00 2001 From: Brittney Payne Date: Sun, 28 Mar 2021 15:15:17 -0700 Subject: [PATCH 1/4] Finished Project pre-submission --- .vscode/launch.json | 15 ++++ .vscode/settings.json | 8 ++ viewing_party/main.py | 190 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..17e15f27e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..60400e381 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/viewing_party/main.py b/viewing_party/main.py index e69de29bb..ba2e09009 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -0,0 +1,190 @@ + + +# *****wave 1 testing - tests # 1 - 9 ****** +# test 1 funct that takes in 3 args /creates a dict of movie info +# test 2 if title returns none function returns none +# test 3 if genre returns none function returns none +# test 4 if rating returns none function returns none +def create_movie(movie_title, genre, rating): + movie = { + 'title' : movie_title, + 'genre': genre, + 'rating': rating + } + if movie['title'] == None or movie['genre'] == None or movie['rating'] == None: + return None + else: + return movie + +# test 5 funct to add movie to "watched" list, takes in +# user data (list of dict) and a movie dict returns new list +def add_to_watched(user_data, movie): + user_data['watched'].append(movie) + return user_data + +# test 6 func to add movie to watchlist, takes in user data (list of dict) +# and a movie dict and returns the new list +def add_to_watchlist(user_data, movie): + user_data['watchlist'].append(movie) + return user_data + +# test 7 func for watched movies moves a movie +# (by title) from watchlist to empty watched list + +# test 8 moves a movie from watched list to watchlist when watchlist is truthy + +# test 9 function does nothing if movie title is not in watched list +def watch_movie(user_data, title): + for movie_dict in user_data['watchlist']: + if title in movie_dict.values(): + user_data['watchlist'].remove(movie_dict) + user_data['watched'].append(movie_dict) + return user_data + return user_data + +# *****wave 2 testing test 10 - 13 ***** +# test 10 funct for avg rating that takes in user_data returns avg of ratings + +# # test 11 function returns 0.0 if no movies in watched list +def get_watched_avg_rating(user_data): + if len(user_data['watched']) == 0: + mean = 0.0 + else: + ratings = [movie['rating'] for movie in user_data['watched']] + mean = sum(ratings) / len(ratings) + return mean + + +# test 12 funct collects the genre data and returns most watched genre + +# test 13 make sure the function returns none if list is empty +def get_most_watched_genre(user_data): + word_count = {} + if user_data['watched'] == []: + return None + else: + for movie_dict in user_data['watched']: + if movie_dict['genre'] not in word_count: + word_count[movie_dict['genre']] = 1 + else: + word_count[movie_dict['genre']] += 1 + max_genre = max(word_count) + return max_genre + + + +# ***** wave 3 tests 14-18 **** +# test 14 funct get_unique_watched takes in user data +# returns list of movies in user data that are not in friends data + +# test 15 returns an empty list if everyone watched the same movies + +def get_unique_watched(user_data): + + friends_watched = [] + for dictionary in user_data['friends']: + for title_list in dictionary.values(): + for dict in title_list: + friends_watched.append(dict) + + unique_watched = [movie for movie in user_data['watched'] if movie not in friends_watched] + + # for movie_title_dict in user_data['watched']: + # if movie_title_dict not in friends_watched: + # unique_watched.append(movie_title_dict) + + return unique_watched + + +# test 16 function get_friends_unique_watched +# takes in user_data determines which movies at least one of +# users friend has watched, but user has not. return as +# list of dict. + +# test 17 does it work with only one friend + + +# test 18 make sure the function returns [] if the user has +# watched all the movies friends have watched. + + +def get_friends_unique_watched(user_data): + friends_watched = [] +# creates a list of dict of movies friends have watched + for friend_dict in user_data['friends']: + for title_list in friend_dict.values(): + for title in title_list: + friends_watched.append(title) +# set a new list to remove duplicate movies + friends_watched_remove_dupes = [] + for movie in friends_watched: + if movie not in friends_watched_remove_dupes: + friends_watched_remove_dupes.append(movie) + + more_unique = [movie for movie in friends_watched_remove_dupes +if movie not in user_data['watched']] + + return more_unique + + +# ****** wave 4 tests 19 - 20 ******** +# test 19 funct get_available_recs takes in user_data +# w/ dict key "subscriptions" value is list strings +# each friends watched movie data will also have a host key, whose +# value will be the streaming service as string +# output should be a list of reccomended moves that +# a: user has not watched +# b: at least one friend has watched +# c: the host of the movie is in the users "subscriptions" + +# test 20 ensure you return an empty list if there are no intersections +def get_available_recs(user_data): + friends_movies = get_friends_unique_watched(user_data) + reccomendations = [dictionary for dictionary in + friends_movies if dictionary['host'] in + user_data['subscriptions']] + return reccomendations + + +# ****** test wave 5 tests 20 - 25 ****** +# test 21 funct get_new_rec_by_genre takes in user_data +# consider most frequently watched genre/determine +# a list of recco movies - only if: +# a. user has not watched it +# b. at least one of friends has watched it +# c. the genre of the movie is the same as the most freq genre +# return list of reccomended movies +# return a valid list with large input +# +# +# test 22 return empty list when user_data is empty + +# test 23 return empty list when friends watched lists are empty + +# test 24 return empty list when user has no faves and no unique +# movies in watch list + + +def get_new_rec_by_genre(user_data): + + most_watched_genre = get_most_watched_genre(user_data) + friends_watched_user_has_not = get_friends_unique_watched(user_data) + new_rec_by_genre = [movie for movie in friends_watched_user_has_not if + movie['genre']== most_watched_genre] + return new_rec_by_genre + + +# test 25 funct get_rec_from_favorites +# take in user_data +# consider most freq watched genre, then determine a list +# of recco movies that should be added to the list only if in users +# favorites and if none of the friends have watched. + +def get_rec_from_favorites(user_data): + fave_movies = [movie for movie in user_data['favorites']] + unique_watched = get_unique_watched(user_data) + reccomended_from_faves = [movie for movie in fave_movies if + movie in unique_watched] + return reccomended_from_faves + + From 5d99621dbb6a9c327eb56835c4c6d36c79084943 Mon Sep 17 00:00:00 2001 From: Brittney Payne Date: Sun, 28 Mar 2021 19:12:40 -0700 Subject: [PATCH 2/4] Final Polishing --- viewing_party/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index ba2e09009..2eeeeb3e3 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -87,7 +87,9 @@ def get_unique_watched(user_data): for dict in title_list: friends_watched.append(dict) - unique_watched = [movie for movie in user_data['watched'] if movie not in friends_watched] + + unique_watched = [movie for movie in user_data['watched']\ + if movie not in friends_watched] # for movie_title_dict in user_data['watched']: # if movie_title_dict not in friends_watched: @@ -96,6 +98,9 @@ def get_unique_watched(user_data): return unique_watched + + + # test 16 function get_friends_unique_watched # takes in user_data determines which movies at least one of # users friend has watched, but user has not. return as @@ -183,8 +188,8 @@ def get_new_rec_by_genre(user_data): def get_rec_from_favorites(user_data): fave_movies = [movie for movie in user_data['favorites']] unique_watched = get_unique_watched(user_data) - reccomended_from_faves = [movie for movie in fave_movies if + recommended_from_faves = [movie for movie in fave_movies if movie in unique_watched] - return reccomended_from_faves + return recommended_from_faves From 0d2df7d580ef9974f6f1960592c241362f914150 Mon Sep 17 00:00:00 2001 From: Brittney Payne Date: Mon, 29 Mar 2021 10:48:02 -0700 Subject: [PATCH 3/4] added a note for git testing --- viewing_party/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index 2eeeeb3e3..7ac79bc70 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -1,5 +1,5 @@ - +#### VIEWING PARTY PROJECT ##### # *****wave 1 testing - tests # 1 - 9 ****** # test 1 funct that takes in 3 args /creates a dict of movie info # test 2 if title returns none function returns none From 773e2f7327f17160cc170f0f4800f05ce51d1784 Mon Sep 17 00:00:00 2001 From: Brittney Payne Date: Wed, 31 Mar 2021 10:43:29 -0700 Subject: [PATCH 4/4] Updated get_unique_watched functions with sets and tuples --- viewing_party/main.py | 85 +++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index 7ac79bc70..05eae7f6f 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -79,23 +79,49 @@ def get_most_watched_genre(user_data): # test 15 returns an empty list if everyone watched the same movies +def uniq_user_movies(user_data): + movies = set() + for movie in user_data["watched"]: + movies.add(tuple(movie.items())) + print(movies) + return movies + +def uniq_friends_movies(user_data): + movies = set() + + for friend in user_data["friends"]: + for movie in friend["watched"]: + movies.add(tuple(movie.items())) + print(movies) + return movies + + def get_unique_watched(user_data): + user_movies = uniq_user_movies(user_data) + + friends_movies = uniq_friends_movies(user_data) + + return [dict(movie) for movie in user_movies - friends_movies] + + + +# def get_unique_watched(user_data): - friends_watched = [] - for dictionary in user_data['friends']: - for title_list in dictionary.values(): - for dict in title_list: - friends_watched.append(dict) +# friends_watched = [] +# for dictionary in user_data['friends']: +# for title_list in dictionary.values(): +# for dict in title_list: +# friends_watched.append(dict) - unique_watched = [movie for movie in user_data['watched']\ - if movie not in friends_watched] +# unique_watched = [movie for movie in user_data['watched']\ +# if movie not in friends_watched] - # for movie_title_dict in user_data['watched']: - # if movie_title_dict not in friends_watched: - # unique_watched.append(movie_title_dict) +# # for movie_title_dict in user_data['watched']: +# # if movie_title_dict not in friends_watched: +# # unique_watched.append(movie_title_dict) - return unique_watched +# return unique_watched @@ -114,22 +140,27 @@ def get_unique_watched(user_data): def get_friends_unique_watched(user_data): - friends_watched = [] -# creates a list of dict of movies friends have watched - for friend_dict in user_data['friends']: - for title_list in friend_dict.values(): - for title in title_list: - friends_watched.append(title) -# set a new list to remove duplicate movies - friends_watched_remove_dupes = [] - for movie in friends_watched: - if movie not in friends_watched_remove_dupes: - friends_watched_remove_dupes.append(movie) - - more_unique = [movie for movie in friends_watched_remove_dupes -if movie not in user_data['watched']] - - return more_unique +#trying with tuples + user_watched = uniq_user_movies(user_data) + friends_watched = uniq_friends_movies(user_data) + + return [dict(movie) for movie in friends_watched - user_watched ] +# friends_watched = [] +# # creates a list of dict of movies friends have watched +# for friend_dict in user_data['friends']: +# for title_list in friend_dict.values(): +# for title in title_list: +# friends_watched.append(title) +# # set a new list to remove duplicate movies +# friends_watched_remove_dupes = [] +# for movie in friends_watched: +# if movie not in friends_watched_remove_dupes: +# friends_watched_remove_dupes.append(movie) + +# more_unique = [movie for movie in friends_watched_remove_dupes +# if movie not in user_data['watched']] + +# return more_unique # ****** wave 4 tests 19 - 20 ********