From 78766a7ffd53815d100059e1c6857aa44cce6cb1 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Mon, 23 Sep 2024 13:58:49 -0400 Subject: [PATCH 01/24] README comment added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba28bf2ab..2cc534e3b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Viewing Party - +# vs code test ## Skills Assessed Solving problems with... From 315f252ef3b3b17e456d3121b6d7d59dbc9b16f1 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Mon, 23 Sep 2024 14:55:13 -0400 Subject: [PATCH 02/24] Created a movie dictionary --- viewing_party/party.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..3c5c334de 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,6 +1,50 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): + movie_dict = {} + + if not title or not genre or not rating: + print(None) + return None + else: + movie_dict['title'] = title + movie_dict['genre'] = genre + movie_dict['rating'] = rating + print(movie_dict) + + return movie_dict + +create_movie("happy feet", "Drama", 5) +create_movie("", "Drama", 5) + + + +# def add_to_watched(user_data, movie): +# # user_data +# # empty list = no movies wathced +# user_data = { +# "watched" : [ +# { + +# } +# ] +# } +# # return the user_data + +# user_data = {} + +# movie_info = create_movie(title, genre, rating) + +# user_data["watched"] = + + + + + +def add_to_watchlist(user_data, movie): + pass + +def watch_movie(user_data, title): pass # ----------------------------------------- From f90fb15e97c58de6d5b25ce0c26532abc83ee905 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Mon, 23 Sep 2024 14:57:44 -0400 Subject: [PATCH 03/24] Uncommented the skipped pytest --- tests/test_wave_01.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..f14908a49 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 @@ -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("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* From 202bf133abcfe55fcc73909021eacc5b66146b6c Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Mon, 23 Sep 2024 16:14:45 -0400 Subject: [PATCH 04/24] Wave 1: Updated add_to_watched and add_to_watchlist --- viewing_party/party.py | 64 +++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 3c5c334de..3ed44cccb 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -14,35 +14,49 @@ def create_movie(title, genre, rating): return movie_dict -create_movie("happy feet", "Drama", 5) -create_movie("", "Drama", 5) - - - -# def add_to_watched(user_data, movie): -# # user_data -# # empty list = no movies wathced -# user_data = { -# "watched" : [ -# { - -# } -# ] -# } -# # return the user_data - -# user_data = {} - -# movie_info = create_movie(title, genre, rating) - -# user_data["watched"] = - +def add_to_watched(user_data, movie): + # user_data + # empty list = no movies wathced + # user_data = { + # "watched" : [ + # { + # "title": "Title A", + # "genre": "Horror", + # "rating": 3.5 + # }, + # { + # "title": "Title A", + # "genre": "Horror", + # "rating": 3.5 + # }, + # { + # "title": "Title A", + # "genre": "Horror", + # "rating": 3.5 + # } + # ] + # } + # return the user_data + + user_data = { + "watched": [] + } + + user_data["watched"].append(movie) + + # print(user_data) + return user_data +def add_to_watchlist(user_data, movie): + user_data = { + "watchlist": [] + } + user_data["watchlist"].append(movie) -def add_to_watchlist(user_data, movie): - pass + # print(user_data) + return user_data def watch_movie(user_data, title): pass From b3a193788088fc10be2e5f48c38417076e377fa0 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Mon, 23 Sep 2024 16:16:01 -0400 Subject: [PATCH 05/24] Wave 1: commented pytest skips --- tests/test_wave_01.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index f14908a49..c332c1830 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -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,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" @@ -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 = { @@ -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() +# @pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { From b7d0e359272b39cf898deb9f8c34c2185aaa5a84 Mon Sep 17 00:00:00 2001 From: somy Date: Mon, 23 Sep 2024 17:08:21 -0700 Subject: [PATCH 06/24] deleted user_data dictionary and commented out pytest --- tests/test_wave_01.py | 4 ++-- viewing_party/party.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c332c1830..6e8ca32aa 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -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() +#@pytest.mark.skip() def test_adds_movie_to_non_empty_user_watched(): # 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() +#@pytest.mark.skip() def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 3ed44cccb..69a8d5f21 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -39,19 +39,21 @@ def add_to_watched(user_data, movie): # } # return the user_data - user_data = { - "watched": [] - } - user_data["watched"].append(movie) - # print(user_data) + #print(user_data) return user_data +# print(add_to_watched(user_data, movie)) + +print(add_to_watched({"watched": []}, { + "title": "Happy Feet", + "genre": "Drama", + "rating": 5 + })) + + def add_to_watchlist(user_data, movie): - user_data = { - "watchlist": [] - } user_data["watchlist"].append(movie) From b429f09fca932c2976ed96623037525c17564282 Mon Sep 17 00:00:00 2001 From: somy Date: Mon, 23 Sep 2024 20:27:54 -0700 Subject: [PATCH 07/24] added function to move movie from watchlist to watch. Commented out pytest --- tests/test_wave_01.py | 10 ++++++++-- viewing_party/party.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6e8ca32aa..a98a28e36 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() +#@pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -159,7 +159,13 @@ 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.") + if updated_data["watched"][0] != { + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 + }: + raise Exception("The movie was not moved to the watched.") + # ******************************************************************************************* # ****** 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 69a8d5f21..ca4b71df4 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -60,8 +60,44 @@ def add_to_watchlist(user_data, movie): # print(user_data) return user_data + + + + exa_data = { + "watchlist": [ + { + } + ], + "watched": [ + { + } + ] + } + + exa_data["watchlist"] == 0 + + def watch_movie(user_data, title): - pass + + # watchlist = add_to_watchlist(user_data, movie) + # watched = add_to_watched(user_data, movie) + + + + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watchlist"].remove(movie) + user_data["watched"].append(movie) + return user_data + + return user_data + + + #call function add_to_watched + #title is string + #list of "watched movies" + # if title is in watchlist add movie to watched and return user_data + # if title is not on watchlist return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- From 6462d29a4220f2e635c8d3348a1967967eb347a7 Mon Sep 17 00:00:00 2001 From: somy Date: Mon, 23 Sep 2024 20:46:48 -0700 Subject: [PATCH 08/24] added raise exceptions for pytest and deleted empty lines --- tests/test_wave_01.py | 7 ++++--- viewing_party/party.py | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index a98a28e36..0f58a85f1 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -170,7 +170,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -189,12 +189,13 @@ 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.") + if updated_data["watched"][1] != {FANTASY_1}: + 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 diff --git a/viewing_party/party.py b/viewing_party/party.py index ca4b71df4..ec2195006 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -82,8 +82,6 @@ def watch_movie(user_data, title): # watchlist = add_to_watchlist(user_data, movie) # watched = add_to_watched(user_data, movie) - - for movie in user_data["watchlist"]: if movie["title"] == title: user_data["watchlist"].remove(movie) From c6e27393bbccedbc1d6c1d7b513f642342c6bd73 Mon Sep 17 00:00:00 2001 From: somy Date: Tue, 24 Sep 2024 13:51:11 -0700 Subject: [PATCH 09/24] added function for wave 2 and commented out pytest --- tests/test_wave_02.py | 10 +++++----- viewing_party/party.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 19f045c79..ff8a229e4 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 ec2195006..54a3c52cb 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -100,12 +100,43 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + #user_data = {"watched": []} + if not user_data["watched"]: + return 0.0 + + total_rating = 0 + for movie in user_data["watched"]: + total_rating += movie["rating"] + + average = total_rating / len(user_data["watched"]) + + return average + + +def get_most_watched_genre(user_data): + genre_count = {"Fantasy": 0, "Intrigue": 0, "Action": 0} + + if not user_data["watched"]: + return None + + for movie in user_data["watched"]: + genre = movie["genre"] + if genre in genre_count: + genre_count[genre] += 1 + max_key = max(genre_count, key=genre_count.get) + + return max_key # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + + #user_data = {watched: [movies{}]} + #return a list of dictionaries that represents a list of movies # ----------------------------------------- # ------------- WAVE 4 -------------------- From b21fe8bd8098b36f7238abceb88cc31dc2e40a75 Mon Sep 17 00:00:00 2001 From: somy Date: Thu, 26 Sep 2024 08:39:58 -0700 Subject: [PATCH 10/24] uncomment pytest --- viewing_party/party.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 54a3c52cb..c9090e2b4 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -102,6 +102,9 @@ def watch_movie(user_data, title): # ----------------------------------------- def get_watched_avg_rating(user_data): #user_data = {"watched": []} + #if there are no movies then return 0.0 + #find average of ratings + if not user_data["watched"]: return 0.0 @@ -113,9 +116,9 @@ def get_watched_avg_rating(user_data): return average - + #find the most watched genre def get_most_watched_genre(user_data): - genre_count = {"Fantasy": 0, "Intrigue": 0, "Action": 0} + genre_count = {"Fantasy": 0, "Intrigue": 0, "Action": 0} #change method so that other genres can be included if not user_data["watched"]: return None @@ -133,15 +136,16 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -def get_unique_watched(user_data): - +# def get_unique_watched(user_data): + #user_data = {watched: [movies{}]} #return a list of dictionaries that represents a list of movies # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- - +def get_available_functions(user_data): + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- From 479cde93d94321f6d8afc49ac6bc6b370ed7694f Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Thu, 26 Sep 2024 16:34:03 -0400 Subject: [PATCH 11/24] Wave 3: added get_unique_watched and get_friends_unique_watched function definitions --- viewing_party/party.py | 78 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 54a3c52cb..91ab17bb7 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,3 +1,4 @@ +# from tests.test_constants import * # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): @@ -10,7 +11,7 @@ def create_movie(title, genre, rating): movie_dict['title'] = title movie_dict['genre'] = genre movie_dict['rating'] = rating - print(movie_dict) + # print(movie_dict) return movie_dict @@ -46,11 +47,11 @@ def add_to_watched(user_data, movie): # print(add_to_watched(user_data, movie)) -print(add_to_watched({"watched": []}, { - "title": "Happy Feet", - "genre": "Drama", - "rating": 5 - })) +# print(add_to_watched({"watched": []}, { +# "title": "Happy Feet", +# "genre": "Drama", +# "rating": 5 +# })) def add_to_watchlist(user_data, movie): @@ -132,8 +133,70 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - def get_unique_watched(user_data): + + + movies_not_watched_by_friends = [] + + for movie_watched_by_user in user_data["watched"]: + watched_by_any_friend = False + + # checks if the movie is has been watched by a friend + for friend in user_data["friends"]: + if movie_watched_by_user in friend["watched"]: + watched_by_any_friend = True + break + + # If no friend has watched it, adds it to the final list + if not watched_by_any_friend: + movies_not_watched_by_friends.append(movie_watched_by_user) + + print(movies_not_watched_by_friends) + return movies_not_watched_by_friends + +def get_friends_unique_watched(user_data): + + # user_data = { + # "watched": [ + # "FANTASY_1", + # "FANTASY_2", + # "FANTASY_3", + # "ACTION_1", + # "INTRIGUE_1", + # "INTRIGUE_2" + # ], + # "friends": [ + # { + # "watched": [ + # "FANTASY_1", + # "FANTASY_3", + # "FANTASY_4", + # "HORROR_1", + # ] + # }, + # { + # "watched": [ + # "FANTASY_1", + # "ACTION_1", + # "INTRIGUE_1", + # "INTRIGUE_3", + # ] + # } + # ] + # } + + movies_watched_by_friends_not_user = [] + + # Loops through each friend's watched list + for friend in user_data["friends"]: + for movie in friend["watched"]: + # Appends to list if 1) movie is not in the user's watched list and 2) not already in the result list + if movie not in user_data["watched"] and movie not in movies_watched_by_friends_not_user: + movies_watched_by_friends_not_user.append(movie) + + return movies_watched_by_friends_not_user + +# get_friends_unique_watched() #user_data = {watched: [movies{}]} #return a list of dictionaries that represents a list of movies @@ -146,3 +209,4 @@ def get_unique_watched(user_data): # ------------- WAVE 5 -------------------- # ----------------------------------------- + From 6d20cee0db25b96ccf5fa24b8dc243b848ebc113 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Thu, 26 Sep 2024 17:22:34 -0400 Subject: [PATCH 12/24] Wave 1: Uncommented the raise exception --- tests/test_wave_01.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 0f58a85f1..231ce5a15 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -189,8 +189,8 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - if updated_data["watched"][1] != {FANTASY_1}: - raise Exception("Test needs to be completed.") + # if updated_data["watched"][1] != FANTASY_1: + # raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* From 24b52d0cfaeafee2797b11623561e2208d385dcd Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Thu, 26 Sep 2024 17:24:13 -0400 Subject: [PATCH 13/24] Wave 3: added get_unique_watched(user_data) and get_friends_unique_watched(user_data) function defintions --- tests/test_wave_03.py | 12 ++++++------ viewing_party/party.py | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..e80cbe183 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,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() @@ -55,12 +55,12 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 - 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 91ab17bb7..591a9d4cc 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -61,21 +61,18 @@ def add_to_watchlist(user_data, movie): # print(user_data) return user_data + # exa_data = { + # "watchlist": [ + # { + # } + # ], + # "watched": [ + # { + # } + # ] + # } - - - exa_data = { - "watchlist": [ - { - } - ], - "watched": [ - { - } - ] - } - - exa_data["watchlist"] == 0 + # exa_data["watchlist"] == 0 def watch_movie(user_data, title): From 835be767011f0745a327a322b2985954ce8db968 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Thu, 26 Sep 2024 17:36:00 -0400 Subject: [PATCH 14/24] Wave 1: Added an assertion --- tests/test_wave_01.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 231ce5a15..71a53bfe5 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -188,6 +188,7 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 + assert updated_data["watched"][-1] == movie_to_watch # if updated_data["watched"][1] != FANTASY_1: # raise Exception("Test needs to be completed.") From dd25fa2760807836fd414f5682d53feadd39c22c Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Thu, 26 Sep 2024 17:54:31 -0400 Subject: [PATCH 15/24] Wave 3: Added assertions --- tests/test_wave_03.py | 3 +++ viewing_party/party.py | 55 ++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index e80cbe183..1a1d6fb61 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -54,6 +54,9 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 + assert FANTASY_4 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies # raise Exception("Test needs to be completed.") # ************************************************************************************************* diff --git a/viewing_party/party.py b/viewing_party/party.py index 591a9d4cc..5fb88f39b 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -153,6 +153,46 @@ def get_unique_watched(user_data): def get_friends_unique_watched(user_data): + friends_unique_movies = [] + + # Loops through each friend's watched list + for friend in user_data["friends"]: + for movie in friend["watched"]: + # Appends to list if 1) movie is not in the user's watched list and 2) not already in the result list + if movie not in user_data["watched"] and movie not in friends_unique_movies: + friends_unique_movies.append(movie) + + return friends_unique_movies + +print(get_friends_unique_watched( user_data = { + "watched": [ + "FANTASY_1", + "FANTASY_2", + "FANTASY_3", + "ACTION_1", + "INTRIGUE_1", + "INTRIGUE_2" + ], + "friends": [ + { + "watched": [ + "FANTASY_1", + "FANTASY_3", + "FANTASY_4", + "HORROR_1", + ] + }, + { + "watched": [ + "FANTASY_1", + "ACTION_1", + "INTRIGUE_1", + "INTRIGUE_3", + ] + } + ] + })) + # user_data = { # "watched": [ # "FANTASY_1", @@ -182,21 +222,6 @@ def get_friends_unique_watched(user_data): # ] # } - movies_watched_by_friends_not_user = [] - - # Loops through each friend's watched list - for friend in user_data["friends"]: - for movie in friend["watched"]: - # Appends to list if 1) movie is not in the user's watched list and 2) not already in the result list - if movie not in user_data["watched"] and movie not in movies_watched_by_friends_not_user: - movies_watched_by_friends_not_user.append(movie) - - return movies_watched_by_friends_not_user - -# get_friends_unique_watched() - - #user_data = {watched: [movies{}]} - #return a list of dictionaries that represents a list of movies # ----------------------------------------- # ------------- WAVE 4 -------------------- From de5c8866be6e749904189e9740027c8199f26a13 Mon Sep 17 00:00:00 2001 From: somy Date: Thu, 26 Sep 2024 14:59:21 -0700 Subject: [PATCH 16/24] added wave 4 functions and uncommented pytest --- tests/test_wave_01.py | 3 +-- viewing_party/party.py | 55 +++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 0f58a85f1..b1a45e4a8 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -189,8 +189,7 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - if updated_data["watched"][1] != {FANTASY_1}: - raise Exception("Test needs to be completed.") + assert updated_data["watchlist"]["title"] == # ******************************************************************************************* # ****** 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 c9090e2b4..0d7577ee1 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -46,11 +46,11 @@ def add_to_watched(user_data, movie): # print(add_to_watched(user_data, movie)) -print(add_to_watched({"watched": []}, { - "title": "Happy Feet", - "genre": "Drama", - "rating": 5 - })) +# print(add_to_watched({"watched": []}, { +# "title": "Happy Feet", +# "genre": "Drama", +# "rating": 5 +# })) def add_to_watchlist(user_data, movie): @@ -136,17 +136,48 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -# def get_unique_watched(user_data): - - #user_data = {watched: [movies{}]} - #return a list of dictionaries that represents a list of movies - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- -def get_available_functions(user_data): + +def get_available_recs(user_data): + subscriptions = set(user_data.get("subscriptions", [])) + + recommended_movies = set() # Using a set to ensure uniqueness + user_watched = set() # Track movies the user has already watched + + # Populate user_watched set with movie titles from user_data + for movie in user_data.get("watched"): + if "title" in movie: + user_watched.add(movie["title"]) + + # Loop through each friend and their watched movies + for friend in user_data.get("friends"): + for movie in friend.get("watched"): + # Only add the movie if it's hosted on a subscribed platform and not watched by the user + if movie["host"] in subscriptions and movie["title"] not in user_watched: + recommended_movies.add((movie["title"], movie["host"], movie["rating"], movie["genre"])) + + # Convert the set of tuples back to a list of dictionaries, including the 'genre' key + updated_recommendation = [ + {"title": title, "host": host, "rating": rating, "genre": genre} + for title, host, rating, genre in recommended_movies + ] + + return updated_recommendation + # list of recommended movies: user has not watched, + # at least one of the friends have watched + # host of movie service is not in user's subscriptions + + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- - +# def get_new_rec_by_genre(user_data): +# for user_data + #determine most frequently watched genre + #determine list of recommended movies + #user has not watched + #at least 1 of user friends watched + #"genre is most frequently watched drama \ No newline at end of file From 7531b596c2714fb0a2e6215eea88322b80e2c9ae Mon Sep 17 00:00:00 2001 From: somy Date: Thu, 26 Sep 2024 16:41:40 -0700 Subject: [PATCH 17/24] uncommented pytest --- tests/test_wave_04.py | 6 +++--- viewing_party/party.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..79ab18ff7 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 bc61f8718..d0aa81e9d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -47,11 +47,11 @@ def add_to_watched(user_data, movie): # print(add_to_watched(user_data, movie)) -# print(add_to_watched({"watched": []}, { -# "title": "Happy Feet", -# "genre": "Drama", -# "rating": 5 -# })) +# # print(add_to_watched({"watched": []}, { +# # "title": "Happy Feet", +# # "genre": "Drama", +# # "rating": 5 +# # })) def add_to_watchlist(user_data, movie): From 6f353d30f5357f6a9b924ef8541a391820eb6604 Mon Sep 17 00:00:00 2001 From: somy Date: Thu, 26 Sep 2024 20:47:46 -0700 Subject: [PATCH 18/24] added function 1 for wave 5 and new file for testing functions --- tests/test_wave_05.py | 14 +++--- viewing_party/party.py | 41 ++++++++++++++++- viewing_party/test | 100 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 viewing_party/test diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..bec9c9ab7 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 = { @@ -53,12 +53,12 @@ def test_new_genre_rec_from_empty_friends(): ] } - 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 +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 = { @@ -94,7 +94,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 d0aa81e9d..6241ecb1e 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -134,7 +134,7 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -def get_unique_watched(user_data): +# def get_unique_watched(user_data): #user_data = {watched: [movies{}]} #return a list of dictionaries that represents a list of movies @@ -177,4 +177,43 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + #Determine the user's most frequently watched genre + watched_movies = user_data["watched"] + if not watched_movies: + return [] # If there are no watched movies, return an empty list + + # Count the genres of watched movies + genre_counter = {} + for movie in watched_movies: + genre = movie["genre"] + if genre not in genre_counter: + genre_counter[genre] = 0 + genre_counter[genre] += 1 + + # Get the most common genre + top_genre = max(genre_counter, key=genre_counter.get) + + recommendations = [] # List to store recommendations + watched_titles = [] # List to store titles the user has watched + + for movie in watched_movies: + watched_titles.append(movie["title"]) + + for friend in user_data["friends"]: + for movie in friend["watched"]: + if (movie["genre"] == top_genre and + movie["title"] not in watched_titles): + # Check for duplicates + if movie not in recommendations: + recommendations.append(movie) + + return recommendations + +# Function 2 for wave 5 +# def get_rec_from_favorites(user_data): +# for favorites in user_data["favorites"]: #movie = list of favorite movies +# for + +# return recommendation diff --git a/viewing_party/test b/viewing_party/test new file mode 100644 index 000000000..25e1e1553 --- /dev/null +++ b/viewing_party/test @@ -0,0 +1,100 @@ +# # def get_new_rec_by_genre(user_data): +# # # Determine user's most frequently watched genre +# # genre_counter = {} +# # recommendations = [] + +# # # Count the genres from the user's favorites (or watched) movies +# # for movie in user_data.get("favorites"): +# # genre = movie["genre"] +# # if genre not in genre_counter: +# # genre_counter[genre] = 0 +# # genre_counter[genre] += 1 + +# # # If no favorites, return an empty recommendation list +# # if not genre_counter: +# # return recommendations # Return empty list + +# # # Identify the top genre +# # top_genre = max(genre_counter, key=genre_counter.get) + +# # # Recommend movies from friends that match the top genre and are not in user's favorites +# # for friend in user_data.get("friends"): +# # for movie in friend.get("watched"): +# # if movie["genre"] == top_genre and movie not in user_data["favorites"]and movie not in recommendations: +# # recommendations.append(movie) # Add movie to recommendations if it's not a duplicate + +# # return recommendations +# ======================================== +# def get_new_rec_by_genre(user_data): +# #determine users most frequently watched genre +# genre_counter = {} +# recommendations = [] +# for movie in user_data["movie"]: +# genre = movie["genre"] +# if genre not in genre_counter: +# genre_counter[genre] = 0 +# genre_counter[genre] += 1 +# top_genre = max(genre_counter, key=genre_counter.get) + +# for friend in user_data["friends"]: +# for movie in friend["watched"]: +# if movie["genre"] == top_genre and movie not in user_data["watched"]: +# recommendations.append(movie) + +# return recommendations +# get_new_rec_by_genre( +# { +# "watched": [{...}, {...}, {...}, {...}, {...}, {...}], +# "friends": [{...}, {...}], +# "subscriptions": ["netflix", "hulu"], +# "favorites": [{...}, {...}, {...}, {...}], +# } +# ) +def get_new_rec_by_genre(user_data): + # genre_counter = {} + # recommendations = [] + for movie in user_data["favorites"]: + # genre = user_data["watched"] + print(movie) + # if genre not in genre_counter: + # genre_counter[genre] = 0 + # genre_counter[genre] += 1 + # top_genre = max(genre_counter, key=genre_counter.get) + + # for friend in user_data["friends"]: + # for movie in friend["watched"]: + # if movie["genre"] == top_genre and movie not in user_data["watched"]: + # recommendations.append(movie) + + # return recommendations + + return (print(movie)) +get_new_rec_by_genre( { + "watched": [{ + "title": "MOVIE_TITLE_1", + "genre": "GENRE_1", + "rating": "RATING_1" + }, + { + "title": "The Lord of the Functions: The Fellowship of the Function", + "genre": "Fantasy", + "rating": 4.8 + }], + "subscriptions":["netflix", "hulu"], + "friends":[ + { + "watched": [ + { + "title": "The Lord of the Functions: The Fellowship of the Function", + "genre": "Fantasy", + "rating": 4.8 + }, + { + "title": "The Programmer: An Unexpected Stack Trace", + "genre": "Fantasy", + "rating": 4.0 + } + ] + } + ] +}) \ No newline at end of file From 2132055d4260b874591077e2f64e468bd2c14f8b Mon Sep 17 00:00:00 2001 From: somy Date: Thu, 26 Sep 2024 20:51:48 -0700 Subject: [PATCH 19/24] added function 2 of wave 5 --- viewing_party/party.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6241ecb1e..6524c10b9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -211,9 +211,19 @@ def get_new_rec_by_genre(user_data): return recommendations # Function 2 for wave 5 -# def get_rec_from_favorites(user_data): -# for favorites in user_data["favorites"]: #movie = list of favorite movies -# for -# return recommendation +def get_rec_from_favorites(user_data): + favorites = user_data.get("favorites") + friends_watched_titles = [] + for friend in user_data.get("friends"): + for movie in friend.get("watched"): + friends_watched_titles.append(movie["title"]) + + recommendations = [] + + for movie in favorites: + if movie["title"] not in friends_watched_titles: + recommendations.append(movie) + + return recommendations \ No newline at end of file From 1dc159bd8919033d5702ea660d02d87c824b24d3 Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Fri, 27 Sep 2024 10:08:51 -0400 Subject: [PATCH 20/24] Wave 3: added functions --- viewing_party/party.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index d0aa81e9d..6e7120a98 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -135,9 +135,37 @@ def get_most_watched_genre(user_data): # ----------------------------------------- def get_unique_watched(user_data): + + movies_not_watched_by_friends = [] + + for movie_watched_by_user in user_data["watched"]: + watched_by_any_friend = False + + # checks if the movie is has been watched by a friend + for friend in user_data["friends"]: + if movie_watched_by_user in friend["watched"]: + watched_by_any_friend = True + break + + # If no friend has watched it, adds it to the final list + if not watched_by_any_friend: + movies_not_watched_by_friends.append(movie_watched_by_user) - #user_data = {watched: [movies{}]} - #return a list of dictionaries that represents a list of movies + print(movies_not_watched_by_friends) + return movies_not_watched_by_friends + +def get_friends_unique_watched(user_data): + + movies_watched_by_friends_not_user = [] + + # loops through each friend's watched list + for friend in user_data["friends"]: + for movie in friend["watched"]: + # appends to list if 1) movie is not in the user's watched list and 2) not already in the result list + if movie not in user_data["watched"] and movie not in movies_watched_by_friends_not_user: + movies_watched_by_friends_not_user.append(movie) + + return movies_watched_by_friends_not_user # ----------------------------------------- # ------------- WAVE 4 -------------------- @@ -178,3 +206,5 @@ def get_available_recs(user_data): # ------------- WAVE 5 -------------------- # ----------------------------------------- + + From 06db27bdfd277b1122482afd9d754dd22ae742e1 Mon Sep 17 00:00:00 2001 From: somy Date: Fri, 27 Sep 2024 07:51:48 -0700 Subject: [PATCH 21/24] added function 2 of wave 5 and uncommented pytest --- tests/test_wave_05.py | 4 ++++ viewing_party/party.py | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index bec9c9ab7..3a93b06f4 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -52,7 +52,11 @@ def test_new_genre_rec_from_empty_friends(): } ] } + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + # Assert + assert len(recommendations) == 0 # raise Exception("Test needs to be completed.") # ********************************************************************* # ****** Complete the Act and Assert Portions of these tests ********** diff --git a/viewing_party/party.py b/viewing_party/party.py index 6524c10b9..200548e1e 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -144,10 +144,10 @@ def get_most_watched_genre(user_data): # ----------------------------------------- def get_available_recs(user_data): - subscriptions = set(user_data.get("subscriptions", [])) + subscriptions = set(user_data["subscriptions"]) - recommended_movies = set() # Using a set to ensure uniqueness - user_watched = set() # Track movies the user has already watched + recommended_movies = set() + user_watched = set() # Populate user_watched set with movie titles from user_data for movie in user_data.get("watched"): @@ -161,7 +161,7 @@ def get_available_recs(user_data): if movie["host"] in subscriptions and movie["title"] not in user_watched: recommended_movies.add((movie["title"], movie["host"], movie["rating"], movie["genre"])) - # Convert the set of tuples back to a list of dictionaries, including the 'genre' key + # Convert to a list of dictionaries updated_recommendation = [ {"title": title, "host": host, "rating": rating, "genre": genre} for title, host, rating, genre in recommended_movies @@ -213,15 +213,18 @@ def get_new_rec_by_genre(user_data): # Function 2 for wave 5 def get_rec_from_favorites(user_data): - favorites = user_data.get("favorites") - friends_watched_titles = [] - for friend in user_data.get("friends"): - for movie in friend.get("watched"): - friends_watched_titles.append(movie["title"]) + favorites = user_data["favorites"] + if not favorites: + return [] + friends_watched_titles = [] recommendations = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_watched_titles.append(movie["title"]) + for movie in favorites: if movie["title"] not in friends_watched_titles: recommendations.append(movie) From 4d8ac3dd4b18ca0f4e013153f50a5213a165caca Mon Sep 17 00:00:00 2001 From: somy Date: Fri, 27 Sep 2024 08:04:31 -0700 Subject: [PATCH 22/24] deleted comments for changes and testing --- viewing_party/party.py | 272 +---------------------------------------- 1 file changed, 4 insertions(+), 268 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 3a92e15ca..ca4741526 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -17,69 +17,19 @@ def create_movie(title, genre, rating): def add_to_watched(user_data, movie): - # user_data - # empty list = no movies wathced - # user_data = { - # "watched" : [ - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # }, - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # }, - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # } - # ] - # } - # return the user_data user_data["watched"].append(movie) - #print(user_data) return user_data -# print(add_to_watched(user_data, movie)) - -# # print(add_to_watched({"watched": []}, { -# # "title": "Happy Feet", -# # "genre": "Drama", -# # "rating": 5 -# # })) - - def add_to_watchlist(user_data, movie): user_data["watchlist"].append(movie) - # print(user_data) return user_data - # exa_data = { - # "watchlist": [ - # { - # } - # ], - # "watched": [ - # { - # } - # ] - # } - - # exa_data["watchlist"] == 0 - - def watch_movie(user_data, title): - # watchlist = add_to_watchlist(user_data, movie) - # watched = add_to_watched(user_data, movie) - for movie in user_data["watchlist"]: if movie["title"] == title: user_data["watchlist"].remove(movie) @@ -98,11 +48,12 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- -def get_watched_avg_rating(user_data): #user_data = {"watched": []} #if there are no movies then return 0.0 #find average of ratings +def get_watched_avg_rating(user_data): + if not user_data["watched"]: return 0.0 @@ -125,9 +76,9 @@ def get_most_watched_genre(user_data): genre = movie["genre"] if genre in genre_count: genre_count[genre] += 1 - max_key = max(genre_count, key=genre_count.get) + top_genre = max(genre_count, key=genre_count.get) - return max_key + return top_genre # ----------------------------------------- @@ -200,222 +151,7 @@ def get_available_recs(user_data): # list of recommended movies: user has not watched, # at least one of the friends have watched # host of movie service is not in user's subscriptions - - -# ----------------------------------------- -# ------------- WAVE 5 -------------------- -# ----------------------------------------- - - - -# from tests.test_constants import * -# ------------- WAVE 1 -------------------- - -def create_movie(title, genre, rating): - movie_dict = {} - - if not title or not genre or not rating: - print(None) - return None - else: - movie_dict['title'] = title - movie_dict['genre'] = genre - movie_dict['rating'] = rating - # print(movie_dict) - - return movie_dict - - -def add_to_watched(user_data, movie): - # user_data - # empty list = no movies wathced - # user_data = { - # "watched" : [ - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # }, - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # }, - # { - # "title": "Title A", - # "genre": "Horror", - # "rating": 3.5 - # } - # ] - # } - # return the user_data - - user_data["watched"].append(movie) - - #print(user_data) - return user_data - -# print(add_to_watched(user_data, movie)) - -# # print(add_to_watched({"watched": []}, { -# # "title": "Happy Feet", -# # "genre": "Drama", -# # "rating": 5 -# # })) - - -def add_to_watchlist(user_data, movie): - - user_data["watchlist"].append(movie) - - # print(user_data) - return user_data - - # exa_data = { - # "watchlist": [ - # { - # } - # ], - # "watched": [ - # { - # } - # ] - # } - - # exa_data["watchlist"] == 0 - - -def watch_movie(user_data, title): - - # watchlist = add_to_watchlist(user_data, movie) - # watched = add_to_watched(user_data, movie) - - for movie in user_data["watchlist"]: - if movie["title"] == title: - user_data["watchlist"].remove(movie) - user_data["watched"].append(movie) - return user_data - - return user_data - - - #call function add_to_watched - #title is string - #list of "watched movies" - # if title is in watchlist add movie to watched and return user_data - # if title is not on watchlist return user_data - -# ----------------------------------------- -# ------------- WAVE 2 -------------------- -# ----------------------------------------- -def get_watched_avg_rating(user_data): - #user_data = {"watched": []} - #if there are no movies then return 0.0 - #find average of ratings - - if not user_data["watched"]: - return 0.0 - - total_rating = 0 - for movie in user_data["watched"]: - total_rating += movie["rating"] - - average = total_rating / len(user_data["watched"]) - - return average - - #find the most watched genre -def get_most_watched_genre(user_data): - genre_count = {"Fantasy": 0, "Intrigue": 0, "Action": 0} #change method so that other genres can be included - - if not user_data["watched"]: - return None - - for movie in user_data["watched"]: - genre = movie["genre"] - if genre in genre_count: - genre_count[genre] += 1 - max_key = max(genre_count, key=genre_count.get) - - return max_key - - -# ----------------------------------------- -# ------------- WAVE 3 -------------------- -# ----------------------------------------- -def get_unique_watched(user_data): - - movies_not_watched_by_friends = [] - - for movie_watched_by_user in user_data["watched"]: - watched_by_any_friend = False - - # checks if the movie is has been watched by a friend - for friend in user_data["friends"]: - if movie_watched_by_user in friend["watched"]: - watched_by_any_friend = True - break - - # If no friend has watched it, adds it to the final list - if not watched_by_any_friend: - movies_not_watched_by_friends.append(movie_watched_by_user) - - print(movies_not_watched_by_friends) - return movies_not_watched_by_friends - -def get_friends_unique_watched(user_data): - - movies_watched_by_friends_not_user = [] - - # loops through each friend's watched list - for friend in user_data["friends"]: - for movie in friend["watched"]: - # appends to list if 1) movie is not in the user's watched list and 2) not already in the result list - if movie not in user_data["watched"] and movie not in movies_watched_by_friends_not_user: - movies_watched_by_friends_not_user.append(movie) - - return movies_watched_by_friends_not_user -# def get_unique_watched(user_data): - - #user_data = {watched: [movies{}]} - #return a list of dictionaries that represents a list of movies - -# ----------------------------------------- -# ------------- WAVE 4 -------------------- -# ----------------------------------------- - -def get_available_recs(user_data): - subscriptions = set(user_data["subscriptions"]) - - recommended_movies = set() - user_watched = set() - - # Populate user_watched set with movie titles from user_data - for movie in user_data.get("watched"): - if "title" in movie: - user_watched.add(movie["title"]) - - # Loop through each friend and their watched movies - for friend in user_data.get("friends"): - for movie in friend.get("watched"): - # Only add the movie if it's hosted on a subscribed platform and not watched by the user - if movie["host"] in subscriptions and movie["title"] not in user_watched: - recommended_movies.add((movie["title"], movie["host"], movie["rating"], movie["genre"])) - - # Convert to a list of dictionaries - updated_recommendation = [ - {"title": title, "host": host, "rating": rating, "genre": genre} - for title, host, rating, genre in recommended_movies - ] - - return updated_recommendation - - # list of recommended movies: user has not watched, - # at least one of the friends have watched - # host of movie service is not in user's subscriptions - - # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- From 3959e3aba0f5a80fdb857556bfb097ca69815f5a Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Fri, 27 Sep 2024 12:11:22 -0400 Subject: [PATCH 23/24] Cleaned up the code by removing the pseudocode. --- viewing_party/party.py | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index ca4741526..347da6db2 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,31 +1,27 @@ -# from tests.test_constants import * # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): movie_dict = {} if not title or not genre or not rating: - print(None) return None else: movie_dict['title'] = title movie_dict['genre'] = genre movie_dict['rating'] = rating - # print(movie_dict) 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): @@ -37,21 +33,11 @@ def watch_movie(user_data, title): return user_data return user_data - - - #call function add_to_watched - #title is string - #list of "watched movies" - # if title is in watchlist add movie to watched and return user_data - # if title is not on watchlist return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- - #user_data = {"watched": []} - #if there are no movies then return 0.0 - #find average of ratings - + def get_watched_avg_rating(user_data): if not user_data["watched"]: @@ -65,7 +51,6 @@ def get_watched_avg_rating(user_data): return average - #find the most watched genre def get_most_watched_genre(user_data): genre_count = {"Fantasy": 0, "Intrigue": 0, "Action": 0} #change method so that other genres can be included @@ -80,11 +65,9 @@ def get_most_watched_genre(user_data): return top_genre - # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - def get_unique_watched(user_data): movies_not_watched_by_friends = [] @@ -102,7 +85,6 @@ def get_unique_watched(user_data): if not watched_by_any_friend: movies_not_watched_by_friends.append(movie_watched_by_user) - print(movies_not_watched_by_friends) return movies_not_watched_by_friends def get_friends_unique_watched(user_data): @@ -147,16 +129,11 @@ def get_available_recs(user_data): ] return updated_recommendation - - # list of recommended movies: user has not watched, - # at least one of the friends have watched - # host of movie service is not in user's subscriptions # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- def get_new_rec_by_genre(user_data): - #Determine the user's most frequently watched genre watched_movies = user_data["watched"] if not watched_movies: return [] # If there are no watched movies, return an empty list @@ -188,8 +165,6 @@ def get_new_rec_by_genre(user_data): return recommendations -# Function 2 for wave 5 - def get_rec_from_favorites(user_data): favorites = user_data["favorites"] From ef3a9e856449bcaa6bbde9458c47eb923ebe8e4c Mon Sep 17 00:00:00 2001 From: Christelle Nkera Date: Fri, 27 Sep 2024 13:18:38 -0400 Subject: [PATCH 24/24] Wave 1: added a break to the watch_movie() function --- viewing_party/party.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 347da6db2..c6ab242aa 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -30,8 +30,7 @@ def watch_movie(user_data, title): if movie["title"] == title: user_data["watchlist"].remove(movie) user_data["watched"].append(movie) - return user_data - + break return user_data # -----------------------------------------