diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..429b687ed 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 @@ -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 = { @@ -120,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 = { @@ -140,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 = { @@ -158,13 +154,11 @@ 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 + -@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -182,13 +176,11 @@ 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"] + -@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..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/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/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/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 6d34a6b5f..812ce6d5e 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,244 @@ # ------------- 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 + +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 + return updated_data + + +def watch_movie(user_data, movie_title): + # Create a duplicate of user data + updated_data = user_data.copy() + + # Find movie in watchlist + 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 user data + return updated_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +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: + 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 -------------------- # ----------------------------------------- +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 -------------------- # ----------------------------------------- +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 -------------------- # ----------------------------------------- +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