From f5e4bbe82459283cca8ebcebf45596a25e2403c4 Mon Sep 17 00:00:00 2001 From: Sabrina Lauredan Date: Thu, 16 Sep 2021 18:28:48 -0400 Subject: [PATCH 1/3] Co-authored-by: KitSutliff --- tests/test_wave_01.py | 3 ++- viewing_party/party.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 995262069..453395996 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -3,7 +3,8 @@ from viewing_party.party import * -def test_create_movie_all_params_valid_returns_movie(): +def test_create_movie_all_params_valid_returns_movie(): + ## create function that returns new dict to contain ratings, etc # Arrange movie_title = "Title A" genre = "Horror" diff --git a/viewing_party/party.py b/viewing_party/party.py index e69de29bb..76b280296 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -0,0 +1,3 @@ +def create_movie(movie_title, genre, rating): + new_movie = {"title": movie_title, "genre": genre, "rating": rating} + return new_movie From a8060fc80b2cc7327c7e7b30872d8aaa96992c64 Mon Sep 17 00:00:00 2001 From: Sabrina Lauredan Date: Fri, 17 Sep 2021 09:15:20 -0400 Subject: [PATCH 2/3] S.Lauredan --- README.md | 30 +++++----- viewing_party/party.py | 132 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 144 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index dfa89c150..12627584d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Viewing Party + ### Wave 1 -1. The first four tests are about a `create_movie()` function. + -2. The next two tests are about an `add_to_watched()` function. + + --> ### Wave 2 - + -2. The next three tests are about a `get_most_watched_genre()` function. + + ### Wave 3 diff --git a/viewing_party/party.py b/viewing_party/party.py index 76b280296..d05845476 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,3 +1,129 @@ -def create_movie(movie_title, genre, rating): - new_movie = {"title": movie_title, "genre": genre, "rating": rating} - return new_movie +#wave 1 + +def create_movie(title, genre, rating): + if title == None: + return None + if genre == None: + return None + if rating == None: + return None + else: + movie = {"title": 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, title): + for movie in user_data['watchlist']: + if movie['title'] == title: + user_data['watchlist'].remove(movie) + user_data["watched"].append(movie) + if user_data['watched'] == []: + user_data["watched"].append(movie) + + return user_data + +#wave 2 pt 1 + +def get_watched_avg_rating(user_data): + if len(user_data["watched"]) == 0: + return 0 + else: + ratings = [] + for movie in user_data['watched']: + ratings.append(movie["rating"]) + average = sum(ratings)/len(ratings) + return average + + # wave 2 pt 2 + +def get_most_watched_genre(user_data): + genres_watched = [] + + if len (user_data["watched"]) == 0: + return None + + for movie in user_data["watched"]: + genres_watched.append(movie["genre"]) + + freq = {} + + for genre in genres_watched: + if not genre in freq: + freq.update({genre:1}) + else: + freq[genre] += 1 + + popular_genre = max(freq, key = freq.get) + + return popular_genre + +#wave 3 pt 1 + +def get_unique_watched(user_data): + user_watched = user_data["watched"] + friends_watched = user_data["friends"] + friend_titles = [] + unique = [] + for friend in friends_watched: + for title in friend["watched"]: + friend_titles.append(title["title"]) + for title in user_watched: + if title['title'] not in friend_titles: + unique.append(title) + return unique + +#wave 3 pt 2 + +def get_friends_unique_watched(user_data): + unique_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if not is_movie_in_list(user_data["watched"], movie) and not is_movie_in_list(unique_movies, movie): + unique_movies.append(movie) + return unique_movies + +# wave 4 + +def get_available_recs(user_data): + host_list = [] + user_subscriptions = user_data["subscriptions"] + rec = [] + friends_unique = get_friends_unique_watched(user_data) + for movie in friends_unique: + if movie["host"] in user_subscriptions: + rec.append(movie) + return rec + + +# #wave 5 pt1 + +def get_new_rec_by_genre(user_data): + fav = get_most_watched_genre(user_data) + friends_unique = get_friends_unique_watched(user_data) + rec =[] + for movie in friends_unique: + if movie["genre"] == fav and not is_movie_in_list(rec, movie): + rec.append(movie) + return rec + +# wave 5 pt 2 + +def get_rec_from_favorites(user_data): + unique_watched = get_unique_watched(user_data) + favorites = user_data['favorites'] + return [movie for movie in unique_watched if movie in favorites] + +# helper + +def is_movie_in_list(list, movie): + for item in list: + if item["title"] == movie["title"]: + return True + return False \ No newline at end of file From 155864969afbdbbda4280be418735b8af7a462a7 Mon Sep 17 00:00:00 2001 From: Sabrina Lauredan Date: Mon, 11 Oct 2021 16:06:35 -0400 Subject: [PATCH 3/3] refactored + readme edit --- README.md | 4 +-- viewing_party/party.py | 69 +++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 12627584d..efbac3a96 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - +- return the genre that is the most frequently watched ### Wave 3 diff --git a/viewing_party/party.py b/viewing_party/party.py index d05845476..05ea13fed 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,11 +1,7 @@ +import statistics #wave 1 - def create_movie(title, genre, rating): - if title == None: - return None - if genre == None: - return None - if rating == None: + if title is None or genre is None or rating is None: return None else: movie = {"title": title, "genre": genre, "rating": rating} @@ -24,9 +20,6 @@ def watch_movie(user_data, title): if movie['title'] == title: user_data['watchlist'].remove(movie) user_data["watched"].append(movie) - if user_data['watched'] == []: - user_data["watched"].append(movie) - return user_data #wave 2 pt 1 @@ -41,14 +34,12 @@ def get_watched_avg_rating(user_data): average = sum(ratings)/len(ratings) return average - # wave 2 pt 2 - +# wave 2 pt 2 + def get_most_watched_genre(user_data): genres_watched = [] - - if len (user_data["watched"]) == 0: + if len(user_data["watched"]) == 0: return None - for movie in user_data["watched"]: genres_watched.append(movie["genre"]) @@ -73,7 +64,7 @@ def get_unique_watched(user_data): unique = [] for friend in friends_watched: for title in friend["watched"]: - friend_titles.append(title["title"]) + friend_titles.append(title["title"]) for title in user_watched: if title['title'] not in friend_titles: unique.append(title) @@ -82,34 +73,49 @@ def get_unique_watched(user_data): #wave 3 pt 2 def get_friends_unique_watched(user_data): + user_watched = user_data['watched'] + any_amount_of_friends_watched = user_data['friends'] + friends_list_of_movies = [] + user_list_of_movies = [] unique_movies = [] - for friend in user_data["friends"]: - for movie in friend["watched"]: - if not is_movie_in_list(user_data["watched"], movie) and not is_movie_in_list(unique_movies, movie): - unique_movies.append(movie) - return unique_movies + for friends_movie in any_amount_of_friends_watched: + for title in friends_movie['watched']: + friends_list_of_movies.append(title) + + for user_movies in user_watched: + user_list_of_movies.append(user_movies['title']) + + for movie in friends_list_of_movies: + if movie["title"] in user_list_of_movies: + continue + elif movie not in unique_movies: + unique_movies.append(movie) + + return unique_movies + + # wave 4 def get_available_recs(user_data): - host_list = [] - user_subscriptions = user_data["subscriptions"] rec = [] + user_subscriptions = user_data["subscriptions"] friends_unique = get_friends_unique_watched(user_data) + for movie in friends_unique: if movie["host"] in user_subscriptions: rec.append(movie) - return rec - + return rec -# #wave 5 pt1 +# wave 5 pt1 def get_new_rec_by_genre(user_data): fav = get_most_watched_genre(user_data) friends_unique = get_friends_unique_watched(user_data) rec =[] + for movie in friends_unique: - if movie["genre"] == fav and not is_movie_in_list(rec, movie): + if movie["genre"] == fav: rec.append(movie) return rec @@ -117,13 +123,6 @@ def get_new_rec_by_genre(user_data): def get_rec_from_favorites(user_data): unique_watched = get_unique_watched(user_data) - favorites = user_data['favorites'] - return [movie for movie in unique_watched if movie in favorites] - -# helper + fav = user_data['favorites'] -def is_movie_in_list(list, movie): - for item in list: - if item["title"] == movie["title"]: - return True - return False \ No newline at end of file + return [movie for movie in unique_watched if movie in fav]