From a3abe8edbafdfaa3cfd6ecd509c25e40055d8aff Mon Sep 17 00:00:00 2001 From: Jessica Date: Wed, 29 Mar 2023 13:20:59 -0600 Subject: [PATCH 1/8] wave 1 code and tests --- tests/test_wave_01.py | 37 +++++++++------ tests/test_wave_02.py | 10 ++-- tests/test_wave_03.py | 12 ++--- tests/test_wave_04.py | 6 +-- tests/test_wave_05.py | 14 +++--- viewing_party/party.py | 103 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 146 insertions(+), 36 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..a9b67f967 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +32,7 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +45,7 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +58,7 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +79,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] == GENRE_1 assert updated_data["watched"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +99,7 @@ def test_adds_movie_to_non_empty_user_watched(): assert movie in updated_data["watched"] assert FANTASY_2 in updated_data["watched"] -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -120,7 +120,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] == GENRE_1 assert updated_data["watchlist"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -140,7 +140,7 @@ def test_adds_movie_to_non_empty_user_watchlist(): assert movie in updated_data["watchlist"] assert FANTASY_2 in updated_data["watchlist"] -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -158,13 +158,16 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 - - raise Exception("Test needs to be completed.") + assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 + assert updated_data["watched"][0]["genre"] == GENRE_1 + assert updated_data["watched"][0]["rating"] == RATING_1 + + # raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -182,13 +185,17 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - - raise Exception("Test needs to be completed.") + + assert movie_to_watch not in updated_data["watchlist"] + assert movie_to_watch in updated_data["watched"] + assert FANTASY_2 in updated_data["watched"] + + # raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 19f045c79..64b62729d 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +27,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +39,7 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre_order_mixed(): # Arrange janes_data = clean_wave_2b_data() @@ -51,7 +51,7 @@ def test_most_watched_genre_order_mixed(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2b_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..8b3d1a203 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Assert assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,7 +43,7 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -54,13 +54,13 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 - + raise Exception("Test needs to be completed.") # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..0b0b3c7e2 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { @@ -38,7 +38,7 @@ def test_no_available_friend_recs(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_no_available_friend_recs_watched_all(): # Arrange amandas_data = { diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..345423fb7 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +38,7 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -53,12 +53,14 @@ def test_new_genre_rec_from_empty_friends(): ] } + raise Exception("Test needs to be completed.") + # ********************************************************************* # ****** Complete the Act and Assert Portions of these tests ********** # ********************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -72,7 +74,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -94,7 +96,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..ad859f86d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,124 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + + if not (title and genre and rating): + 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) + break + + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +# Wave 2 +# Create a function named get_watched_avg_rating. This function should... +# take one parameter: user_data +# the value of user_data will be a dictionary with a "watched" list of movie dictionaries +# This represents that the user has a list of watched movies +# Calculate the average rating of all movies in the watched list +# The average rating of an empty watched list is 0.0 +# return the average rating +# Create a function named get_most_watched_genre. This function should... +# take one parameter: user_data +# the value of user_data will be a dictionary with a "watched" list of movie dictionaries. Each movie dictionary has a key "genre". +# This represents that the user has a list of watched movies. Each watched movie has a genre. +# The values of "genre" is a string. +# Determine which genre is most frequently occurring in the watched list +# return the genre that is the most frequently watched +# If the value of "watched" is an empty list, get_most_watched_genre should return None. + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +# Create a function named get_unique_watched. This function should... +# take one parameter: user_data +# the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" +# This represents that the user has a list of watched movies and a list of friends +# The value of "friends" is a list +# Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. +# Each movie dictionary has a "title". +# Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies the user has watched, but none of their friends have watched. +# Return a list of dictionaries, that represents a list of movies +# Create a function named get_friends_unique_watched. This function should... +# take one parameter: user_data +# the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" +# This represents that the user has a list of watched movies and a list of friends +# The value of "friends" is a list +# Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. +# Each movie dictionary has a "title". +# Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies at least one of the user's friends have watched, but the user has not watched. +# Return a list of dictionaries, that represents a list of movies + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +# Wave 4 +# Create a function named get_available_recs. This function should... +# take one parameter: user_data +# user_data will have a field "subscriptions". The value of "subscriptions" is a list of strings +# This represents the names of streaming services that the user has access to +# Each friend in "friends" has a watched list. Each movie in the watched list has a "host", which is a string that says what streaming service it's hosted on +# Determine a list of recommended movies. A movie should be added to this list if and only if: +# The user has not watched it +# At least one of the user's friends has watched +# The "host" of the movie is a service that is in the user's "subscriptions" +# Return the list of recommended movies + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +# Wave 5 +# Create a function named get_new_rec_by_genre. This function should... +# take one parameter: user_data +# Consider the user's most frequently watched genre. Then, determine a list of recommended movies. A movie should be added to this list if and only if: +# The user has not watched it +# At least one of the user's friends has watched +# The "genre" of the movie is the same as the user's most frequent genre +# Return the list of recommended movies +# Create a function named get_rec_from_favorites. This function should... +# take one parameter: user_data +# user_data will have a field "favorites". The value of "favorites" is a list of movie dictionaries +# This represents the user's favorite movies +# Determine a list of recommended movies. A movie should be added to this list if and only if: +# The movie is in the user's "favorites" +# None of the user's friends have watched it +# Return the list of recommended movies + + + + + + + + + From 74b3331079812c80c09e7b4a65e2613be2156c84 Mon Sep 17 00:00:00 2001 From: Jackie Date: Wed, 29 Mar 2023 15:41:37 -0400 Subject: [PATCH 2/8] first wave changes --- viewing_party/party.py | 45 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..b853f0552 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,50 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + #returns None if a parameter is missing + #else creates a dictionary for a movie. Includes three keys: title, genre, and rating + #return movie + + if title == None or genre == None or rating == None: + return None + else: + movie = {"title" : title, + "genre" : genre, + "rating" : rating, + } + + return movie + +def add_to_watched(user_data, movie): + #user_data is a dictionary that contains two key value pairs. The keys are "watched" and "watchlist." The values are lists that contain movies stored as dictionaries. + #movie is a dictionary created with create_movie function + #adds a movie into the list of movies paired with the "watched" key in user_data + #return updated user_data + + user_data["watched"].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + #user_data is a dictionary that contains two key value pairs. The keys are "watched" and "watchlist." The values are lists that contain movies stored as dictionaries. + #movie is a dictionary created with create_movie function + #adds a movie into the list of movies paired with the "watchlist" key in user_data + #return updated user_data + + user_data["watchlist"].append(movie) + return user_data + +def watch_movie(user_data, movie_title): + #user_data is a dictionary that contains two key value pairs. The keys are "watched" and "watchlist." The values are lists that contain movies stored as dictionaries. + #movie_title is the value paired with the "title" key in a movie dictionary created with create_movie function + #moves a movie dictionary with a title of movie_title from watch list in user_data to watched. + #return updated user_data + + for item in user_data["watchlist"]: + if item["title"] == movie_title: + user_data["watched"].append(item) + user_data["watchlist"].remove(item) + + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- From 00f4d0d27223b630a61fe54c08d11f29ba7ce4b7 Mon Sep 17 00:00:00 2001 From: Jackie Date: Wed, 29 Mar 2023 15:43:54 -0400 Subject: [PATCH 3/8] tests --- tests/test_wave_01.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..5a26d8192 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +32,7 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +45,7 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +58,7 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +79,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] == GENRE_1 assert updated_data["watched"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +99,7 @@ def test_adds_movie_to_non_empty_user_watched(): assert movie in updated_data["watched"] assert FANTASY_2 in updated_data["watched"] -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -120,7 +120,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] == GENRE_1 assert updated_data["watchlist"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -140,7 +140,7 @@ def test_adds_movie_to_non_empty_user_watchlist(): assert movie in updated_data["watchlist"] assert FANTASY_2 in updated_data["watchlist"] -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { From c6ed49df5d91721f9f573bdc23ec69d05d03e465 Mon Sep 17 00:00:00 2001 From: Jackie Date: Sun, 2 Apr 2023 19:55:28 -0400 Subject: [PATCH 4/8] second wave commit. Includes a function to get the average rating of movies in the user's watch list and a function to get the user's most watched genre. --- viewing_party/party.py | 48 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index ad859f86d..557bcd85c 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -6,8 +6,9 @@ def create_movie(title, genre, rating): return None else: movie = { "title" : title, - "genre" : genre, - "rating" : rating} + "genre" : genre, + "rating" : rating + } return movie def add_to_watched(user_data, movie): @@ -15,6 +16,7 @@ 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) @@ -35,23 +37,33 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- -# Wave 2 -# Create a function named get_watched_avg_rating. This function should... -# take one parameter: user_data -# the value of user_data will be a dictionary with a "watched" list of movie dictionaries -# This represents that the user has a list of watched movies -# Calculate the average rating of all movies in the watched list -# The average rating of an empty watched list is 0.0 -# return the average rating -# Create a function named get_most_watched_genre. This function should... -# take one parameter: user_data -# the value of user_data will be a dictionary with a "watched" list of movie dictionaries. Each movie dictionary has a key "genre". -# This represents that the user has a list of watched movies. Each watched movie has a genre. -# The values of "genre" is a string. -# Determine which genre is most frequently occurring in the watched list -# return the genre that is the most frequently watched -# If the value of "watched" is an empty list, get_most_watched_genre should return None. +def get_watched_avg_rating(user_data): + rating_list = [] + if not user_data["watched"]: + return 0.0 + for movie in user_data["watched"]: + rating_list.append(movie["rating"]) + average_rating = sum(rating_list) / len(rating_list) + return average_rating + +def get_most_watched_genre(user_data): + if not user_data["watched"]: + return None + + genre_list = [] + for movie in user_data["watched"]: + genre_list.append(movie["genre"]) + + most_watched_genre_frequency = 0 + most_watched_genre = genre_list[0] + for genre in genre_list: + genre_frequency = genre_list.count(genre) + if genre_frequency > most_watched_genre_frequency: + most_watched_genre_frequency = genre_frequency + most_watched_genre = genre + + return most_watched_genre # ----------------------------------------- # ------------- WAVE 3 -------------------- From c0ba72777af55f7c5ea075cbbf8984a40ea63ba3 Mon Sep 17 00:00:00 2001 From: Jackie Date: Sun, 2 Apr 2023 21:16:58 -0400 Subject: [PATCH 5/8] third wave commit. Includes a function get_unique_watched_movies that returns a list of the movies the user has watched that their friends haven't watched. Includes a function get_friends_unique_movies that returns a list of movies the user's friends have watched that they haven't watched. test_wave_03 updated. test_friends_unique_movies_not_duplicated also tests to make sure the correct movies are returned from get_friends_unique_watched. --- tests/test_wave_03.py | 5 +-- viewing_party/party.py | 69 +++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 8b3d1a203..15b10c251 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -54,11 +54,12 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 - - raise Exception("Test needs to be completed.") # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** + assert INTRIGUE_3 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies # @pytest.mark.skip() def test_friends_not_unique_movies(): diff --git a/viewing_party/party.py b/viewing_party/party.py index 557bcd85c..9e47a4f17 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -69,24 +69,57 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -# Create a function named get_unique_watched. This function should... -# take one parameter: user_data -# the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" -# This represents that the user has a list of watched movies and a list of friends -# The value of "friends" is a list -# Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. -# Each movie dictionary has a "title". -# Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies the user has watched, but none of their friends have watched. -# Return a list of dictionaries, that represents a list of movies -# Create a function named get_friends_unique_watched. This function should... -# take one parameter: user_data -# the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" -# This represents that the user has a list of watched movies and a list of friends -# The value of "friends" is a list -# Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. -# Each movie dictionary has a "title". -# Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies at least one of the user's friends have watched, but the user has not watched. -# Return a list of dictionaries, that represents a list of movies +def get_unique_watched(user_data): + + user_watched_titles =[] + for movie in user_data["watched"]: + user_watched_titles.append(movie["title"]) + + friends_watched_titles = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] not in friends_watched_titles: + friends_watched_titles.append(movie["title"]) + + user_unique_titles = [] + for title in user_watched_titles: + if title not in friends_watched_titles: + user_unique_titles.append(title) + + user_unique_movies = [] + for title in user_unique_titles: + for movie in user_data["watched"]: + if movie["title"] == title: + user_unique_movies.append(movie) + + return user_unique_movies + + +def get_friends_unique_watched(user_data): + + user_watched_titles =[] + for movie in user_data["watched"]: + user_watched_titles.append(movie["title"]) + + friends_watched_titles = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] not in friends_watched_titles: + friends_watched_titles.append(movie["title"]) + + friends_unique_titles = [] + for title in friends_watched_titles: + if title not in user_watched_titles: + friends_unique_titles.append(title) + + friends_unique_movies = [] + for title in friends_unique_titles: + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] == title and movie not in friends_unique_movies: + friends_unique_movies.append(movie) + + return friends_unique_movies # ----------------------------------------- From da8ef9c9a003113f7fad78058ca4a24f8858212f Mon Sep 17 00:00:00 2001 From: Jackie Date: Sun, 2 Apr 2023 21:41:06 -0400 Subject: [PATCH 6/8] wave 4 commit. Includes a function, get_available_recs that returns recommended movies from friends watched movies if the user is subscribed to the movie's host and the user hasn't watched the movie yet. --- viewing_party/party.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 9e47a4f17..1b18913b7 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -126,17 +126,16 @@ def get_friends_unique_watched(user_data): # ------------- WAVE 4 -------------------- # ----------------------------------------- -# Wave 4 -# Create a function named get_available_recs. This function should... -# take one parameter: user_data -# user_data will have a field "subscriptions". The value of "subscriptions" is a list of strings -# This represents the names of streaming services that the user has access to -# Each friend in "friends" has a watched list. Each movie in the watched list has a "host", which is a string that says what streaming service it's hosted on -# Determine a list of recommended movies. A movie should be added to this list if and only if: -# The user has not watched it -# At least one of the user's friends has watched -# The "host" of the movie is a service that is in the user's "subscriptions" -# Return the list of recommended movies +def get_available_recs(user_data): + + friends_recommended_movies = get_friends_unique_watched(user_data) + + recommended_movies =[] + for movie in friends_recommended_movies: + if movie["host"] in user_data["subscriptions"]: + recommended_movies.append(movie) + + return recommended_movies # ----------------------------------------- # ------------- WAVE 5 -------------------- From 628dc458c26a23d3c34797ca676c0646eed5a47a Mon Sep 17 00:00:00 2001 From: Jackie Date: Sun, 2 Apr 2023 22:20:09 -0400 Subject: [PATCH 7/8] wave 5 commit. function get_new_rec_by_genre returns a list of movie recommendations for the user if their friends have watched it and the movie genre is the most watched genre by user. the function get_rec_from_favorites returns a list of movies the user recommends if their friends haven't watched it and it is in their favorites list. The test test_new_genre_rec_from_empty_friends is completed. --- tests/test_wave_05.py | 8 ++++++-- viewing_party/party.py | 34 ++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 345423fb7..8419fcccd 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -52,9 +52,13 @@ def test_new_genre_rec_from_empty_friends(): } ] } + #Act + recommendations = get_new_rec_by_genre(sonyas_data) - - raise Exception("Test needs to be completed.") + #Assert + assert len(recommendations) == 0 + assert not recommendations + assert recommendations == [] # ********************************************************************* # ****** Complete the Act and Assert Portions of these tests ********** diff --git a/viewing_party/party.py b/viewing_party/party.py index 1b18913b7..84c29efae 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -141,14 +141,18 @@ def get_available_recs(user_data): # ------------- WAVE 5 -------------------- # ----------------------------------------- -# Wave 5 -# Create a function named get_new_rec_by_genre. This function should... -# take one parameter: user_data -# Consider the user's most frequently watched genre. Then, determine a list of recommended movies. A movie should be added to this list if and only if: -# The user has not watched it -# At least one of the user's friends has watched -# The "genre" of the movie is the same as the user's most frequent genre -# Return the list of recommended movies +def get_new_rec_by_genre(user_data): + + most_watched_genre = get_most_watched_genre(user_data) + friends_recommended_movies = get_friends_unique_watched(user_data) + + recommended_movies_by_genre = [] + for movie in friends_recommended_movies: + if movie["genre"] == most_watched_genre: + recommended_movies_by_genre.append(movie) + + return recommended_movies_by_genre + # Create a function named get_rec_from_favorites. This function should... # take one parameter: user_data # user_data will have a field "favorites". The value of "favorites" is a list of movie dictionaries @@ -157,6 +161,20 @@ def get_available_recs(user_data): # The movie is in the user's "favorites" # None of the user's friends have watched it # Return the list of recommended movies +def get_rec_from_favorites(user_data): + pass + user_recommended_movies = [] + user_unique_movies = get_unique_watched(user_data) + # for movie in user_data["favorites"]: + # for friend in user_data["friends"]: + # if movie not in friend["watched"] and movie not in user_recommended_movies: + # user_recommended_movies.append(movie) + for movie in user_data["favorites"]: + if movie in user_unique_movies: + user_recommended_movies.append(movie) + return user_recommended_movies + + From bdfad1e963b4ffc43e5d04754e72f6cea78c49f6 Mon Sep 17 00:00:00 2001 From: Jackie Date: Sun, 2 Apr 2023 22:25:31 -0400 Subject: [PATCH 8/8] comments removed from wave 5 --- viewing_party/party.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 84c29efae..c80eacb1d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -153,22 +153,12 @@ def get_new_rec_by_genre(user_data): return recommended_movies_by_genre -# Create a function named get_rec_from_favorites. This function should... -# take one parameter: user_data -# user_data will have a field "favorites". The value of "favorites" is a list of movie dictionaries -# This represents the user's favorite movies -# Determine a list of recommended movies. A movie should be added to this list if and only if: -# The movie is in the user's "favorites" -# None of the user's friends have watched it -# Return the list of recommended movies + def get_rec_from_favorites(user_data): - pass + user_recommended_movies = [] user_unique_movies = get_unique_watched(user_data) - # for movie in user_data["favorites"]: - # for friend in user_data["friends"]: - # if movie not in friend["watched"] and movie not in user_recommended_movies: - # user_recommended_movies.append(movie) + for movie in user_data["favorites"]: if movie in user_unique_movies: user_recommended_movies.append(movie)