From c3178c9aa2fbc4786fe3b9f7661550a61d3ceed2 Mon Sep 17 00:00:00 2001 From: izzycommits Date: Mon, 23 Sep 2024 14:48:47 -0400 Subject: [PATCH 01/11] add create_movie and add_to_watched functions and pass associated tests --- tests/test_wave_01.py | 13 +++++++------ viewing_party/party.py | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..e1fcf8c83 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,13 +4,13 @@ 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 genre = GENRE_1 rating = RATING_1 - + # Act new_movie = create_movie(movie_title, genre, rating) @@ -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,12 +32,13 @@ 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" genre = None rating = 3.5 + # Act new_movie = create_movie(movie_title, genre, rating) @@ -45,7 +46,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 +59,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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..57d5eb3a0 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,22 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + if not title or not genre or not rating: + return None + new_movie = { + "title": title, + "genre": genre, + "rating": rating + } + return new_movie + +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + + # for data in user_data.keys(): + # user_data[data].append(movie) + + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- From 0fc3206c0f1ccca1c1c9e3a3cf622e36daac9246 Mon Sep 17 00:00:00 2001 From: izzycommits Date: Mon, 23 Sep 2024 16:11:12 -0400 Subject: [PATCH 02/11] start watch_movie --- tests/test_wave_01.py | 8 ++++---- viewing_party/party.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index e1fcf8c83..269dcf7b4 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -80,7 +80,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 = { @@ -100,7 +100,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 = { @@ -121,7 +121,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 = { @@ -141,7 +141,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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 57d5eb3a0..991fdc52a 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,3 +1,4 @@ +import copy # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): @@ -18,6 +19,51 @@ def add_to_watched(user_data, movie): return user_data +def add_to_watchlist(user_data, movie): + user_data["watchlist"].append(movie) + + # for data in user_data.keys(): + # user_data[data].append(movie) + + return user_data + +def watch_movie(user_data, title): + temp_user_data = copy.deepcopy(user_data) + watch_list = temp_user_data["watchlist"] + watched = temp_user_data["watched"] + + # for i in range(0, len(watch_list)): + # watch_list_title = watch_list[i]["title"] + # # if watch_list_title == title: + # removed_movie = watch_list[i].remove() + # print("rm", removed_movie) + + + + # return + + #watched_movie = user_data["watchlist"] + # loop through list /access key to compare title + #remove watched_movie.pop() + #append to user + + +janes_data = { + "watchlist": [{ + "title": "MOVIE_TITLE_1", + "genre": "GENRE_1", + "rating": "RATING_1" + },{ + "title": "MOVIE_TITLE_2", + "genre": "GENRE_1", + "rating": "RATING_1" + }], + + "watched": [] +} + +updated_data = watch_movie(janes_data, "MOVIE_TITLE_1") + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- From 952224e2d23f78f6610f35273443689f04ed5d37 Mon Sep 17 00:00:00 2001 From: nelasunitha <80846358+nelasunitha@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:37:26 -0700 Subject: [PATCH 03/11] Implementing add_to_watchlist function --- tests/test_wave_01.py | 8 ++--- viewing_party/party.py | 76 ++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 269dcf7b4..ef94ee39d 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -10,7 +10,7 @@ def test_create_successful_movie(): movie_title = MOVIE_TITLE_1 genre = GENRE_1 rating = RATING_1 - + # Act new_movie = create_movie(movie_title, genre, rating) @@ -38,7 +38,7 @@ def test_create_no_genre_movie(): movie_title = "Title A" genre = None rating = 3.5 - + # Act new_movie = create_movie(movie_title, genre, rating) @@ -159,7 +159,7 @@ 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" ********** @@ -183,7 +183,7 @@ 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" ********** diff --git a/viewing_party/party.py b/viewing_party/party.py index 991fdc52a..e9dfd9635 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -2,67 +2,64 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - if not title or not genre or not rating: + if not title or not genre or not rating: return None new_movie = { "title": title, "genre": genre, "rating": rating - } + } return new_movie -def add_to_watched(user_data, movie): +def add_to_watched(user_data, movie): user_data["watched"].append(movie) - # for data in user_data.keys(): + # for data in user_data.keys(): # user_data[data].append(movie) return user_data -def add_to_watchlist(user_data, movie): +def add_to_watchlist(user_data, movie): user_data["watchlist"].append(movie) - # for data in user_data.keys(): + # for data in user_data.keys(): # user_data[data].append(movie) return user_data -def watch_movie(user_data, title): +def watch_movie(user_data, title): temp_user_data = copy.deepcopy(user_data) watch_list = temp_user_data["watchlist"] watched = temp_user_data["watched"] + test = False - # for i in range(0, len(watch_list)): - # watch_list_title = watch_list[i]["title"] - # # if watch_list_title == title: - # removed_movie = watch_list[i].remove() - # print("rm", removed_movie) - - - - # return - - #watched_movie = user_data["watchlist"] - # loop through list /access key to compare title - #remove watched_movie.pop() - #append to user - - -janes_data = { - "watchlist": [{ - "title": "MOVIE_TITLE_1", - "genre": "GENRE_1", - "rating": "RATING_1" - },{ - "title": "MOVIE_TITLE_2", - "genre": "GENRE_1", - "rating": "RATING_1" - }], - - "watched": [] -} - -updated_data = watch_movie(janes_data, "MOVIE_TITLE_1") + for i in range(0, len(user_data["watchlist"])): + watch_list_title = watch_list[i]["title"] + if watch_list_title == title: + watched.append(watch_list[i]) + test = i + + if test: + del watch_list[test] + + return temp_user_data + + +# janes_data = { +# "watchlist": [{ +# "title": "MOVIE_TITLE_1", +# "genre": "GENRE_1", +# "rating": "RATING_1" +# },{ +# "title": "MOVIE_TITLE_2", +# "genre": "GENRE_1", +# "rating": "RATING_1" +# }], + +# "watched": [] +# } + +# updated_data = watch_movie(janes_data, "MOVIE_TITLE_1") # ----------------------------------------- # ------------- WAVE 2 -------------------- @@ -73,7 +70,7 @@ def watch_movie(user_data, title): # ------------- WAVE 3 -------------------- # ----------------------------------------- - + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- @@ -81,4 +78,3 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- - From 7c42bbe38e4e12bbc1e0f76d9c13dc17d07e8b71 Mon Sep 17 00:00:00 2001 From: nelasunitha <80846358+nelasunitha@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:21:31 -0700 Subject: [PATCH 04/11] completed wave 1 --- viewing_party/party.py | 69 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index e9dfd9635..447a030f6 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -27,39 +27,44 @@ def add_to_watchlist(user_data, movie): return user_data + def watch_movie(user_data, title): - temp_user_data = copy.deepcopy(user_data) - watch_list = temp_user_data["watchlist"] - watched = temp_user_data["watched"] - test = False - - for i in range(0, len(user_data["watchlist"])): - watch_list_title = watch_list[i]["title"] - if watch_list_title == title: - watched.append(watch_list[i]) - test = i - - if test: - del watch_list[test] - - return temp_user_data - - -# janes_data = { -# "watchlist": [{ -# "title": "MOVIE_TITLE_1", -# "genre": "GENRE_1", -# "rating": "RATING_1" -# },{ -# "title": "MOVIE_TITLE_2", -# "genre": "GENRE_1", -# "rating": "RATING_1" -# }], - -# "watched": [] -# } - -# updated_data = watch_movie(janes_data, "MOVIE_TITLE_1") + + watch_list = user_data["watchlist"] + watched = user_data["watched"] + + for movie in watch_list: + if isinstance(movie, list): + #add Horror_1 "watched" + #remove movie_to_watch "watchlist" + if title in movie: + watched.append(title) + watch_list.remove(title) + + elif isinstance(movie, dict): + if movie["title"] == title: + watched.append(movie) + watch_list.remove(movie) + break + print(user_data) + return user_data + + +HORROR_1 = { + "title": "MOVIE_TITLE_1", + "genre": "GENRE_1", + "rating": "RATING_1" +} +movie_to_watch = HORROR_1 +janes_data = { + "watchlist": [ + "FANTASY_1", + movie_to_watch + ], + "watched": ["FANTASY_2"] + } + +updated_data = watch_movie(janes_data, movie_to_watch["title"]) # ----------------------------------------- # ------------- WAVE 2 -------------------- From 254a30803655963076e602b1037d10204da94cc1 Mon Sep 17 00:00:00 2001 From: nelasunitha <80846358+nelasunitha@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:06:22 -0700 Subject: [PATCH 05/11] completed wave 1 --- tests/test_wave_01.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ef94ee39d..f41325b9b 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -152,6 +152,14 @@ def test_moves_movie_from_watchlist_to_empty_watched(): }], "watched": [] } + expected_result = { + "watchlist": [], + "watched": [{ + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 + }] + } # Act updated_data = watch_movie(janes_data, MOVIE_TITLE_1) @@ -159,13 +167,14 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 + assert updated_data == expected_result - raise Exception("Test needs to be completed.") + # 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 @@ -176,6 +185,13 @@ def test_moves_movie_from_watchlist_to_watched(): ], "watched": [FANTASY_2] } + expected_result = { + "watchlist": [ + FANTASY_1 + + ], + "watched": [FANTASY_2, movie_to_watch] + } # Act updated_data = watch_movie(janes_data, movie_to_watch["title"]) @@ -183,13 +199,14 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 + assert updated_data == expected_result - raise Exception("Test needs to be completed.") + # 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 From 4fa9dd5dbe1e0ae18b02b40bfb34d41e7831e169 Mon Sep 17 00:00:00 2001 From: izzycommits Date: Tue, 24 Sep 2024 23:39:10 -0400 Subject: [PATCH 06/11] pass test wave 2 --- tests/test_wave_02.py | 10 +++++----- viewing_party/party.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) 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/viewing_party/party.py b/viewing_party/party.py index 447a030f6..1bd3a0292 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -69,7 +69,35 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- - +def get_watched_avg_rating(user_data): + if not len(user_data["watched"]): + return 0.0 + sum = 0 + for movie in user_data["watched"]: + sum += movie["rating"] + + average = sum / len(user_data["watched"]) + return average + +def get_most_watched_genre(user_data): + if not user_data: + return None + + genres = {} + for movie in user_data["watched"]: + movie_genre = movie["genre"] + count = genres.get(movie_genre, 0) + genres[movie_genre] = count + 1 + + entry = None + max_number_of_occurences = 0 + + for genre, count in genres.items(): + if count > max_number_of_occurences: + entry = genre + max_number_of_occurences = count + + return entry # ----------------------------------------- # ------------- WAVE 3 -------------------- From 99a4d0fff2b14c9a176793145a9a40cfbf52e8d5 Mon Sep 17 00:00:00 2001 From: izzycommits Date: Wed, 25 Sep 2024 01:27:48 -0400 Subject: [PATCH 07/11] pass test wave 3 --- tests/test_wave_03.py | 25 ++++++++++++++++++------- viewing_party/party.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..73cceb1e7 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,24 +43,35 @@ 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() amandas_data["friends"][0]["watched"].append(INTRIGUE_3) - + # Act friends_unique_movies = get_friends_unique_watched(amandas_data) + + INTRIGUE_3_count = 0 + for movie in friends_unique_movies: + if movie == INTRIGUE_3: + INTRIGUE_3_count += 1 + # Assert assert len(friends_unique_movies) == 3 + assert HORROR_1 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies + assert INTRIGUE_3_count == 1 + - raise Exception("Test needs to be completed.") + # 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/viewing_party/party.py b/viewing_party/party.py index 1bd3a0292..29f55172f 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -102,7 +102,38 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + friend_movie = [] + for friend_list in user_data["friends"]: + for movie in friend_list["watched"]: + if movie not in friend_movie: + friend_movie.append(movie) + + unique_user_movie = [] + + for movie in user_data["watched"]: + if movie not in friend_movie: + unique_user_movie.append(movie) + return unique_user_movie + + +def get_friends_unique_watched(user_data): + unique_user_movie = [] + + for movie in user_data["watched"]: + if movie not in unique_user_movie: + unique_user_movie.append(movie) + + friend_unique_movie = [] + + for friend_list in user_data["friends"]: + for movie in friend_list["watched"]: + if movie not in unique_user_movie: + if movie not in friend_unique_movie: + friend_unique_movie.append(movie) + + return friend_unique_movie # ----------------------------------------- # ------------- WAVE 4 -------------------- From 2e464375b6bcb8d8845de8c0f0f19b80ef91f13d Mon Sep 17 00:00:00 2001 From: izzycommits Date: Wed, 25 Sep 2024 17:44:14 -0400 Subject: [PATCH 08/11] pass test wave 5 --- tests/test_wave_04.py | 6 +++--- viewing_party/party.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) 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/viewing_party/party.py b/viewing_party/party.py index 29f55172f..e6044abba 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -138,7 +138,17 @@ def get_friends_unique_watched(user_data): # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- - +# user has not watched +# one friend has watched +# host should be in user subscription + +def get_available_recs(user_data): + friend_unique_movie = get_friends_unique_watched(user_data) + rec_movies = [] + for movie in friend_unique_movie: + if movie["host"] in user_data["subscriptions"]: + rec_movies.append(movie) + return rec_movies # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- From 379ff23955b51495a3f2e0e964a7bbc42ea46d3d Mon Sep 17 00:00:00 2001 From: izzycommits Date: Wed, 25 Sep 2024 18:54:52 -0400 Subject: [PATCH 09/11] pass test wave 5 --- tests/test_wave_05.py | 22 +++++++++++++++------- viewing_party/party.py | 25 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..e9c0ab57e 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 = { @@ -52,13 +52,21 @@ def test_new_genre_rec_from_empty_friends(): } ] } + expected_result = [] + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + + # Assert + assert not recommendations + assert len(recommendations) == 0 + - raise Exception("Test needs to be completed.") + # 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 +80,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 +102,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 e6044abba..cbf5e0221 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -46,7 +46,6 @@ def watch_movie(user_data, title): watched.append(movie) watch_list.remove(movie) break - print(user_data) return user_data @@ -152,3 +151,27 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- + + +def get_new_rec_by_genre(user_data): + rec_movies = [] + most_watched_genre = get_most_watched_genre(user_data) + friend_unique_movie = get_friends_unique_watched(user_data) + + for movie in friend_unique_movie: + if most_watched_genre == movie["genre"]: + rec_movies.append(movie) + + return rec_movies + + +def get_rec_from_favorites(user_data): + unique_watched_movie = get_unique_watched(user_data) + rec_movies = [] + for user_movie in unique_watched_movie: + for fav_movie in user_data["favorites"]: + if user_movie["title"] == fav_movie["title"]: + rec_movies.append(user_movie) + + return rec_movies + From ab41f017f15f306faac998187bfca741df3355a4 Mon Sep 17 00:00:00 2001 From: nelasunitha <80846358+nelasunitha@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:10:19 -0700 Subject: [PATCH 10/11] Completed viewing party --- viewing_party/party.py | 82 +++++++++++++----------------------------- 1 file changed, 25 insertions(+), 57 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index cbf5e0221..a3dbde551 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -14,17 +14,12 @@ def create_movie(title, genre, rating): def add_to_watched(user_data, movie): user_data["watched"].append(movie) - # for data in user_data.keys(): - # user_data[data].append(movie) return user_data def add_to_watchlist(user_data, movie): user_data["watchlist"].append(movie) - # for data in user_data.keys(): - # user_data[data].append(movie) - return user_data @@ -34,36 +29,13 @@ def watch_movie(user_data, title): watched = user_data["watched"] for movie in watch_list: - if isinstance(movie, list): - #add Horror_1 "watched" - #remove movie_to_watch "watchlist" - if title in movie: - watched.append(title) - watch_list.remove(title) - - elif isinstance(movie, dict): - if movie["title"] == title: - watched.append(movie) - watch_list.remove(movie) - break + if movie["title"] == title: + watched.append(movie) + watch_list.remove(movie) + break return user_data -HORROR_1 = { - "title": "MOVIE_TITLE_1", - "genre": "GENRE_1", - "rating": "RATING_1" -} -movie_to_watch = HORROR_1 -janes_data = { - "watchlist": [ - "FANTASY_1", - movie_to_watch - ], - "watched": ["FANTASY_2"] - } - -updated_data = watch_movie(janes_data, movie_to_watch["title"]) # ----------------------------------------- # ------------- WAVE 2 -------------------- @@ -81,13 +53,13 @@ def get_watched_avg_rating(user_data): def get_most_watched_genre(user_data): if not user_data: return None - + genres = {} for movie in user_data["watched"]: movie_genre = movie["genre"] count = genres.get(movie_genre, 0) genres[movie_genre] = count + 1 - + entry = None max_number_of_occurences = 0 @@ -107,13 +79,13 @@ def get_unique_watched(user_data): for friend_list in user_data["friends"]: for movie in friend_list["watched"]: if movie not in friend_movie: - friend_movie.append(movie) - + friend_movie.append(movie) + unique_user_movie = [] for movie in user_data["watched"]: if movie not in friend_movie: - unique_user_movie.append(movie) + unique_user_movie.append(movie) return unique_user_movie @@ -122,30 +94,27 @@ def get_friends_unique_watched(user_data): for movie in user_data["watched"]: if movie not in unique_user_movie: - unique_user_movie.append(movie) - + unique_user_movie.append(movie) + friend_unique_movie = [] for friend_list in user_data["friends"]: for movie in friend_list["watched"]: - if movie not in unique_user_movie: - if movie not in friend_unique_movie: - friend_unique_movie.append(movie) - + if movie not in unique_user_movie and movie not in friend_unique_movie: + friend_unique_movie.append(movie) + return friend_unique_movie # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- -# user has not watched -# one friend has watched -# host should be in user subscription -def get_available_recs(user_data): + +def get_available_recs(user_data): friend_unique_movie = get_friends_unique_watched(user_data) rec_movies = [] for movie in friend_unique_movie: - if movie["host"] in user_data["subscriptions"]: + if movie["host"] in user_data["subscriptions"]: rec_movies.append(movie) return rec_movies # ----------------------------------------- @@ -157,21 +126,20 @@ def get_new_rec_by_genre(user_data): rec_movies = [] most_watched_genre = get_most_watched_genre(user_data) friend_unique_movie = get_friends_unique_watched(user_data) - + for movie in friend_unique_movie: if most_watched_genre == movie["genre"]: rec_movies.append(movie) - + return rec_movies def get_rec_from_favorites(user_data): unique_watched_movie = get_unique_watched(user_data) - rec_movies = [] - for user_movie in unique_watched_movie: - for fav_movie in user_data["favorites"]: - if user_movie["title"] == fav_movie["title"]: - rec_movies.append(user_movie) - - return rec_movies + fav_titles = {movie["title"] for movie in user_data["favorites"]} + + rec_movies = [movie for movie in unique_watched_movie if movie["title"] in fav_titles] + + + return rec_movies From 9305c631c0391cb2bd50dc26b00ffef5a968d66c Mon Sep 17 00:00:00 2001 From: izzycommits Date: Fri, 27 Sep 2024 03:11:17 -0400 Subject: [PATCH 11/11] change watch movie to copy --- viewing_party/party.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index a3dbde551..2efa5c96f 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -24,18 +24,27 @@ def add_to_watchlist(user_data, movie): def watch_movie(user_data, title): + new_watchlist = [] + new_watched = [] - watch_list = user_data["watchlist"] - watched = user_data["watched"] + for movie in user_data["watchlist"]: + new_watchlist.append(movie) + + for movie in user_data["watched"]: + new_watched.append(movie) - for movie in watch_list: + for movie in new_watchlist: if movie["title"] == title: - watched.append(movie) - watch_list.remove(movie) + new_watched.append(movie) + new_watchlist.remove(movie) break - return user_data - + updated_user_data = { + "watchlist": new_watchlist, + "watched": new_watched + } + + return updated_user_data # ----------------------------------------- # ------------- WAVE 2 --------------------