From a9e8fef2fd75467d02d98dfb36d9416c2c68d02a Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 27 Mar 2023 17:57:50 -0600 Subject: [PATCH 01/20] Part One of Wave One --- tests/test_wave_01.py | 18 ++++++++-------- viewing_party/party.py | 47 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..665700416 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,7 @@ 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 +32,7 @@ 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 +45,7 @@ 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 +58,7 @@ 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 +79,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] == GENRE_1 assert updated_data["watched"][0]["rating"] == RATING_1 -@pytest.mark.skip() + def test_adds_movie_to_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +99,7 @@ def test_adds_movie_to_non_empty_user_watched(): assert movie in updated_data["watched"] assert FANTASY_2 in updated_data["watched"] -@pytest.mark.skip() + def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -120,7 +120,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] == GENRE_1 assert updated_data["watchlist"][0]["rating"] == RATING_1 -@pytest.mark.skip() + def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -159,7 +159,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 - raise Exception("Test needs to be completed.") + raise Exception(ValueError) # ******************************************************************************************* # ****** 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 6d34a6b5f..3082c127a 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,52 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + if check_invalid_inputs(title, genre, rating) is True: + + movie = {"title": title, "genre": genre, "rating": rating} + return movie + +def check_invalid_inputs(title, genre, rating): + if (title, genre, rating) == None: + return None + return True + + + +# def add_to_watched(user_data, movie): +# watched_movie = movie +# user_data = {"watched": [watched_movie]} +# return user_data + +# def add_to_watchlist(user_data, movie): +# new_movie = movie +# user_data = {"watchlist": [new_movie]} +# return user_data + +# def watch_movie(user_data, title): +# add_to_watched(user_data,) + +# user_data = {"watchlist": [new_movie], "watched": [watched_movie]} +# title = "" +# if title != str: +# return None +# elif title in user_data["watchlist"]: +# user_data["wacthlist"].remove(title) +# user_data["watched"].append(title) +# return user_data +# else: +# return user_data + + + + + + + + + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- From 82912d1b9c9be3ed08da5f74ff8dad1a0ad96e24 Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 27 Mar 2023 20:33:30 -0600 Subject: [PATCH 02/20] Wave 01 All Passed Except 2 --- tests/test_wave_01.py | 14 ++++++---- viewing_party/party.py | 62 ++++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 665700416..f080ffc6a 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -140,7 +140,7 @@ def test_adds_movie_to_non_empty_user_watchlist(): assert movie in updated_data["watchlist"] assert FANTASY_2 in updated_data["watchlist"] -@pytest.mark.skip() + def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -158,13 +158,15 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 + # - raise Exception(ValueError) - # ******************************************************************************************* - # ****** Add assertions here to test that the correct movie was added to "watched" ********** + #TypeError: 'NoneType' object is not subscriptable + #raise ValueError("This movie is not in the watchlist list.") + # ****** 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 @@ -188,7 +190,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 diff --git a/viewing_party/party.py b/viewing_party/party.py index 3082c127a..47cb58317 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,41 +1,51 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - if check_invalid_inputs(title, genre, rating) is True: - + if check_invalid_movies(title, genre, rating) is True: movie = {"title": title, "genre": genre, "rating": rating} return movie -def check_invalid_inputs(title, genre, rating): - if (title, genre, rating) == None: +def check_invalid_movies(title, genre, rating): + if title == None or genre == None or rating == None: return None return True - - -# def add_to_watched(user_data, movie): -# watched_movie = movie -# user_data = {"watched": [watched_movie]} -# return user_data +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + return user_data -# def add_to_watchlist(user_data, movie): -# new_movie = movie -# user_data = {"watchlist": [new_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): -# add_to_watched(user_data,) +def watch_movie(user_data, title): + #add_to_watched(user_data,) + watchlist_value = user_data["watchlist"] + watched_value = user_data["watched"] + + for item in watchlist_value: + item_title = item["title"] + if title == item_title: + watchlist_value.remove(item) + + watched_value.append(item) + return user_data + else: + return user_data -# user_data = {"watchlist": [new_movie], "watched": [watched_movie]} -# title = "" -# if title != str: -# return None -# elif title in user_data["watchlist"]: -# user_data["wacthlist"].remove(title) -# user_data["watched"].append(title) -# return user_data -# else: -# return user_data + #user_data = {"watchlist": [new_movie], "watched": [watched_movie]} + #title = "" + # if title != str: + # return None + #elif title in user_data["watchlist"][0]["title"]: + # for index in len(user_data["watchlist"]): + # if title in user_data["watchlist"][index]["title"]: + # user_data["watchlist"].pop(index) + # #user_data["wacthlist"].remove(title) + # user_data["watched"].append(title) + # return user_data + # else: + # return user_data From 809023f45bb712a681603639dc987416dfbf764f Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 27 Mar 2023 22:39:51 -0600 Subject: [PATCH 03/20] HI NADIA, WAVE 01 ALL TESTS PASSED EXCEPT ONE --- tests/test_wave_01.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index f080ffc6a..26800043e 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -158,10 +158,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 - # - - #TypeError: 'NoneType' object is not subscriptable - #raise ValueError("This movie is not in the watchlist list.") + assert MOVIE_TITLE_1 in updated_data["watched"][0]["title"] # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* @@ -184,7 +181,9 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 + #assert FANTASY_2 in updated_data["watched"] + raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** From 549fefbc9dbf050fe8b6dbfe2387cad79e451496 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 28 Mar 2023 09:16:45 -0600 Subject: [PATCH 04/20] WAVE 01 DONE --- tests/test_wave_01.py | 5 ++--- viewing_party/party.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 26800043e..fb40009bd 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -181,10 +181,9 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - #assert FANTASY_2 in updated_data["watched"] - + assert HORROR_1["title"] == updated_data["watched"][1]["title"] - 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" ********** # ******************************************************************************************* diff --git a/viewing_party/party.py b/viewing_party/party.py index 47cb58317..595102c26 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -30,8 +30,7 @@ def watch_movie(user_data, title): watched_value.append(item) return user_data - else: - return user_data + return user_data #user_data = {"watchlist": [new_movie], "watched": [watched_movie]} #title = "" From 7da26aed728c9a56d38f97cde108db3054a27433 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Tue, 28 Mar 2023 11:52:16 -0400 Subject: [PATCH 05/20] not correct --- tests/test_wave_01.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index f080ffc6a..fbf7170d4 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -185,11 +185,6 @@ def test_moves_movie_from_watchlist_to_watched(): 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" ********** - # ******************************************************************************************* - def test_does_nothing_if_movie_not_in_watchlist(): # Arrange From a44661263e7f3d817a19da6c3ede351f3a9dbe05 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 28 Mar 2023 15:08:12 -0600 Subject: [PATCH 06/20] no no --- viewing_party/party.py | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 595102c26..a4b58f22f 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -31,37 +31,15 @@ def watch_movie(user_data, title): watched_value.append(item) return user_data return user_data - - #user_data = {"watchlist": [new_movie], "watched": [watched_movie]} - #title = "" - # if title != str: - # return None - #elif title in user_data["watchlist"][0]["title"]: - # for index in len(user_data["watchlist"]): - # if title in user_data["watchlist"][index]["title"]: - # user_data["watchlist"].pop(index) - # #user_data["wacthlist"].remove(title) - # user_data["watched"].append(title) - # return user_data - # else: - # return user_data - - - - - - - - - - - + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- + + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- From 5ac1a1bc63fa81b4057291560c23d6082bf500fb Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Tue, 28 Mar 2023 23:54:34 -0400 Subject: [PATCH 07/20] wave_3 all done except one test --- viewing_party/party.py | 58 ++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index def1e6c41..d407c524d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -97,21 +97,53 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- +# def get_unique_watched(user_data): +# count = 0 +# both_users_watched = [] +# only_user_watched = [] +# for movie in user_data["watched"]: +# # for item in user_data["friends"]: +# if movie in user_data["friends"]: +# # if movie in item["watched"]: +# both_users_watched.append(movie) +# # if movie not in item["watched"]: +# else: +# only_user_watched.append(movie) + +# return only_user_watched + def get_unique_watched(user_data): - count = 0 - both_users_watched = set() - only_user_watched = set() + only_user_watched = [] + friends_watched =[] + for item in user_data["friends"]: + for movie in item["watched"]: + friends_watched.append(movie) + for movie in user_data["watched"]: - for item in user_data["friends"]: - - if movie == item["watched"][count]: - both_users_watched.add(movie) - if movie not in item["watched"][count]: - only_user_watched.add(movie) - count += 1 - return only_user_watched - - + if movie not in friends_watched: + only_user_watched.append(movie) + return only_user_watched + + +def get_friends_unique_watched(user_data): + only_friends_watched = [] + friends_watched =[] + + for item in user_data["friends"]: + for movie in item["watched"]: + friends_watched.append(movie) + + unique_movies = [] + for movie in friends_watched: + if movie not in user_data["watched"] and not unique_movies: + # only_friends_watched.append(movie) + unique_movies.append(movie) + + return only_friends_watched + + + + # ----------------------------------------- From 0f4686ffdcf0864b16724f17c8ba1950a12157c7 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Wed, 29 Mar 2023 00:24:23 -0400 Subject: [PATCH 08/20] wave_3 is all set --- viewing_party/party.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index d407c524d..bbacbdb74 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -135,11 +135,10 @@ def get_friends_unique_watched(user_data): unique_movies = [] for movie in friends_watched: - if movie not in user_data["watched"] and not unique_movies: - # only_friends_watched.append(movie) + if movie not in user_data["watched"] and movie not in unique_movies: unique_movies.append(movie) - return only_friends_watched + return unique_movies From 0648a7b7c71d5c276e5d612d82eaa32136641238 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Wed, 29 Mar 2023 00:36:31 -0400 Subject: [PATCH 09/20] some more edits --- viewing_party/party.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index bbacbdb74..ed897bbbf 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -36,8 +36,6 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- - - def get_watched_avg_rating(user_data): try: @@ -90,27 +88,6 @@ def get_most_watched_genre(user_data): elif counter_intrigue > counter_horror and counter_intrigue > counter_fantasy and \ counter_intrigue > counter_action: return "Intrigue" - - - -# ----------------------------------------- -# ------------- WAVE 3 -------------------- -# ----------------------------------------- - -# def get_unique_watched(user_data): -# count = 0 -# both_users_watched = [] -# only_user_watched = [] -# for movie in user_data["watched"]: -# # for item in user_data["friends"]: -# if movie in user_data["friends"]: -# # if movie in item["watched"]: -# both_users_watched.append(movie) -# # if movie not in item["watched"]: -# else: -# only_user_watched.append(movie) - -# return only_user_watched def get_unique_watched(user_data): only_user_watched = [] @@ -140,11 +117,6 @@ def get_friends_unique_watched(user_data): return unique_movies - - - - - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From e09e3f60bb113e1c4cab567c7aac7ab2044ef082 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Wed, 29 Mar 2023 00:39:12 -0400 Subject: [PATCH 10/20] added assertations to test_wave_03.py --- tests/test_wave_03.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index d91dd9294..7f89c5a21 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -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() + def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -54,8 +54,10 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 - - raise Exception("Test needs to be completed.") + assert HORROR_1 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies + assert FANTASY_4 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 ********** # ************************************************************************************************** From e75cb2e8beae434cdbf627ff110f67c5195d1083 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 29 Mar 2023 15:42:35 -0600 Subject: [PATCH 11/20] wave 4 all tests passed --- tests/test_wave_04.py | 5 ++--- viewing_party/party.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..80734d518 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,7 @@ 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 +37,7 @@ 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 ed897bbbf..71ca46dfe 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -88,6 +88,10 @@ def get_most_watched_genre(user_data): elif counter_intrigue > counter_horror and counter_intrigue > counter_fantasy and \ counter_intrigue > counter_action: return "Intrigue" + +# ----------------------------------------- +# ------------- WAVE 3 -------------------- +# ----------------------------------------- def get_unique_watched(user_data): only_user_watched = [] @@ -121,7 +125,17 @@ def get_friends_unique_watched(user_data): # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + recommended_movies = [] + unique_movies = get_friends_unique_watched(user_data) + for movie in unique_movies: + if movie["host"] in user_data["subscriptions"]: + recommended_movies.append(movie) + return recommended_movies + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + \ No newline at end of file From 76cfea9e4636b52feda8a2ed78ed3e04e94d6ba6 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 29 Mar 2023 16:50:22 -0600 Subject: [PATCH 12/20] wave 4 all but 2 tests passed --- tests/test_wave_05.py | 21 +++++++++++++-------- viewing_party/party.py | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..31a90a545 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,18 @@ def test_new_genre_rec_from_empty_friends(): } ] } - - raise Exception("Test needs to be completed.") + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + + # Assert + assert len(recommendations) == 0 + + # ********************************************************************* # ****** 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 +77,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 +99,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 71ca46dfe..2b5035015 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -138,4 +138,22 @@ def get_available_recs(user_data): # ----------------------------------------- def get_new_rec_by_genre(user_data): - \ No newline at end of file + recommended_movies = [] + most_frequently_watched = get_most_watched_genre(user_data) + unique_movies = get_friends_unique_watched(user_data) + if most_frequently_watched is None: + return [] + for movie in unique_movies: + if movie["genre"] in most_frequently_watched: + recommended_movies.append(movie) + return recommended_movies + + +def get_rec_from_favorites(user_data): + recommended_movies = [] + friends_movies = get_friends_unique_watched(user_data) + for movie in user_data["favorites"]: + if not movie in friends_movies["watched"]: + recommended_movies.append(movie) + return recommended_movies + \ No newline at end of file From d925965b8ba85b6065c7dccab2983cd68a14b020 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Wed, 29 Mar 2023 19:39:30 -0400 Subject: [PATCH 13/20] All tests passed --- tests/test_wave_05.py | 18 +++++++++++------- viewing_party/party.py | 23 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..dce01f8ac 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 = { @@ -53,12 +53,16 @@ def test_new_genre_rec_from_empty_friends(): ] } - raise Exception("Test needs to be completed.") + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + + # Assert + assert len(recommendations) == 0 # ********************************************************************* # ****** 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 +76,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 +98,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 71ca46dfe..c5c9eb6bb 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -138,4 +138,25 @@ def get_available_recs(user_data): # ----------------------------------------- def get_new_rec_by_genre(user_data): - \ No newline at end of file + recommended_movies = [] + most_frequently_watched = get_most_watched_genre(user_data) + friends_unique_movies = get_friends_unique_watched(user_data) + if most_frequently_watched is None: + return [] + for movie in friends_unique_movies: + if movie["genre"] in most_frequently_watched: + recommended_movies.append(movie) + return recommended_movies + +def get_rec_from_favorites(user_data): + friends_watched =[] + + for item in user_data["friends"]: + for movie in item["watched"]: + friends_watched.append(movie) + recommended_movies = [] + # friends_movies = get_friends_unique_watched(user_data) + for movie in user_data["favorites"]: + if not movie in friends_watched: + recommended_movies.append(movie) + return recommended_movies \ No newline at end of file From 5a2331beeed463e646a74ac82c8e92da93e0107c Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Wed, 29 Mar 2023 19:47:59 -0400 Subject: [PATCH 14/20] minor changes added --- viewing_party/party.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 74f11efbf..764136430 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -149,26 +149,6 @@ def get_new_rec_by_genre(user_data): return recommended_movies -def get_rec_from_favorites(user_data): - recommended_movies = [] - friends_movies = get_friends_unique_watched(user_data) - for movie in user_data["favorites"]: - if not movie in friends_movies["watched"]: - recommended_movies.append(movie) - return recommended_movies - - -def get_rec_from_favorites(user_data): - friends_watched =[] - - for item in user_data["friends"]: - for movie in item["watched"]: - friends_watched.append(movie) - recommended_movies = [] - for movie in user_data["favorites"]: - if not movie in friends_watched: - recommended_movies.append(movie) - return recommended_movies def get_rec_from_favorites(user_data): friends_watched =[] From 1d0a0639febea0e78fbd833a116987342b7630fa Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 30 Mar 2023 14:54:20 -0600 Subject: [PATCH 15/20] wave 02 was refactored --- viewing_party/party.py | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 764136430..43c0e9662 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -35,6 +35,8 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +import statistics + def get_watched_avg_rating(user_data): @@ -52,42 +54,14 @@ def get_watched_avg_rating(user_data): def get_most_watched_genre(user_data): - counter_fantasy = 0 - counter_horror = 0 - counter_action = 0 - counter_intrigue = 0 - + genre = [] + if user_data["watched"] == []: return None for movie in user_data["watched"]: - if movie["genre"] == "Fantasy": - counter_fantasy += 1 - elif movie["genre"] == "Action": - counter_action += 1 - elif movie["genre"] == "intrigue": - counter_intrigue += 1 - elif movie["genre"] == "Horror": - counter_horror += 1 - - if counter_fantasy > counter_horror and counter_fantasy > counter_action and \ - counter_fantasy > counter_intrigue: - return "Fantasy" - - elif counter_horror > counter_action and counter_horror > counter_intrigue and \ - counter_horror > counter_fantasy: - return "Horror" - - elif counter_action > counter_horror and counter_action > counter_fantasy and \ - counter_action > counter_intrigue: - return "Action" - - elif counter_action > counter_horror and counter_action > counter_fantasy and \ - counter_action > counter_intrigue: - return "Action" - - elif counter_intrigue > counter_horror and counter_intrigue > counter_fantasy and \ - counter_intrigue > counter_action: - return "Intrigue" + genre.append(movie["genre"]) + return statistics.mode(genre) + # ----------------------------------------- # ------------- WAVE 3 -------------------- From fa77c5e250f669d1b32bbc1407d7927861b3dfd6 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 30 Mar 2023 14:59:36 -0600 Subject: [PATCH 16/20] wave 01 and wave 02 refactored --- viewing_party/party.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 43c0e9662..c339881cd 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,14 +1,10 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - if check_invalid_movies(title, genre, rating) is True: - movie = {"title": title, "genre": genre, "rating": rating} - return movie - -def check_invalid_movies(title, genre, rating): if title == None or genre == None or rating == None: return None - return True + movie = {"title": title, "genre": genre, "rating": rating} + return movie def add_to_watched(user_data, movie): user_data["watched"].append(movie) @@ -19,7 +15,6 @@ def add_to_watchlist(user_data, movie): return user_data def watch_movie(user_data, title): - watchlist_value = user_data["watchlist"] watched_value = user_data["watched"] @@ -27,7 +22,6 @@ def watch_movie(user_data, title): item_title = item["title"] if title == item_title: watchlist_value.remove(item) - watched_value.append(item) return user_data return user_data @@ -46,7 +40,6 @@ def get_watched_avg_rating(user_data): for movie in user_data["watched"]: average_rating += movie["rating"] number_of_movies += 1 - average_rating = average_rating / number_of_movies return average_rating except ZeroDivisionError: @@ -55,7 +48,6 @@ def get_watched_avg_rating(user_data): def get_most_watched_genre(user_data): genre = [] - if user_data["watched"] == []: return None for movie in user_data["watched"]: From 8d12459fa8feab277fce8bd501dd00038acd91f8 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 30 Mar 2023 15:02:10 -0600 Subject: [PATCH 17/20] refactored entire project --- viewing_party/party.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index c339881cd..7bdcefd67 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -65,7 +65,6 @@ def get_unique_watched(user_data): for item in user_data["friends"]: for movie in item["watched"]: friends_watched.append(movie) - for movie in user_data["watched"]: if movie not in friends_watched: only_user_watched.append(movie) @@ -75,16 +74,13 @@ def get_unique_watched(user_data): def get_friends_unique_watched(user_data): only_friends_watched = [] friends_watched =[] - for item in user_data["friends"]: for movie in item["watched"]: friends_watched.append(movie) - unique_movies = [] for movie in friends_watched: if movie not in user_data["watched"] and movie not in unique_movies: unique_movies.append(movie) - return unique_movies # ----------------------------------------- @@ -113,17 +109,13 @@ def get_new_rec_by_genre(user_data): if movie["genre"] in most_frequently_watched: recommended_movies.append(movie) return recommended_movies - - def get_rec_from_favorites(user_data): friends_watched =[] - for item in user_data["friends"]: for movie in item["watched"]: friends_watched.append(movie) - recommended_movies = [] - # friends_movies = get_friends_unique_watched(user_data) + recommended_movies = [] for movie in user_data["favorites"]: if not movie in friends_watched: recommended_movies.append(movie) From 4ecfa2e0404c2a8b057455c5ba7b5ca7d5a4e8a1 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 30 Mar 2023 15:50:02 -0600 Subject: [PATCH 18/20] wave 01 wave 02 wave 03 refactored --- tests/test_wave_01.py | 3 ++- tests/test_wave_03.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index fb40009bd..656ad703a 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -182,8 +182,9 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 assert HORROR_1["title"] == updated_data["watched"][1]["title"] + assert HORROR_1 in updated_data["watched"] - #raise Exception("Test needs to be completed.") + # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 7f89c5a21..41ea0c7ab 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -57,7 +57,6 @@ def test_friends_unique_movies_not_duplicated(): assert HORROR_1 in friends_unique_movies assert INTRIGUE_3 in friends_unique_movies assert FANTASY_4 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 ********** # ************************************************************************************************** From 5905c529e1c865fc4fa7f19898a7a36f8446de47 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 30 Mar 2023 15:59:59 -0600 Subject: [PATCH 19/20] everything has been refactored --- viewing_party/party.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 7bdcefd67..227f39282 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -58,25 +58,24 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - -def get_unique_watched(user_data): - only_user_watched = [] - friends_watched =[] +def all_movies_friends_watched(user_data): + friends_watched = [] for item in user_data["friends"]: for movie in item["watched"]: friends_watched.append(movie) + return friends_watched + +def get_unique_watched(user_data): + user_unique_movies = [] + friends_watched = all_movies_friends_watched(user_data) for movie in user_data["watched"]: if movie not in friends_watched: - only_user_watched.append(movie) - return only_user_watched + user_unique_movies.append(movie) + return user_unique_movies def get_friends_unique_watched(user_data): - only_friends_watched = [] - friends_watched =[] - for item in user_data["friends"]: - for movie in item["watched"]: - friends_watched.append(movie) + friends_watched = all_movies_friends_watched(user_data) unique_movies = [] for movie in friends_watched: if movie not in user_data["watched"] and movie not in unique_movies: @@ -111,10 +110,7 @@ def get_new_rec_by_genre(user_data): return recommended_movies def get_rec_from_favorites(user_data): - friends_watched =[] - for item in user_data["friends"]: - for movie in item["watched"]: - friends_watched.append(movie) + friends_watched = all_movies_friends_watched(user_data) recommended_movies = [] for movie in user_data["favorites"]: if not movie in friends_watched: From 0c72f34bc1a8b69469c87fe094ef77d58a6de233 Mon Sep 17 00:00:00 2001 From: Nadia Mirzai Date: Thu, 30 Mar 2023 21:25:31 -0400 Subject: [PATCH 20/20] little changes --- viewing_party/party.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 227f39282..34b0168d9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,7 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - if title == None or genre == None or rating == None: + if title is None or genre is None or rating is None: return None movie = {"title": title, "genre": genre, "rating": rating} return movie @@ -31,7 +31,6 @@ def watch_movie(user_data, title): # ----------------------------------------- import statistics - def get_watched_avg_rating(user_data): try: @@ -42,6 +41,7 @@ def get_watched_avg_rating(user_data): number_of_movies += 1 average_rating = average_rating / number_of_movies return average_rating + except ZeroDivisionError: return 0.0 @@ -50,6 +50,7 @@ def get_most_watched_genre(user_data): genre = [] if user_data["watched"] == []: return None + for movie in user_data["watched"]: genre.append(movie["genre"]) return statistics.mode(genre) @@ -104,6 +105,7 @@ def get_new_rec_by_genre(user_data): unique_movies = get_friends_unique_watched(user_data) if most_frequently_watched is None: return [] + for movie in unique_movies: if movie["genre"] in most_frequently_watched: recommended_movies.append(movie)