From c62bb95f8cdd97c0a1da6b3211fcf19eb5bfeb14 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 17 Mar 2022 13:53:54 -0700 Subject: [PATCH 01/15] added comment --- .test_wave_01.py | 0 .tests | 0 play_tester.py | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .test_wave_01.py create mode 100644 .tests diff --git a/.test_wave_01.py b/.test_wave_01.py new file mode 100644 index 000000000..e69de29bb diff --git a/.tests b/.tests new file mode 100644 index 000000000..e69de29bb diff --git a/play_tester.py b/play_tester.py index 9e2aecf48..7510da8da 100644 --- a/play_tester.py +++ b/play_tester.py @@ -1,4 +1,4 @@ -# import source code +# import source code #myfirst comment from viewing_party.party import * # import test data From b10272b43b9abc1a6dcd1921de2fd44f717b73f2 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 17 Mar 2022 14:43:50 -0700 Subject: [PATCH 02/15] first 4 tests passed, create movie function made --- tests/test_wave_01.py | 8 ++++---- viewing_party/party.py | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c033af09f..13f1e3b66 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"] is 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" diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..6231c22ef 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,14 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + if title != None and genre != None and rating != None: + movie_dict = {} + movie_dict["title"] = title + movie_dict["genre"] = genre + movie_dict["rating"] = rating + else: + return None + return movie_dict # ----------------------------------------- # ------------- WAVE 2 -------------------- From 0decb6c8f3c348c080497e7a9c808811bdbaee95 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 17 Mar 2022 18:34:14 -0700 Subject: [PATCH 03/15] added watch_movie function, passed 7 tests --- play_tester.py | 2 +- tests/test_wave_01.py | 6 +++--- viewing_party/party.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/play_tester.py b/play_tester.py index 7510da8da..9e2aecf48 100644 --- a/play_tester.py +++ b/play_tester.py @@ -1,4 +1,4 @@ -# import source code #myfirst comment +# import source code from viewing_party.party import * # import test data diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 13f1e3b66..16c477a28 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -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"] is GENRE_1 assert updated_data["watched"][0]["rating"] is RATING_1 -@pytest.mark.skip() +#pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -100,7 +100,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] is GENRE_1 assert updated_data["watchlist"][0]["rating"] is RATING_1 -@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 6231c22ef..14c8cf3d5 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,5 +1,8 @@ # ------------- WAVE 1 -------------------- +from re import U + + def create_movie(title, genre, rating): if title != None and genre != None and rating != None: movie_dict = {} @@ -10,6 +13,24 @@ def create_movie(title, genre, rating): return None return movie_dict +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 = add_to_watched(user_data, movie) + return user_data + + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- From 9cb67d5e7c27198af1a481dacb65d234626a024f Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 17 Mar 2022 19:13:38 -0700 Subject: [PATCH 04/15] passed tests for wave 1 --- tests/test_wave_01.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 16c477a28..7ffa239f3 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -118,12 +118,15 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 1 + assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1 + assert updated_data["watched"][0]["genre"] is GENRE_1 + assert updated_data["watched"][0]["rating"] is RATING_1 # ******************************************************************************************* # ****** 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 @@ -141,12 +144,15 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) is 1 assert len(updated_data["watched"]) is 2 + assert updated_data["watched"][1]["title"] is MOVIE_TITLE_1 + assert updated_data["watched"][1]["genre"] is GENRE_1 + assert updated_data["watched"][1]["rating"] is RATING_1 # ******************************************************************************************* # ****** 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 c1dda7df328b1792958ac19c5c9626dd1b4d47cd Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 18 Mar 2022 11:39:07 -0700 Subject: [PATCH 05/15] added get_watched_avg_rating function, passed tests for it --- requirements.txt | 2 +- tests/test_wave_02.py | 4 ++-- viewing_party/party.py | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index a1f490d3d..4071a1f89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ pluggy==0.13.1 pprintpp==0.4.0 py==1.10.0 pyparsing==2.4.7 -pytest==6.2.1 +pytest==7.1.0 toml==0.10.2 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..c24fec8d4 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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 14c8cf3d5..17c24d888 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -30,10 +30,21 @@ def watch_movie(user_data, title): - # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + lst = [] + sum = 0 + for item in user_data["watched"]: + lst.append(item["rating"]) + for number in lst: + sum += number + if lst: + return sum / len(lst) + else: + return 0.0 + # ----------------------------------------- From caaa834d61d2dab86b6f90d510843ba4ca1c2441 Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 15:30:21 -0700 Subject: [PATCH 06/15] added get_most_watched_genre function, passed tests for Wave2 --- .gitignore | 1 + tests/test_constants.py | 14 ++++++++++++++ tests/test_wave_01.py | 12 ++++++------ tests/test_wave_02.py | 15 +++++++++++++-- viewing_party/party.py | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7b7b959c8..01228ce14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vscode/ .DS_Store .vscode +.idea # GitHub's boilerplate Python gitignore # https://github.com/github/gitignore/blob/master/Python.gitignore diff --git a/tests/test_constants.py b/tests/test_constants.py index 55d4dceb5..69805fd4b 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -78,6 +78,17 @@ ], } +USER_ADDITIONAL_DATA_2 = { + "watched": [ + ACTION_1, + INTRIGUE_1, + INTRIGUE_2, + FANTASY_1, + FANTASY_2, + FANTASY_3 + ], +} + #-----WAVE 3-------- USER_DATA_3 = copy.deepcopy(USER_DATA_2) USER_DATA_3["friends"] = [ @@ -173,6 +184,9 @@ def clean_wave_2_data(): return copy.deepcopy(USER_DATA_2) +def clean_wave_2_additional_data(): + return copy.deepcopy(USER_ADDITIONAL_DATA_2) + def clean_wave_3_data(): return copy.deepcopy(USER_DATA_3) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 7ffa239f3..e01fe9d22 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -96,9 +96,9 @@ def test_adds_movie_to_user_watchlist(): # Assert assert len(updated_data["watchlist"]) is 1 - assert updated_data["watchlist"][0]["title"] is MOVIE_TITLE_1 - assert updated_data["watchlist"][0]["genre"] is GENRE_1 - assert updated_data["watchlist"][0]["rating"] is RATING_1 + assert updated_data["watchlist"][0]["title"] == MOVIE_TITLE_1 + assert updated_data["watchlist"][0]["genre"] == GENRE_1 + assert updated_data["watchlist"][0]["rating"] == RATING_1 #@pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): @@ -118,9 +118,9 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 1 - assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1 - assert updated_data["watched"][0]["genre"] is GENRE_1 - assert updated_data["watched"][0]["rating"] is RATING_1 + 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 # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index c24fec8d4..7c3eca885 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -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,18 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +def test_most_watched_genre_additional(): + # Arrange + janes_data = clean_wave_2_additional_data() + + # Act + popular_genre = get_most_watched_genre(janes_data) + + # Assert + assert popular_genre == "Fantasy" + assert janes_data == clean_wave_2_additional_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 17c24d888..4111fff87 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -45,6 +45,22 @@ def get_watched_avg_rating(user_data): else: return 0.0 +def get_most_watched_genre(user_data): + + most_watched = {} + for movie in user_data["watched"]: + most_watched.setdefault(movie["genre"], 0) + most_watched[movie["genre"]] += 1 + + max_value = 0 + max_key = None + + for key, value in most_watched.items(): + if value > max_value: + max_value = value + max_key = key + return max_key + # ----------------------------------------- From 58ce1cc300a914e8a04b278b2a7e916a0bdcf19e Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 18:36:35 -0700 Subject: [PATCH 07/15] created get_unique_watched function, passed tests for it --- tests/test_wave_03.py | 4 ++-- viewing_party/party.py | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 7c42a63c4..5810d12b0 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() diff --git a/viewing_party/party.py b/viewing_party/party.py index 4111fff87..7d23351ef 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -27,8 +27,6 @@ def watch_movie(user_data, title): user_data["watchlist"].remove(movie) user_data = add_to_watched(user_data, movie) return user_data - - # ----------------------------------------- # ------------- WAVE 2 -------------------- @@ -60,14 +58,26 @@ def get_most_watched_genre(user_data): max_value = value max_key = key return max_key - - - # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + list_watched = [] + for movie in user_data["watched"]: + list_watched.append(movie) + + friends_watched_set = set() + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_set.add(movie["title"]) + + list_unique = [] + for movie in list_watched: + if movie["title"] not in friends_watched_set: + list_unique.append(movie) + return list_unique + - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From 04bb3f301da776ebe3a7dea5d60a3dc7796dad8d Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 19:00:12 -0700 Subject: [PATCH 08/15] made get_friends_unique_watched function, completed tests for Wave 3 --- tests/test_wave_03.py | 4 ++-- viewing_party/party.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 5810d12b0..62e6ff0f4 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Arrange 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() diff --git a/viewing_party/party.py b/viewing_party/party.py index 7d23351ef..93e60f582 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -77,7 +77,22 @@ def get_unique_watched(user_data): list_unique.append(movie) return list_unique +def get_friends_unique_watched(user_data): + set_watched = set() + for movie in user_data["watched"]: + set_watched.add(movie["title"]) + + friends_watched_dict = {} + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_dict[movie["title"]] = movie + list_unique = [] + for key, value in friends_watched_dict.items(): + if key not in set_watched: + list_unique.append(value) + + return list_unique # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From ee1a6c49dfcc6083294a1b6611e9a1f8d2d32969 Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 22:29:28 -0700 Subject: [PATCH 09/15] added get_available_recs function,passed tests for Wave 4 --- tests/test_wave_04.py | 4 ++-- viewing_party/party.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 72888410f..8bb8958d4 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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 93e60f582..f29eb33a9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -96,6 +96,28 @@ def get_friends_unique_watched(user_data): # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + set_watched = set() + for movie in user_data["watched"]: + set_watched.add(movie["title"]) + + friends_watched_list = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_list.append(movie) + + list_friends_watched = [] + for movie in friends_watched_list: + if movie["title"] not in set_watched: + list_friends_watched.append(movie) + + recs_list = [] + for movie in list_friends_watched: + if movie["host"] in user_data["subscriptions"]: + recs_list.append(movie) + + return recs_list + # ----------------------------------------- # ------------- WAVE 5 -------------------- From 59684749a3346f99cb6b794bc500d96b467de68d Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 22:56:15 -0700 Subject: [PATCH 10/15] added get_new_rec_by_genre function, passed tests for it --- tests/test_wave_01.py | 24 ++++++++++++------------ tests/test_wave_05.py | 9 +++++---- viewing_party/party.py | 24 +++++++++++++++++++++++- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index e01fe9d22..35464b638 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -15,8 +15,8 @@ def test_create_successful_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie["title"] is MOVIE_TITLE_1 - assert new_movie["genre"] is GENRE_1 + assert new_movie["title"] == MOVIE_TITLE_1 + assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) #@pytest.mark.skip() @@ -43,7 +43,7 @@ def test_create_no_genre_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie is None + assert new_movie == None #@pytest.mark.skip() def test_create_no_rating_movie(): @@ -56,7 +56,7 @@ def test_create_no_rating_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie is None + assert new_movie == None #@pytest.mark.skip() def test_adds_movie_to_user_watched(): @@ -75,9 +75,9 @@ def test_adds_movie_to_user_watched(): # Assert assert len(updated_data["watched"]) is 1 - assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1 - assert updated_data["watched"][0]["genre"] is GENRE_1 - assert updated_data["watched"][0]["rating"] is RATING_1 + 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_adds_movie_to_user_watchlist(): @@ -142,11 +142,11 @@ def test_moves_movie_from_watchlist_to_watched(): updated_data = watch_movie(janes_data, movie_to_watch["title"]) # Assert - assert len(updated_data["watchlist"]) is 1 - assert len(updated_data["watched"]) is 2 - assert updated_data["watched"][1]["title"] is MOVIE_TITLE_1 - assert updated_data["watched"][1]["genre"] is GENRE_1 - assert updated_data["watched"][1]["rating"] is RATING_1 + assert len(updated_data["watchlist"]) == 1 + assert len(updated_data["watched"]) == 2 + assert updated_data["watched"][1]["title"] == MOVIE_TITLE_1 + assert updated_data["watched"][1]["genre"] == GENRE_1 + assert updated_data["watched"][1]["rating"] == RATING_1 # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 8ce5b57db..971614c16 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,7 +52,8 @@ def test_new_genre_rec_from_empty_friends(): } ] } - + recommendations = get_new_rec_by_genre(sonyas_data) + assert len(recommendations) == 0 # ********************************************************************* # ****** Complete the Act and Assert Portions of theis tests ********** # ********************************************************************* diff --git a/viewing_party/party.py b/viewing_party/party.py index f29eb33a9..07898ab45 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -118,8 +118,30 @@ def get_available_recs(user_data): return recs_list - # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + most_watched_genre = get_most_watched_genre(user_data) + + set_watched = set() + for movie in user_data["watched"]: + set_watched.add(movie["title"]) + + friends_watched_list = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_list.append(movie) + + list_friends_watched = [] + for movie in friends_watched_list: + if movie["title"] not in set_watched: + list_friends_watched.append(movie) + + rec_by_genre_list = [] + for movie in list_friends_watched: + if movie["genre"] == most_watched_genre: + rec_by_genre_list.append(movie) + return rec_by_genre_list + From a82c7623dc3f8e5549c53118f6e1f35d9df14971 Mon Sep 17 00:00:00 2001 From: Daria Date: Sat, 19 Mar 2022 23:07:37 -0700 Subject: [PATCH 11/15] added get_rec_from_favorites function, tests for Wave 5 passed --- tests/test_wave_03.py | 2 +- tests/test_wave_05.py | 6 +++--- viewing_party/party.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 62e6ff0f4..ea5170ab9 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -59,7 +59,7 @@ def test_friends_unique_movies_not_duplicated(): # ****** 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_05.py b/tests/test_wave_05.py index 971614c16..29deafb30 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -58,7 +58,7 @@ def test_new_genre_rec_from_empty_friends(): # ****** Complete the Act and Assert Portions of theis tests ********** # ********************************************************************* -@pytest.mark.skip() +#@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() +#@pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -93,7 +93,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 07898ab45..15e0285e5 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -145,3 +145,14 @@ def get_new_rec_by_genre(user_data): rec_by_genre_list.append(movie) return rec_by_genre_list +def get_rec_from_favorites(user_data): + friends_watched_set = set() + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_set.add(movie["title"]) + + rec_from_fav_list = [] + for movie in user_data["favorites"]: + if movie["title"] not in friends_watched_set: + rec_from_fav_list.append(movie) + return rec_from_fav_list \ No newline at end of file From e87cb25bc24b7bda5aaa8c4b1e6be58f7a1a2ea6 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 24 Mar 2022 22:43:45 -0700 Subject: [PATCH 12/15] viewing_party code refactoring --- .test_wave_01.py | 0 .tests | 0 tests/test_wave_01.py | 8 ++++---- viewing_party/party.py | 23 ++++++++++++----------- 4 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 .test_wave_01.py delete mode 100644 .tests diff --git a/.test_wave_01.py b/.test_wave_01.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/.tests b/.tests deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 35464b638..fbd911eb3 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -30,7 +30,7 @@ def test_create_no_title_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie is None + assert new_movie == None #@pytest.mark.skip() def test_create_no_genre_movie(): @@ -95,7 +95,7 @@ def test_adds_movie_to_user_watchlist(): updated_data = add_to_watchlist(user_data, movie) # Assert - assert len(updated_data["watchlist"]) is 1 + assert len(updated_data["watchlist"]) == 1 assert updated_data["watchlist"][0]["title"] == MOVIE_TITLE_1 assert updated_data["watchlist"][0]["genre"] == GENRE_1 assert updated_data["watchlist"][0]["rating"] == RATING_1 @@ -116,8 +116,8 @@ def test_moves_movie_from_watchlist_to_empty_watched(): updated_data = watch_movie(janes_data, MOVIE_TITLE_1) # Assert - assert len(updated_data["watchlist"]) is 0 - assert len(updated_data["watched"]) is 1 + assert len(updated_data["watchlist"]) == 0 + assert len(updated_data["watched"]) == 1 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 diff --git a/viewing_party/party.py b/viewing_party/party.py index 15e0285e5..53013aeaf 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -32,14 +32,14 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- def get_watched_avg_rating(user_data): - lst = [] + watched_movies_list = [] sum = 0 for item in user_data["watched"]: - lst.append(item["rating"]) - for number in lst: + watched_movies_list.append(item["rating"]) + for number in watched_movies_list: sum += number - if lst: - return sum / len(lst) + if watched_movies_list : + return sum / len(watched_movies_list) else: return 0.0 @@ -61,6 +61,7 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- + def get_unique_watched(user_data): list_watched = [] for movie in user_data["watched"]: @@ -106,13 +107,13 @@ def get_available_recs(user_data): for movie in friend["watched"]: friends_watched_list.append(movie) - list_friends_watched = [] + list_only_friends_watched = [] for movie in friends_watched_list: if movie["title"] not in set_watched: - list_friends_watched.append(movie) + list_only_friends_watched.append(movie) recs_list = [] - for movie in list_friends_watched: + for movie in list_only_friends_watched: if movie["host"] in user_data["subscriptions"]: recs_list.append(movie) @@ -134,13 +135,13 @@ def get_new_rec_by_genre(user_data): for movie in friend["watched"]: friends_watched_list.append(movie) - list_friends_watched = [] + list_only_friends_watched = [] for movie in friends_watched_list: if movie["title"] not in set_watched: - list_friends_watched.append(movie) + list_only_friends_watched.append(movie) rec_by_genre_list = [] - for movie in list_friends_watched: + for movie in list_only_friends_watched: if movie["genre"] == most_watched_genre: rec_by_genre_list.append(movie) return rec_by_genre_list From f498fc9514693c148e1d0463a3be7d995aae53f1 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 24 Mar 2022 23:06:44 -0700 Subject: [PATCH 13/15] added asserts to Wave3 function test_friends_unique_movies_not_duplicated --- tests/test_wave_03.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index ea5170ab9..0c283e747 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -54,6 +54,9 @@ def test_friends_unique_movies_not_duplicated(): # Arrange 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 # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** From dce019c048bffca83fb616867377179913a68c61 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 24 Mar 2022 23:34:57 -0700 Subject: [PATCH 14/15] added comment to test in Wave2 --- tests/test_wave_01.py | 2 +- tests/test_wave_02.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index fbd911eb3..aff04f4ba 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -74,7 +74,7 @@ def test_adds_movie_to_user_watched(): updated_data = add_to_watched(user_data, movie) # Assert - assert len(updated_data["watched"]) is 1 + assert len(updated_data["watched"]) == 1 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 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 7c3eca885..bfb2c902e 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -39,7 +39,8 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -def test_most_watched_genre_additional(): +def test_most_watched_genre_additional(): #added an additional test to make sure the function picks up + #the most watched genre and not just the first one from the list # Arrange janes_data = clean_wave_2_additional_data() From eb26c55042131a4480392324479a5a036d7b38ae Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 25 Mar 2022 08:20:44 -0700 Subject: [PATCH 15/15] reformatted code --- viewing_party/party.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 53013aeaf..16e5675c3 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,8 +1,4 @@ # ------------- WAVE 1 -------------------- - -from re import U - - def create_movie(title, genre, rating): if title != None and genre != None and rating != None: movie_dict = {} @@ -13,14 +9,17 @@ def create_movie(title, genre, rating): return None return movie_dict + 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: @@ -28,6 +27,7 @@ def watch_movie(user_data, title): user_data = add_to_watched(user_data, movie) return user_data + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- @@ -38,13 +38,13 @@ def get_watched_avg_rating(user_data): watched_movies_list.append(item["rating"]) for number in watched_movies_list: sum += number - if watched_movies_list : + if watched_movies_list: return sum / len(watched_movies_list) else: return 0.0 -def get_most_watched_genre(user_data): +def get_most_watched_genre(user_data): most_watched = {} for movie in user_data["watched"]: most_watched.setdefault(movie["genre"], 0) @@ -58,6 +58,8 @@ def get_most_watched_genre(user_data): max_value = value max_key = key return max_key + + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- @@ -78,6 +80,7 @@ def get_unique_watched(user_data): list_unique.append(movie) return list_unique + def get_friends_unique_watched(user_data): set_watched = set() for movie in user_data["watched"]: @@ -94,6 +97,8 @@ def get_friends_unique_watched(user_data): list_unique.append(value) return list_unique + + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- @@ -119,6 +124,7 @@ def get_available_recs(user_data): return recs_list + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- @@ -146,6 +152,7 @@ def get_new_rec_by_genre(user_data): rec_by_genre_list.append(movie) return rec_by_genre_list + def get_rec_from_favorites(user_data): friends_watched_set = set() for friend in user_data["friends"]: @@ -156,4 +163,4 @@ def get_rec_from_favorites(user_data): for movie in user_data["favorites"]: if movie["title"] not in friends_watched_set: rec_from_fav_list.append(movie) - return rec_from_fav_list \ No newline at end of file + return rec_from_fav_list