From 5dfba98a0c1dcc7a2cbaa401d496f0b2affdb47b Mon Sep 17 00:00:00 2001 From: Tamika Ross Date: Mon, 24 Mar 2025 13:10:08 -0500 Subject: [PATCH 01/15] added comments to the first function --- tests/test_wave_01.py | 2 +- viewing_party/party.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..d8e3f5d9f 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() + def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..86dfbd524 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,17 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + # Check if all parameters are truthy (not empty, not None, etc.) + if title and genre and rating: + # Return a dictionary with the movie details + return { + "title": title, + "genre": genre, + "rating": rating + } + else: + # Return None if any of the parameters are missing or falsy + return None # ----------------------------------------- # ------------- WAVE 2 -------------------- From 53cecf7387ddd616a52affc558a3589cb7753cdb Mon Sep 17 00:00:00 2001 From: collette7 Date: Mon, 24 Mar 2025 21:36:05 -0500 Subject: [PATCH 02/15] Add function for handling "watched" movie status --- tests/test_wave_01.py | 8 ++------ viewing_party/party.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index d8e3f5d9f..5e5bf9678 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -19,7 +19,6 @@ def test_create_successful_movie(): assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +31,6 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +43,6 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +55,6 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +75,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() + def test_adds_movie_to_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +95,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() + def test_adds_movie_to_user_watchlist(): # Arrange movie = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 86dfbd524..88b085163 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -13,6 +13,16 @@ def create_movie(title, genre, rating): # Return None if any of the parameters are missing or falsy return None +def add_to_watched(user_data, movie): + # Create a duplicate of user data + updated_data = user_data.copy() + + # Append the movie to the user's watched list + updated_data["watched"].append(movie) + + # Return the updated user data + return updated_data + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- From ee3419839d41cce8a23c7c14f642489c8408f3d6 Mon Sep 17 00:00:00 2001 From: Tamika Ross Date: Tue, 25 Mar 2025 15:30:00 -0500 Subject: [PATCH 03/15] updating wave 2 --- tests/test_wave_02.py | 10 +++++----- viewing_party/party.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 19f045c79..a0b21ee63 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() + 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() + 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() + 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() + 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() + def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 88b085163..1a61fd2c2 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -26,7 +26,17 @@ def add_to_watched(user_data, movie): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- - +def uses_available_letters(word, letter_bank): + #make a list to count how many times each letter appears in the letter bank + letter_counts = {} + #count each letter in the bank + for letter in letter_bank: + if letter in letter_counts: + #increase letter counts by 1 + letter_counts[letter] += 1 + else: + #else set it equal to 1 + letter_counts[letter] = 1 # ----------------------------------------- # ------------- WAVE 3 -------------------- From 199018737d812347ec7ffcfdb5669340e0051af0 Mon Sep 17 00:00:00 2001 From: collette7 Date: Tue, 25 Mar 2025 15:39:42 -0500 Subject: [PATCH 04/15] add psudeo code for handling watchlist additions --- viewing_party/party.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/viewing_party/party.py b/viewing_party/party.py index 1a61fd2c2..585e0cefa 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -23,6 +23,16 @@ def add_to_watched(user_data, movie): # Return the updated user data return updated_data +def add_to_watchlist(user_data, movie): + # Create a duplicate of user data + + # Add movie to the user watchlist + + # Return user data + pass + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- From fd3a2194c74af9f8e32610a880598ec8b8632d38 Mon Sep 17 00:00:00 2001 From: collette7 Date: Tue, 25 Mar 2025 15:49:12 -0500 Subject: [PATCH 05/15] Handle adding movies to watchlist --- viewing_party/party.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 585e0cefa..8c17dfc49 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -16,20 +16,19 @@ def create_movie(title, genre, rating): def add_to_watched(user_data, movie): # Create a duplicate of user data updated_data = user_data.copy() - # Append the movie to the user's watched list updated_data["watched"].append(movie) - # Return the updated user data return updated_data def add_to_watchlist(user_data, movie): # Create a duplicate of user data - + updated_data = user_data.copy() # Add movie to the user watchlist - + updated_data["watchlist"].append(movie) # Return user data - pass + return updated_data + From 768edcbd511095f8f94507a43bb3e71550556930 Mon Sep 17 00:00:00 2001 From: collette7 Date: Tue, 25 Mar 2025 15:49:43 -0500 Subject: [PATCH 06/15] Remove all pytest.skip --- tests/test_wave_01.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 5e5bf9678..88cdbc4da 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -116,7 +116,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() + def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -136,7 +136,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() + def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -160,7 +160,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() + def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -184,7 +184,7 @@ def test_moves_movie_from_watchlist_to_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() + def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 From 31f1e9529b1e2d80b00c49f595d29d01f1670f59 Mon Sep 17 00:00:00 2001 From: collette7 Date: Tue, 25 Mar 2025 15:49:43 -0500 Subject: [PATCH 07/15] Remove all pytest.skip from wave 1 --- tests/test_wave_01.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 5e5bf9678..88cdbc4da 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -116,7 +116,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() + def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -136,7 +136,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() + def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -160,7 +160,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() + def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -184,7 +184,7 @@ def test_moves_movie_from_watchlist_to_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() + def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 From 4656fb233472c0fd6a686ed5bb433422e78abdbf Mon Sep 17 00:00:00 2001 From: collette7 Date: Wed, 26 Mar 2025 16:27:34 -0500 Subject: [PATCH 08/15] complete assertions in watchlist tests --- tests/test_wave_01.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 88cdbc4da..429b687ed 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -154,11 +154,9 @@ 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.") - # ******************************************************************************************* - # ****** Add assertions here to test that the correct movie was added to "watched" ********** - # ******************************************************************************************* + 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 def test_moves_movie_from_watchlist_to_watched(): @@ -178,11 +176,9 @@ 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.") - # ******************************************************************************************* - # ****** Add assertions here to test that the correct movie was added to "watched" ********** - # ******************************************************************************************* + assert movie_to_watch in updated_data["watched"] + assert FANTASY_2 in updated_data["watched"] + assert FANTASY_1 in updated_data["watchlist"] def test_does_nothing_if_movie_not_in_watchlist(): From 26d5abad7c25d2cb5162c95d61ae24fc6238c574 Mon Sep 17 00:00:00 2001 From: collette7 Date: Wed, 26 Mar 2025 16:40:38 -0500 Subject: [PATCH 09/15] psuedo code for handeling moving movies from watchlist to watch --- viewing_party/party.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 8c17dfc49..0f2a8b7b2 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -30,7 +30,12 @@ def add_to_watchlist(user_data, movie): return updated_data - +def watch_movie(user_data, movie): + # Create a duplicate of user data + # Find movies in watchlist and change status to watched + # update watchlist with removed movie + # Return user data + pass # ----------------------------------------- # ------------- WAVE 2 -------------------- From e04c85b3b20d76391615f51b4471bd3698e4766e Mon Sep 17 00:00:00 2001 From: Tamika Ross Date: Wed, 26 Mar 2025 16:44:23 -0500 Subject: [PATCH 10/15] completed wave 2 --- viewing_party/party.py | 56 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 8c17dfc49..861a13333 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -35,17 +35,53 @@ def add_to_watchlist(user_data, movie): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- -def uses_available_letters(word, letter_bank): - #make a list to count how many times each letter appears in the letter bank - letter_counts = {} - #count each letter in the bank - for letter in letter_bank: - if letter in letter_counts: - #increase letter counts by 1 - letter_counts[letter] += 1 + +def get_watched_avg_rating(user_data): + # Grab the list of watched movies + watched = user_data["watched"] + + # If they haven't watched any movies, return 0.0 + if len(watched) == 0: + return 0.0 + + # Add up all the ratings + total_rating = 0 + for movie in watched: + total_rating += movie["rating"] + + # Divide the total rating by how many movies they watched + average = total_rating / len(watched) + return average + +def get_most_watched_genre(user_data): + # grab list of most watched genre + watched = user_data["watched"] + if len(watched) == 0: + return None + #track how many times each genre comes up + genre_counts = {} + #go through each move in the list + for movie in watched: + genre = movie["genre"] + #if the movie is already in dict add 1 + if genre in genre_counts: + genre_counts[genre] += 1 + # if not in dict start at 1 else: - #else set it equal to 1 - letter_counts[letter] = 1 + genre_counts[genre] = 1 + #store genre we see the most + most_watched = None + highest_count = 0 +#look through all genres we counted + for genre in genre_counts: + #if the genre's count is bigger than what is current + if genre_counts[genre] > highest_count: + #update the most watched genre + most_watched = genre + #update its count + highest_count = genre_counts[genre] + + return most_watched # ----------------------------------------- # ------------- WAVE 3 -------------------- From 3f5dd70cbc8a94000c1bc71022b2dad005ec887b Mon Sep 17 00:00:00 2001 From: collette7 Date: Thu, 27 Mar 2025 15:14:16 -0500 Subject: [PATCH 11/15] handle movie being moved from watchlist to watched --- viewing_party/party.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 533aeb075..278481e73 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -30,12 +30,26 @@ def add_to_watchlist(user_data, movie): return updated_data -def watch_movie(user_data, movie): +def watch_movie(user_data, movie_title): # Create a duplicate of user data - # Find movies in watchlist and change status to watched - # update watchlist with removed movie - # Return user data - pass + updated_data = user_data.copy() + + # Find movie in watchlist by title + movie_to_watch = None + for movie in updated_data["watchlist"]: + if movie["title"] == movie_title: + movie_to_watch = movie + break + + # If movie found in watchlist, move it to watched + if movie_to_watch: + # Remove movie from watchlist + updated_data["watchlist"].remove(movie_to_watch) + # Add movie to watched + updated_data["watched"].append(movie_to_watch) + + # Return updated user data + return updated_data # ----------------------------------------- # ------------- WAVE 2 -------------------- From eb1d112427b9804c53fc43f472a9b6b05ff8cff3 Mon Sep 17 00:00:00 2001 From: collette7 Date: Thu, 27 Mar 2025 15:46:49 -0500 Subject: [PATCH 12/15] remove test skip --- tests/test_wave_04.py | 3 --- viewing_party/party.py | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..8431f3078 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() @@ -16,7 +15,6 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { @@ -38,7 +36,6 @@ def test_no_available_friend_recs(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() def test_no_available_friend_recs_watched_all(): # Arrange amandas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 278481e73..f8bbc759d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -34,7 +34,7 @@ def watch_movie(user_data, movie_title): # Create a duplicate of user data updated_data = user_data.copy() - # Find movie in watchlist by title + # Find movie in watchlist movie_to_watch = None for movie in updated_data["watchlist"]: if movie["title"] == movie_title: @@ -46,9 +46,9 @@ def watch_movie(user_data, movie_title): # Remove movie from watchlist updated_data["watchlist"].remove(movie_to_watch) # Add movie to watched - updated_data["watched"].append(movie_to_watch) + updated_data["watched"].end(movie_to_watch) - # Return updated user data + # Return user data return updated_data # ----------------------------------------- From 7815cd5974010c697d8ed2611ad82398df5b0c25 Mon Sep 17 00:00:00 2001 From: Tamika Ross Date: Thu, 27 Mar 2025 17:04:21 -0500 Subject: [PATCH 13/15] completed wave 3 --- tests/test_wave_03.py | 19 ++++++++++------- viewing_party/party.py | 46 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..a3c88c491 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() + 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() + 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() + def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,24 +43,29 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() + def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() - amandas_data["friends"][0]["watched"].append(INTRIGUE_3) + amandas_data["friends"][0]["watched"].append(INTRIGUE_3) # Act friends_unique_movies = get_friends_unique_watched(amandas_data) + print("\nFriends Unique Movies:") + for movie in friends_unique_movies: + print(movie) + # Assert assert len(friends_unique_movies) == 3 + assert FANTASY_4 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies - raise Exception("Test needs to be completed.") # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** -@pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index f8bbc759d..6388be972 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -105,8 +105,52 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + # Get the user's watched list + user_watched = user_data["watched"] + + # Create a list to hold all the movie titles friends have watched + friends_titles = [] + + # Go through each friend + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] not in friends_titles: + friends_titles.append(movie["title"]) + + # Create a list for movies that only the user has watched + unique_to_user = [] + + for movie in user_watched: + if movie["title"] not in friends_titles: + unique_to_user.append(movie) + + return unique_to_user + + + + +def get_friends_unique_watched(user_data): + user_watched = user_data["watched"] + friends_unique_movies = [] + + # Get titles of movies the user has already watched + user_titles = [movie["title"] for movie in user_watched] + + # Go through each friend + for friend in user_data["friends"]: + for movie in friend["watched"]: + # Only add if the movie's title is not in the user's watched list + # and it's not already in our result list + if ( + movie["title"] not in user_titles + and movie not in friends_unique_movies + ): + friends_unique_movies.append(movie) + + return friends_unique_movies + - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From 51d44c454940c4f2d43db8e99433bbb0542d9768 Mon Sep 17 00:00:00 2001 From: collette7 Date: Thu, 27 Mar 2025 17:34:02 -0500 Subject: [PATCH 14/15] add case for checking friends watched,user subs, and users current recs if no conficts add movie to rec --- viewing_party/party.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6388be972..f02691727 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -46,7 +46,7 @@ def watch_movie(user_data, movie_title): # Remove movie from watchlist updated_data["watchlist"].remove(movie_to_watch) # Add movie to watched - updated_data["watched"].end(movie_to_watch) + updated_data["watched"].append(movie_to_watch) # Return user data return updated_data @@ -151,10 +151,27 @@ def get_friends_unique_watched(user_data): return friends_unique_movies + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + recommendations = [] + user_watched = user_data["watched"] + user_subscriptions = user_data["subscriptions"] + + # check friends watched, subs, and current recs if no conficts add movie + for friend in user_data["friends"]: + for movie in friend["watched"]: + if (movie not in user_watched and + movie["host"] in user_subscriptions and + movie not in recommendations): + recommendations.append(movie) + + return recommendations + + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- From e71f19fabbc2d8cb6a59341e4e8b51dcfd612127 Mon Sep 17 00:00:00 2001 From: Tamika Ross Date: Fri, 28 Mar 2025 04:43:57 -0500 Subject: [PATCH 15/15] completed wave 5 --- tests/test_wave_05.py | 20 ++++++------- viewing_party/party.py | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..99fc99549 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() + 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() + 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() + def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -52,13 +52,13 @@ def test_new_genre_rec_from_empty_friends(): } ] } + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + + # Assert + assert recommendations == [] - raise Exception("Test needs to be completed.") - # ********************************************************************* - # ****** Complete the Act and Assert Portions of these tests ********** - # ********************************************************************* -@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -72,7 +72,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() + def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -94,7 +94,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@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 f02691727..812ce6d5e 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -175,4 +175,70 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + # Count how many times the user has watched each genre + genre_count = {} + + for movie in user_data["watched"]: + genre = movie["genre"] + if genre in genre_count: + genre_count[genre] = genre_count[genre] + 1 + else: + genre_count[genre] = 1 + + # If the user hasn't watched anything, there's nothing to base recs on + if genre_count == {}: + return [] + + # Find the genre the user watches the most + most_genre = None + max_count = 0 + + for genre in genre_count: + if genre_count[genre] > max_count: + most_genre = genre + max_count = genre_count[genre] + + # Store all titles the user has watched to avoid recommending them again + user_titles = [] + for movie in user_data["watched"]: + user_titles.append(movie["title"]) + + # Build recommendations list + recs = [] + rec_titles = [] # Keep track of what we've already added + + for friend in user_data["friends"]: + for movie in friend["watched"]: + title = movie["title"] + genre = movie["genre"] + + # Recommend only if it's the favorite genre, not watched, and not already in recs + if title not in user_titles and genre == most_genre and title not in rec_titles: + recs.append(movie) + rec_titles.append(title) + + return recs + + +def get_rec_from_favorites(user_data): + # Gather all the movie titles that friends have watched + friends_titles = [] + + for friend in user_data["friends"]: + for movie in friend["watched"]: + title = movie["title"] + if title not in friends_titles: + friends_titles.append(title) + + # Recommend favorites only if none of the friends have watched them + recs = [] + + if "favorites" in user_data: + for movie in user_data["favorites"]: + title = movie["title"] + if title not in friends_titles: + recs.append(movie) + + return recs