From f2793f40cd8b9adb576fec43dd6451b52f8d1492 Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 11:57:02 -0700 Subject: [PATCH 01/30] modified readme file to add agreements --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index ba28bf2ab..0e8927822 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # Viewing Party +Fork and Clone -- Complete +Virtual Enviroment -- Complete +Dependencies -- Complete +Comment -- Setting up + +Access needs -- in-person/zoom, maybe mornings +Your learning style -- bringing ideas together and setting goals for working independently +Feedback -- email/slack, in-person +Communcation skill you want to improve with this experience -- meeting with people to improve communication + speaking redundantly, understanding google code + +Wave 01 -- Mon +Wave 02 -- Tues +Wave 03 -- Tues +Wave 04 -- Wed +Wave 05 -- Thurs +Turn in Friday 10am + + ## Skills Assessed Solving problems with... From 2168192294903d7b3188aa31fb16718810a946ae Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Mon, 27 Mar 2023 14:41:31 -0700 Subject: [PATCH 02/30] added function names for wave1 with pass statements for each --- viewing_party/party.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..3b5bbe079 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,8 +1,23 @@ +MOVIE_TITLE_1 = "It Came from the Stack Trace" +GENRE_1 = "Horror" +RATING_1 = 3.5 # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): + if not title or genre or rating: + return None + +def add_to_watched(user_data, movie): + pass + +def add_to_watchlist(user_data, movie): pass +def watch_movie(user_data, title): + pass + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- From a3df68ca247667ae81abdb65757fdbd8f53b3d0e Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 15:22:17 -0700 Subject: [PATCH 03/30] wave 01 function 01 --- tests/test_wave_01.py | 23 ++++++++++++----------- viewing_party/party.py | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 669efee6a..197601fa4 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] == 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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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,12 +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.") # ******************************************************************************************* # ****** 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 @@ -188,7 +189,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() +#@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 3b5bbe079..c7c200783 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -6,6 +6,8 @@ def create_movie(title, genre, rating): if not title or genre or rating: return None + movie_dict = {"title":"", "genre":"", "rating":""} + return movie_dict def add_to_watched(user_data, movie): pass From e721b55c20db98ad679777b399420749a0989cd4 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Mon, 27 Mar 2023 15:45:49 -0700 Subject: [PATCH 04/30] not skipping wave 1 tests --- viewing_party/party.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/viewing_party/party.py b/viewing_party/party.py index 3b5bbe079..b80062d7c 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -4,8 +4,13 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): + ''' + input: title, genre, rating + output: + ''' if not title or genre or rating: return None + movie_dict = {} def add_to_watched(user_data, movie): pass From ddce7ed5e5fa973bde22dc15600e1c60d4c5ff31 Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 16:00:01 -0700 Subject: [PATCH 05/30] wave 01 second function --- viewing_party/party.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index c7c200783..452b5f7b6 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -10,7 +10,14 @@ def create_movie(title, genre, rating): return movie_dict def add_to_watched(user_data, movie): - pass + #user_data is a dict with key "watched" + movies_user_has_watched = user_data["watched"] + # a list of dicts rep the movies the user has watched + # append (represent) movie to list of dict + movies_user_has_watched.append(movie) + #add movie to the "movies_user_has_watched" inside of user data + + return user_data def add_to_watchlist(user_data, movie): pass From c64dedcb4de693bb09d8ee973f778991df462353 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Mon, 27 Mar 2023 18:33:07 -0700 Subject: [PATCH 06/30] create_movie function passes tests and outputs dictionary --- viewing_party/party.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 022168857..be1aa58cc 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -6,11 +6,16 @@ def create_movie(title, genre, rating): ''' input: title, genre, rating - output: + output: dictionary ''' - if not title or genre or rating: + if not title: return None - movie_dict = {"title":"", "genre":"", "rating":""} + if not genre: + return None + if not rating: + return None + + movie_dict = {'title': title, 'genre': genre, 'rating': rating} return movie_dict def add_to_watched(user_data, movie): From 8eb5559a787f2b8728923790d902d83d9c37a8fa Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Mon, 27 Mar 2023 19:30:37 -0700 Subject: [PATCH 07/30] added watch_movie function to wave_01 - passing 7 tests --- viewing_party/party.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index be1aa58cc..c97b8b5f9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -32,8 +32,24 @@ def add_to_watchlist(user_data, movie): pass def watch_movie(user_data, title): - pass - + ''' + input: user_data is a dictionary with a "watchlist" and a "watched" list of movies; + title is a string representing the title of the movie the user has watched + output: user_data + ''' + #If title in user's watchlist + # remove movie from watchlist + # add to movies watched + # return user_data + #if not title in user's watchlist + # return user_data + if not title in user_data: + return user_data + + if title in user_data: + user_data.remove(title) + user_data.append(title) + return user_data # ----------------------------------------- From 1930e435c679c350080559f31d40e8447c9980c7 Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 19:55:45 -0700 Subject: [PATCH 08/30] not sure but terminal says to --- viewing_party/party.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index c97b8b5f9..3a5216c9c 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -8,13 +8,7 @@ def create_movie(title, genre, rating): input: title, genre, rating output: dictionary ''' - if not title: - return None - if not genre: - return None - if not rating: - return None - + movie_dict = {'title': title, 'genre': genre, 'rating': rating} return movie_dict @@ -29,12 +23,12 @@ def add_to_watched(user_data, movie): return user_data def add_to_watchlist(user_data, movie): - pass + def watch_movie(user_data, title): ''' input: user_data is a dictionary with a "watchlist" and a "watched" list of movies; - title is a string representing the title of the movie the user has watched + title is a string representing the title of the movie the user has watched output: user_data ''' #If title in user's watchlist From 387fb5f4a7b799fbf24febc36c5ba9bed91a59a4 Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 20:26:35 -0700 Subject: [PATCH 09/30] wave 01 3/4 complete --- viewing_party/party.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 3a5216c9c..aba06a620 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -8,9 +8,18 @@ def create_movie(title, genre, rating): input: title, genre, rating output: dictionary ''' - + if not title: + return None + if not genre: + return None + if not rating: + return None + movie_dict = {'title': title, 'genre': genre, 'rating': rating} + if movie_dict == False: + return None return movie_dict + def add_to_watched(user_data, movie): #user_data is a dict with key "watched" @@ -23,7 +32,17 @@ def add_to_watched(user_data, movie): return user_data def add_to_watchlist(user_data, movie): - + # user_data is a dict with key "watchlist" + movies_user_wants_to_watch = user_data["watchlist"] + + # an empty list rep that the user has no movies in their watchlist + movies_user_wants_to_watch = [] + # a list of dicts rep the movies the user has watched + # append (represent) movie to list of dict + movies_user_wants_to_watch.append(movie) + + + return user_data def watch_movie(user_data, title): ''' From f19b8da432880ef4cb9ea0d69506148a726453d2 Mon Sep 17 00:00:00 2001 From: Edith Date: Mon, 27 Mar 2023 21:00:05 -0700 Subject: [PATCH 10/30] function 3 complete? --- viewing_party/party.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index aba06a620..c88dee2d4 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -34,9 +34,9 @@ def add_to_watched(user_data, movie): def add_to_watchlist(user_data, movie): # user_data is a dict with key "watchlist" movies_user_wants_to_watch = user_data["watchlist"] - + if movies_user_wants_to_watch is None: # an empty list rep that the user has no movies in their watchlist - movies_user_wants_to_watch = [] + movies_user_wants_to_watch = [] # a list of dicts rep the movies the user has watched # append (represent) movie to list of dict movies_user_wants_to_watch.append(movie) @@ -44,6 +44,7 @@ def add_to_watchlist(user_data, movie): return user_data + def watch_movie(user_data, title): ''' input: user_data is a dictionary with a "watchlist" and a "watched" list of movies; From ef5776d1366a93cbde6419ca6b7cc80c8a38d0a1 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Mon, 27 Mar 2023 21:15:59 -0700 Subject: [PATCH 11/30] added indexing statements for watch_movie --- viewing_party/party.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index c88dee2d4..124416ff2 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -51,18 +51,12 @@ def watch_movie(user_data, title): title is a string representing the title of the movie the user has watched output: user_data ''' - #If title in user's watchlist - # remove movie from watchlist - # add to movies watched - # return user_data - #if not title in user's watchlist - # return user_data if not title in user_data: return user_data if title in user_data: - user_data.remove(title) - user_data.append(title) + user_data.remove(title['watchlist']) + user_data.append(title['watched']) return user_data From a914a33d25e1a8e471df6661d57aade163931cd5 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Tue, 28 Mar 2023 13:25:40 -0700 Subject: [PATCH 12/30] added wave02 function skeletons with parameters and doc strings for inputs/outputs --- viewing_party/party.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 124416ff2..8d4d984b9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -63,8 +63,22 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries + # calculate the average rating of all movies in the watched list + # an empty "watched" list has a value of 0.0 + output: average rating + ''' - +def get_most_watched_genre(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries. + # each movie dictionary has a key 'genre' which is a string + # determine which genre is the most frequently occurring in the 'watched' list + # if the value of 'watched' is an empty string, function should return None + output: genre that's most frequently watched + ''' # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- From 520d0179b97037565c01b8daf0077c423181e59b Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Tue, 28 Mar 2023 13:49:45 -0700 Subject: [PATCH 13/30] added assert statement to testwave01 --- tests/test_wave_01.py | 14 +++++++++----- tests/test_wave_02.py | 10 +++++----- viewing_party/party.py | 11 +++++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 197601fa4..b1a81fbd7 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -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 = { @@ -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() failing - needs to add assertions def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -164,8 +164,10 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* + #assert updated_data["watchlist"] == + #assert updated_data["watched"] == FANTASY_1, FANTASY_2 -#@pytest.mark.skip() +#@pytest.mark.skip() - failing - need to add assertions def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -184,12 +186,14 @@ 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.") + # raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* + assert updated_data["watchlist"] == [FANTASY_1] + assert updated_data["watched"] == [movie_to_watch, FANTASY_2] -#@pytest.mark.skip() +#@pytest.mark.skip() #passing def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 19f045c79..64b62729d 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +27,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +39,7 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre_order_mixed(): # Arrange janes_data = clean_wave_2b_data() @@ -51,7 +51,7 @@ def test_most_watched_genre_order_mixed(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2b_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 8d4d984b9..3ed897506 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,6 +1,4 @@ -MOVIE_TITLE_1 = "It Came from the Stack Trace" -GENRE_1 = "Horror" -RATING_1 = 3.5 + # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): @@ -70,7 +68,11 @@ def get_watched_avg_rating(user_data): # an empty "watched" list has a value of 0.0 output: average rating ''' - +# HORROR_1 = { +# "title": MOVIE_TITLE_1, +# "genre": GENRE_1, +# "rating": RATING_1 +# } def get_most_watched_genre(user_data): ''' input: user_data is a dictionary with a "watched" list of movies dictionaries. @@ -79,6 +81,7 @@ def get_most_watched_genre(user_data): # if the value of 'watched' is an empty string, function should return None output: genre that's most frequently watched ''' + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- From 54ba447d21d9be1c407f6ccf3dd04a74aae55e59 Mon Sep 17 00:00:00 2001 From: Edith Date: Tue, 28 Mar 2023 13:58:32 -0700 Subject: [PATCH 14/30] 10 passed tests --- tests/test_wave_01.py | 6 +++--- viewing_party/party.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index b1a81fbd7..ab0a1cb56 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -160,12 +160,12 @@ def test_moves_movie_from_watchlist_to_empty_watched(): 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" ********** # ******************************************************************************************* - #assert updated_data["watchlist"] == - #assert updated_data["watched"] == FANTASY_1, FANTASY_2 + assert updated_data["watchlist"] == None + assert updated_data["watched"] == [MOVIE_TITLE_1] #@pytest.mark.skip() - failing - need to add assertions def test_moves_movie_from_watchlist_to_watched(): diff --git a/viewing_party/party.py b/viewing_party/party.py index 3ed897506..71f1d5e28 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -62,18 +62,21 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- def get_watched_avg_rating(user_data): + pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries # calculate the average rating of all movies in the watched list # an empty "watched" list has a value of 0.0 output: average rating ''' -# HORROR_1 = { -# "title": MOVIE_TITLE_1, -# "genre": GENRE_1, -# "rating": RATING_1 + # #user_data is a dict with "watched" list of dict + # user_list_of_watched_movies = user_data["watched"] + # #calc th avg rating of all movies in the watched list + # for i in range(len(user_data)): + # sum(user_list_of_watched_movies) # } def get_most_watched_genre(user_data): + pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries. # each movie dictionary has a key 'genre' which is a string From 35f3b8f273e1e1c26fbcc91b1e1649550ccd8bd9 Mon Sep 17 00:00:00 2001 From: Edith Date: Tue, 28 Mar 2023 17:05:01 -0700 Subject: [PATCH 15/30] wave 01 success git commit -m 'wave 01 success!' q exit / --- tests/test_wave_01.py | 7 ++++--- viewing_party/party.py | 47 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ab0a1cb56..5852086a1 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -164,8 +164,8 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* - assert updated_data["watchlist"] == None - assert updated_data["watched"] == [MOVIE_TITLE_1] + assert updated_data["watched"] == [{ "title": MOVIE_TITLE_1, "genre": GENRE_1, + "rating": RATING_1 }] #@pytest.mark.skip() - failing - need to add assertions def test_moves_movie_from_watchlist_to_watched(): @@ -191,7 +191,8 @@ def test_moves_movie_from_watchlist_to_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* assert updated_data["watchlist"] == [FANTASY_1] - assert updated_data["watched"] == [movie_to_watch, FANTASY_2] + assert updated_data["watched"] == [FANTASY_2, movie_to_watch] + # order matters ie FANTASY_2, movie_to_watch #@pytest.mark.skip() #passing def test_does_nothing_if_movie_not_in_watchlist(): diff --git a/viewing_party/party.py b/viewing_party/party.py index 71f1d5e28..fa35b0ab2 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -49,13 +49,48 @@ def watch_movie(user_data, title): title is a string representing the title of the movie the user has watched output: user_data ''' - if not title in user_data: - return user_data + # if not title in user_data: + # return user_data + # value user_data dictionary with "watchlist" + user_watchlist_movies = user_data["watchlist"] + # value user_data dictionary with "watched" + watched_movies = user_data["watched"] + # this represents the title of the movie the user has watched + for watchlist_dict in user_watchlist_movies: + # if this title is in the users watchlist + # is title = title of watch_dict + if title == watchlist_dict['title']: + user_watchlist_movies.remove(watchlist_dict) + watched_movies.append(watchlist_dict) + return user_data + + # value of key called title + +# If the title is in a movie in the user's watchlist: +# remove that movie from the watchlist +# add that movie to watched +# return the user_data + +#Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions +# should not modify user_data. .copy() or .deepcopy() possibly + + + + # for watched_title in watched_movies: + # + # # if the title is in the movie watchlist remove from the watchlist + # + + + + + + - if title in user_data: - user_data.remove(title['watchlist']) - user_data.append(title['watched']) - return user_data + # if title in user_data: + # user_data.remove(title['watchlist']) + # user_data.append(title['watched']) + # return user_data # ----------------------------------------- From c71847f7879891953ba9c0aaf922f21bd6ca0581 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Tue, 28 Mar 2023 21:30:08 -0700 Subject: [PATCH 16/30] added 2 passing functions for wave02, passing all tests --- viewing_party/party.py | 68 +++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index fa35b0ab2..2fb199c88 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,6 +1,5 @@ # ------------- WAVE 1 -------------------- - def create_movie(title, genre, rating): ''' input: title, genre, rating @@ -14,8 +13,9 @@ def create_movie(title, genre, rating): return None movie_dict = {'title': title, 'genre': genre, 'rating': rating} - if movie_dict == False: - return None + # I think these 2 lines don't guard against anything (lines 8-13 do) + # if movie_dict == False: + # return None return movie_dict @@ -29,6 +29,7 @@ def add_to_watched(user_data, movie): return user_data + def add_to_watchlist(user_data, movie): # user_data is a dict with key "watchlist" movies_user_wants_to_watch = user_data["watchlist"] @@ -39,7 +40,6 @@ def add_to_watchlist(user_data, movie): # append (represent) movie to list of dict movies_user_wants_to_watch.append(movie) - return user_data @@ -49,8 +49,6 @@ def watch_movie(user_data, title): title is a string representing the title of the movie the user has watched output: user_data ''' - # if not title in user_data: - # return user_data # value user_data dictionary with "watchlist" user_watchlist_movies = user_data["watchlist"] # value user_data dictionary with "watched" @@ -74,36 +72,28 @@ def watch_movie(user_data, title): #Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions # should not modify user_data. .copy() or .deepcopy() possibly - - - # for watched_title in watched_movies: - # - # # if the title is in the movie watchlist remove from the watchlist - # - - - - - - - - # if title in user_data: - # user_data.remove(title['watchlist']) - # user_data.append(title['watched']) - # return user_data - - # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- def get_watched_avg_rating(user_data): - pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries # calculate the average rating of all movies in the watched list # an empty "watched" list has a value of 0.0 output: average rating - ''' + ''' + #initiate sum to 0.0 and guard against an empty watched list + sum = 0.0 + if not user_data['watched']: + return sum + + #grab values of rating from each movie dictionary and add them to the sum + for movie in user_data['watched']: + sum += movie['rating'] + + #return average (sum / # of watched movies) + return sum / len(user_data['watched']) + # #user_data is a dict with "watched" list of dict # user_list_of_watched_movies = user_data["watched"] # #calc th avg rating of all movies in the watched list @@ -111,7 +101,6 @@ def get_watched_avg_rating(user_data): # sum(user_list_of_watched_movies) # } def get_most_watched_genre(user_data): - pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries. # each movie dictionary has a key 'genre' which is a string @@ -119,6 +108,29 @@ def get_most_watched_genre(user_data): # if the value of 'watched' is an empty string, function should return None output: genre that's most frequently watched ''' + #initialize a dictionary that will store genres of all watched movies + genre_dict = {} + #guard against an empty watched list + if not user_data['watched']: + return None + + #add genre of each watched movie as a key, adding to its frequency everytime + for movie in user_data['watched']: + #get the genre of the movie + movie_genre = movie['genre'] + + #if the genre is not in genre_dict, add it as a key with a value of 1 + #else genre is in genre_dict, increase value by 1 + if not movie_genre in genre_dict: + genre_dict[movie_genre] = 1 + else: + genre_dict[movie_genre] += 1 + + most_popular_genre = max(genre_dict, key=genre_dict.get) + #return genre with highest value from genre_dict + return most_popular_genre + + # ----------------------------------------- # ------------- WAVE 3 -------------------- From 6c5ce9ce4b51532537b66eec427ee3a873a982f1 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Wed, 29 Mar 2023 09:16:21 -0700 Subject: [PATCH 17/30] add docstring and functions for wave03 --- tests/test_wave_03.py | 8 ++++---- viewing_party/party.py | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..efe74eb2d 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() @@ -60,7 +60,7 @@ def test_friends_unique_movies_not_duplicated(): # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 2fb199c88..756a52fe4 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -130,13 +130,29 @@ def get_most_watched_genre(user_data): #return genre with highest value from genre_dict return most_popular_genre - - # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" + # user_data represents a list of watched movies and a list of friends + # each item in "friends" is a dictionary that has a key "watched" with a list of movie dictionaries + # each movie dictionary has a "title" + # function should determine which movies the the user has uniquely watched, friends have not watched it + output: list of dictionaries that represents a list of movies + ''' + +def get_friends_unique_watched(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" + # user_data represents a list of watched movies and a list of friends + # each item in "friends" is a dictionary that has a key "watched" with a list of movie dictionaries + # each movie dictionary has a "title" + # function should determine which movies at least one of the friends has watched, user has not watched it + output: list of dictionaries that represents a list of movies + ''' - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From d1fcbd2a1334ed08f2167fcc3f3bc41b4ab60dab Mon Sep 17 00:00:00 2001 From: Edith Date: Wed, 29 Mar 2023 09:50:45 -0700 Subject: [PATCH 18/30] wave 3 first attempt --- viewing_party/party.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/viewing_party/party.py b/viewing_party/party.py index 756a52fe4..868020b43 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -142,8 +142,22 @@ def get_unique_watched(user_data): # function should determine which movies the the user has uniquely watched, friends have not watched it output: list of dictionaries that represents a list of movies ''' + list_watched_movies = user_data['watched'] + list_of_friends = user_data['friends']['watched'] + unique_watched = [] + + for movie_friends in list_of_friends.items: + for user_movie in list_watched_movies.items: + if not movie_friends in list_watched_movies: + unique_watched.append(user_movie) + return unique_watched + + + + def get_friends_unique_watched(user_data): + pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" # user_data represents a list of watched movies and a list of friends From 3df11a80626157edcfeb3eb90545a365e1b1fb2d Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Wed, 29 Mar 2023 11:05:46 -0700 Subject: [PATCH 19/30] fixed 1 function in wave1 for correct indexing and syntax --- viewing_party/party.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 868020b43..4b28f3375 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -143,14 +143,14 @@ def get_unique_watched(user_data): output: list of dictionaries that represents a list of movies ''' list_watched_movies = user_data['watched'] - list_of_friends = user_data['friends']['watched'] + list_of_friends = user_data['friends'] unique_watched = [] - for movie_friends in list_of_friends.items: - for user_movie in list_watched_movies.items: + for movie_friends in list_of_friends: + for user_movie in list_watched_movies: if not movie_friends in list_watched_movies: unique_watched.append(user_movie) - return unique_watched + return unique_watched From 37b443e85e2e19efd8e67832316846a73b2782d9 Mon Sep 17 00:00:00 2001 From: Edith Date: Wed, 29 Mar 2023 15:52:27 -0700 Subject: [PATCH 20/30] wave 03 function 01 --- viewing_party/party.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 4b28f3375..e2f8ee50d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -141,16 +141,20 @@ def get_unique_watched(user_data): # each movie dictionary has a "title" # function should determine which movies the the user has uniquely watched, friends have not watched it output: list of dictionaries that represents a list of movies - ''' + ''' list_watched_movies = user_data['watched'] list_of_friends = user_data['friends'] - unique_watched = [] + friend_movie_list = [] + + for movie in list_of_friends: + friend_movie_list += movie["watched"] + unique_watched_movies = [] + + for movie in list_watched_movies: + if movie not in friend_movie_list and movie not in unique_watched_movies: + unique_watched_movies.append(movie) + return unique_watched_movies - for movie_friends in list_of_friends: - for user_movie in list_watched_movies: - if not movie_friends in list_watched_movies: - unique_watched.append(user_movie) - return unique_watched From a698b800558c043b23f32f06cfd5a1518a4b1bef Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Wed, 29 Mar 2023 18:14:25 -0700 Subject: [PATCH 21/30] added second function to wave03 passes tests --- viewing_party/party.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index e2f8ee50d..3687a8e12 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -156,12 +156,7 @@ def get_unique_watched(user_data): return unique_watched_movies - - - - def get_friends_unique_watched(user_data): - pass ''' input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" # user_data represents a list of watched movies and a list of friends @@ -170,6 +165,22 @@ def get_friends_unique_watched(user_data): # function should determine which movies at least one of the friends has watched, user has not watched it output: list of dictionaries that represents a list of movies ''' + #grab a list of all the movies the user has watched + list_watched_movies = user_data['watched'] + #grabs a list of watched dictionaries for friends + list_of_friends = user_data['friends'] + + friend_movie_list = [] + + for movie in list_of_friends: + #iterates through all of the movies friends have watched + friend_movie_list += movie["watched"] + #friend_movie_list prints all of the movies all friends have watched + friend_unique_watched_movies = [] + for movie in friend_movie_list: + if movie not in list_watched_movies and movie not in friend_unique_watched_movies: + friend_unique_watched_movies.append(movie) + return friend_unique_watched_movies # ----------------------------------------- # ------------- WAVE 4 -------------------- From e4cf718d6fe6c988e75b02c1faa626440ab771a0 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Wed, 29 Mar 2023 18:32:57 -0700 Subject: [PATCH 22/30] added assert statements to wave03 tests, functions still passing --- tests/test_wave_03.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index efe74eb2d..c993de869 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() +# @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -55,10 +55,12 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 - raise Exception("Test needs to be completed.") - # ************************************************************************************************* - # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** - # ************************************************************************************************** + # raise Exception("Test needs to be completed.") + # ********************************************************************* + # ****** Complete the Assert Portions of these tests ********** + # ********************************************************************* + assert FANTASY_4 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies # @pytest.mark.skip() def test_friends_not_unique_movies(): From 6ec49acd3a1075c3fff977eb5e43a59be87d2188 Mon Sep 17 00:00:00 2001 From: Edith Date: Wed, 29 Mar 2023 21:07:31 -0700 Subject: [PATCH 23/30] wave 4 2/3 pass --- tests/test_wave_04.py | 6 +++--- viewing_party/party.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 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 3687a8e12..6a68b28c4 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -185,6 +185,19 @@ def get_friends_unique_watched(user_data): # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + recs = [] + list_of_friends = user_data['friends'] + unique_friend_watched_list = user_data['watched'] + for movie in list_of_friends: + friend_movie_list = movie['watched'] + for movie in friend_movie_list: + service_subscription = user_data['subscriptions'] + movie_host = movie['host'] + if movie_host in service_subscription and movie not in unique_friend_watched_list: + recs.append(movie) + return recs + # ----------------------------------------- # ------------- WAVE 5 -------------------- From 616c83f17de8fd8c67f8913860c81467cf205dea Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Wed, 29 Mar 2023 22:08:46 -0700 Subject: [PATCH 24/30] refactored wave04 function to remove duplicate movies from rec, passing all tests --- viewing_party/party.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6a68b28c4..2a6b66a03 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -170,14 +170,11 @@ def get_friends_unique_watched(user_data): #grabs a list of watched dictionaries for friends list_of_friends = user_data['friends'] - friend_movie_list = [] - - for movie in list_of_friends: - #iterates through all of the movies friends have watched - friend_movie_list += movie["watched"] - #friend_movie_list prints all of the movies all friends have watched - friend_unique_watched_movies = [] - for movie in friend_movie_list: + friend_unique_watched_movies = [] + #iterates through all of the movies friends have watched + for friend in list_of_friends: + #friend_movie_list prints all of the movies all friends have watched + for movie in friend["watched"]: if movie not in list_watched_movies and movie not in friend_unique_watched_movies: friend_unique_watched_movies.append(movie) return friend_unique_watched_movies @@ -187,15 +184,19 @@ def get_friends_unique_watched(user_data): # ----------------------------------------- def get_available_recs(user_data): recs = [] - list_of_friends = user_data['friends'] - unique_friend_watched_list = user_data['watched'] - for movie in list_of_friends: - friend_movie_list = movie['watched'] + friends = user_data['friends'] + user_watched_movies = user_data['watched'] + service_subscriptions = user_data['subscriptions'] + + for friend in friends: + friend_movie_list = friend['watched'] + for movie in friend_movie_list: - service_subscription = user_data['subscriptions'] movie_host = movie['host'] - if movie_host in service_subscription and movie not in unique_friend_watched_list: + + if movie_host in service_subscriptions and movie not in user_watched_movies and movie not in recs: recs.append(movie) + return recs From 7327bb8f082d1c552aa528703e1ffa363173a1f8 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Thu, 30 Mar 2023 09:59:15 -0700 Subject: [PATCH 25/30] first iteration of wave05 with first function passing 1 test --- tests/test_wave_05.py | 4 ++-- viewing_party/party.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index b2ba9ad33..9035481d3 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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 2a6b66a03..abaa341ec 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -203,4 +203,20 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + recommended_movies = [] + user_frequently_watched_genre = get_most_watched_genre(user_data) + user_watched_movies = user_data['watched'] + friends_watched_movies = get_friends_unique_watched(user_data) + + for movie in user_watched_movies: + if movie not in friends_watched_movies: + recommended_movies.append(movie) + + if not user_watched_movies['genre'] in list(set(user_frequently_watched_genre)): + recommended_movies.remove(movie) + + return recommended_movies + + From 648bcf6327ad1f664f61f5444817ac22fefd8ea7 Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Thu, 30 Mar 2023 13:44:38 -0700 Subject: [PATCH 26/30] first function of wave05 passing 2 tests --- viewing_party/party.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index abaa341ec..9e1cbf6df 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -203,19 +203,26 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- + for movie in user_data['watched']: + #get the genre of the movie + movie_genre = movie['genre'] + def get_new_rec_by_genre(user_data): + recommended_movies = [] - user_frequently_watched_genre = get_most_watched_genre(user_data) user_watched_movies = user_data['watched'] + user_frequently_watched_genre = get_most_watched_genre(user_data) friends_watched_movies = get_friends_unique_watched(user_data) - for movie in user_watched_movies: - if movie not in friends_watched_movies: - recommended_movies.append(movie) - - if not user_watched_movies['genre'] in list(set(user_frequently_watched_genre)): - recommended_movies.remove(movie) - + # go through the list of movies that only friends have watched + for movie in friends_watched_movies: + #get the genre of the movie + movie_genre = movie['genre'] + # if the movie isn't one that the user has watched and the movie genre matches their favorite: + if not movie in user_watched_movies and movie_genre == user_frequently_watched_genre: + #append the movie to the recommended list + recommended_movies.append(movie) + return recommended_movies From 435c1d9c5221cbe343110c5844316b0f337e8845 Mon Sep 17 00:00:00 2001 From: Edith Date: Thu, 30 Mar 2023 13:51:15 -0700 Subject: [PATCH 27/30] Last wave all but last function done --- tests/test_wave_05.py | 9 ++++++++- viewing_party/party.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 9035481d3..a2d0e6c54 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -53,11 +53,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 + + #raise Exception("Test needs to be completed.") # ********************************************************************* # ****** Complete the Act and Assert Portions of these tests ********** # ********************************************************************* + @pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange diff --git a/viewing_party/party.py b/viewing_party/party.py index 9e1cbf6df..0dbcf25da 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -227,3 +227,27 @@ def get_new_rec_by_genre(user_data): +# def get_rec_from_favorites(user_data): +# ''' +# take one parameter: user_data + +# Consider the user's most frequently watched genre. Then, determine a list of +# ''' +# user_frequently_watched_genre = get_most_watched_genre(user_data) +# ''' +# recommended movies. A movie should be added to this list if and only if: +# The user has not watched it +# At least one of the user's friends has watched +# The "genre" of the movie is the same as the user's most frequent genre +# Return the list of recommended movies +# Create a function named get_rec_from_favorites. This function should... +# take one parameter: user_data +# user_data will have a field "favorites". The value of "favorites" is a list of +# movie dictionaries +# This represents the user's favorite movies +# Determine a list of recommended movies. A movie should be added to this list +# if and only if: +# The movie is in the user's "favorites" +# None of the user's friends have watched it +# Return the list of recommended movies +# ''' \ No newline at end of file From 85d9e752ca4e5f19a1301a79b813ffa32be4f3e3 Mon Sep 17 00:00:00 2001 From: Edith Date: Thu, 30 Mar 2023 14:18:14 -0700 Subject: [PATCH 28/30] wave 05 5/7 pass --- tests/test_wave_05.py | 8 ++++---- viewing_party/party.py | 36 ++++++++++++------------------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index a2d0e6c54..a83c51a6a 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -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 = { @@ -65,7 +65,7 @@ def test_new_genre_rec_from_empty_friends(): # ********************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -79,7 +79,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 = { @@ -101,7 +101,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 0dbcf25da..2a7e88022 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -227,27 +227,15 @@ def get_new_rec_by_genre(user_data): -# def get_rec_from_favorites(user_data): -# ''' -# take one parameter: user_data - -# Consider the user's most frequently watched genre. Then, determine a list of -# ''' -# user_frequently_watched_genre = get_most_watched_genre(user_data) -# ''' -# recommended movies. A movie should be added to this list if and only if: -# The user has not watched it -# At least one of the user's friends has watched -# The "genre" of the movie is the same as the user's most frequent genre -# Return the list of recommended movies -# Create a function named get_rec_from_favorites. This function should... -# take one parameter: user_data -# user_data will have a field "favorites". The value of "favorites" is a list of -# movie dictionaries -# This represents the user's favorite movies -# Determine a list of recommended movies. A movie should be added to this list -# if and only if: -# The movie is in the user's "favorites" -# None of the user's friends have watched it -# Return the list of recommended movies -# ''' \ No newline at end of file +def get_rec_from_favorites(user_data): + friends_watched_movies = get_friends_unique_watched(user_data) + favorite_movies = user_data['favorites'] + reccommended_from_favorites = [] + + for movie in favorite_movies: + #for favorite in favorite_movies: + if not friends_watched_movies: + reccommended_from_favorites.append(movie) + return reccommended_from_favorites + + From ba6bea4ab137efbfd0360f508ef623585ab07afa Mon Sep 17 00:00:00 2001 From: Edith Date: Thu, 30 Mar 2023 17:14:27 -0700 Subject: [PATCH 29/30] woo its over --- play_tester.py | 12 ++++++------ tests/test_wave_05.py | 4 ++-- viewing_party/party.py | 19 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/play_tester.py b/play_tester.py index 9e2aecf48..21fc6fb36 100644 --- a/play_tester.py +++ b/play_tester.py @@ -9,10 +9,10 @@ pp = pprint.PrettyPrinter(indent=4) # play testing section -print("\n-----Wave 01 test data-----") -pp.pprint(HORROR_1) -pp.pprint(FANTASY_1) -pp.pprint(FANTASY_2) +# print("\n-----Wave 01 test data-----") +# pp.pprint(HORROR_1) +# pp.pprint(FANTASY_1) +# pp.pprint(FANTASY_2) # print("\n-----Wave 02 user_data-----") # pp.pprint(clean_wave_2_data()) @@ -25,5 +25,5 @@ #pp.pprint(clean_wave_4_data()) # Wave 05 user data -#print("\n-----Wave 05 user_data-----") -#pp.pprint(clean_wave_5_data()) +print("\n-----Wave 05 user_data-----") +pp.pprint(clean_wave_5_data()) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index a83c51a6a..3c7a5d2be 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 = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 2a7e88022..758b95df9 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -145,6 +145,9 @@ def get_unique_watched(user_data): list_watched_movies = user_data['watched'] list_of_friends = user_data['friends'] friend_movie_list = [] + + if len(list_of_friends) == 0: + return list_watched_movies for movie in list_of_friends: friend_movie_list += movie["watched"] @@ -203,9 +206,6 @@ def get_available_recs(user_data): # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- - for movie in user_data['watched']: - #get the genre of the movie - movie_genre = movie['genre'] def get_new_rec_by_genre(user_data): @@ -225,17 +225,16 @@ def get_new_rec_by_genre(user_data): return recommended_movies - def get_rec_from_favorites(user_data): - friends_watched_movies = get_friends_unique_watched(user_data) + user_watched_movies = get_unique_watched(user_data) + # was friends have only watched but wanted user has only watched favorite_movies = user_data['favorites'] reccommended_from_favorites = [] for movie in favorite_movies: #for favorite in favorite_movies: - if not friends_watched_movies: - reccommended_from_favorites.append(movie) - return reccommended_from_favorites - - + if movie in user_watched_movies : + reccommended_from_favorites.append(movie) + + return reccommended_from_favorites \ No newline at end of file From 1eb0ed8678959b74a6eec258dbdcc53838b2970d Mon Sep 17 00:00:00 2001 From: Anna Lima Date: Fri, 31 Mar 2023 06:49:56 -0700 Subject: [PATCH 30/30] cleaned up docstrings and spacing, all functions passing all tests in all waves --- viewing_party/party.py | 165 +++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 87 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 758b95df9..32ff969d5 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,9 +1,8 @@ - # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): ''' - input: title, genre, rating - output: dictionary + input: title, genre, rating of a movie + output: movie dictionary with 3 keys ''' if not title: return None @@ -13,30 +12,32 @@ def create_movie(title, genre, rating): return None movie_dict = {'title': title, 'genre': genre, 'rating': rating} - # I think these 2 lines don't guard against anything (lines 8-13 do) - # if movie_dict == False: - # return None + return movie_dict def add_to_watched(user_data, movie): - #user_data is a dict with key "watched" + ''' + input: user_data with a key for "watched" , movie + output: user_data with movie passed in added + ''' movies_user_has_watched = user_data["watched"] - # a list of dicts rep the movies the user has watched # append (represent) movie to list of dict movies_user_has_watched.append(movie) - #add movie to the "movies_user_has_watched" inside of user data - + return user_data def add_to_watchlist(user_data, movie): - # user_data is a dict with key "watchlist" + ''' + input: user_data with a key for "watchlist", movie + output: user_data with movie added to the "watchlist + ''' movies_user_wants_to_watch = user_data["watchlist"] + if movies_user_wants_to_watch is None: # an empty list rep that the user has no movies in their watchlist movies_user_wants_to_watch = [] - # a list of dicts rep the movies the user has watched # append (represent) movie to list of dict movies_user_wants_to_watch.append(movie) @@ -46,41 +47,28 @@ def add_to_watchlist(user_data, movie): def watch_movie(user_data, title): ''' input: user_data is a dictionary with a "watchlist" and a "watched" list of movies; - title is a string representing the title of the movie the user has watched - output: user_data + output: user_data with a movie that moves from "watchlist" to "watched" ''' - # value user_data dictionary with "watchlist" user_watchlist_movies = user_data["watchlist"] - # value user_data dictionary with "watched" watched_movies = user_data["watched"] - # this represents the title of the movie the user has watched - for watchlist_dict in user_watchlist_movies: - # if this title is in the users watchlist - # is title = title of watch_dict - if title == watchlist_dict['title']: - user_watchlist_movies.remove(watchlist_dict) - watched_movies.append(watchlist_dict) + + # iterate through the watchlist to find if movie in there + for movie in user_watchlist_movies: + #if movie is already in watchlist, remove it and add it to watched movies + if title == movie['title']: + user_watchlist_movies.remove(movie) + watched_movies.append(movie) + return user_data - # value of key called title - -# If the title is in a movie in the user's watchlist: -# remove that movie from the watchlist -# add that movie to watched -# return the user_data - -#Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions -# should not modify user_data. .copy() or .deepcopy() possibly - # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- + def get_watched_avg_rating(user_data): ''' input: user_data is a dictionary with a "watched" list of movies dictionaries - # calculate the average rating of all movies in the watched list - # an empty "watched" list has a value of 0.0 - output: average rating + output: average rating of all movies in the "watched" list, where empty list has a value of 0.0 ''' #initiate sum to 0.0 and guard against an empty watched list sum = 0.0 @@ -94,21 +82,12 @@ def get_watched_avg_rating(user_data): #return average (sum / # of watched movies) return sum / len(user_data['watched']) - # #user_data is a dict with "watched" list of dict - # user_list_of_watched_movies = user_data["watched"] - # #calc th avg rating of all movies in the watched list - # for i in range(len(user_data)): - # sum(user_list_of_watched_movies) -# } + def get_most_watched_genre(user_data): ''' - input: user_data is a dictionary with a "watched" list of movies dictionaries. - # each movie dictionary has a key 'genre' which is a string - # determine which genre is the most frequently occurring in the 'watched' list - # if the value of 'watched' is an empty string, function should return None - output: genre that's most frequently watched + input: user_data is a dictionary with a "watched" list of; each movie has a "genre" key + output: genre that's most frequently watched from the watched list. Return None if "watched" is empty ''' - #initialize a dictionary that will store genres of all watched movies genre_dict = {} #guard against an empty watched list if not user_data['watched']: @@ -116,99 +95,107 @@ def get_most_watched_genre(user_data): #add genre of each watched movie as a key, adding to its frequency everytime for movie in user_data['watched']: - #get the genre of the movie movie_genre = movie['genre'] - #if the genre is not in genre_dict, add it as a key with a value of 1 - #else genre is in genre_dict, increase value by 1 + #if the genre is not in genre_dict, add it as a key with a value of 1, else, add to genre frequency if not movie_genre in genre_dict: genre_dict[movie_genre] = 1 else: genre_dict[movie_genre] += 1 - - most_popular_genre = max(genre_dict, key=genre_dict.get) + #return genre with highest value from genre_dict + most_popular_genre = max(genre_dict, key=genre_dict.get) + return most_popular_genre # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- + def get_unique_watched(user_data): ''' - input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" - # user_data represents a list of watched movies and a list of friends - # each item in "friends" is a dictionary that has a key "watched" with a list of movie dictionaries - # each movie dictionary has a "title" - # function should determine which movies the the user has uniquely watched, friends have not watched it - output: list of dictionaries that represents a list of movies + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" list + output: list of dictionaries that represents a list of movies that user has uniquely watched, ("friends" have not) ''' - list_watched_movies = user_data['watched'] - list_of_friends = user_data['friends'] + user_watched_movies = user_data['watched'] + friends_watched_movies = user_data['friends'] friend_movie_list = [] - - if len(list_of_friends) == 0: - return list_watched_movies - for movie in list_of_friends: + if len(friends_watched_movies) == 0: + return user_watched_movies + + #iterate through the list of movies that friends have watched + for movie in friends_watched_movies: friend_movie_list += movie["watched"] + #initialize an empty list for unique movies unique_watched_movies = [] - for movie in list_watched_movies: + #iterate through the list of movies the user has watched + for movie in user_watched_movies: + #if the movie hasn't been watched by friends and it's not yet in the list of unique movies they've watched if movie not in friend_movie_list and movie not in unique_watched_movies: + #add movie to unique movies, guard against duplicates unique_watched_movies.append(movie) + return unique_watched_movies def get_friends_unique_watched(user_data): ''' - input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" - # user_data represents a list of watched movies and a list of friends - # each item in "friends" is a dictionary that has a key "watched" with a list of movie dictionaries - # each movie dictionary has a "title" - # function should determine which movies at least one of the friends has watched, user has not watched it - output: list of dictionaries that represents a list of movies + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" list + output: list of movies that at least one friend has watched but user has not ''' - #grab a list of all the movies the user has watched - list_watched_movies = user_data['watched'] - #grabs a list of watched dictionaries for friends + user_watched_movies = user_data['watched'] list_of_friends = user_data['friends'] - friend_unique_watched_movies = [] - #iterates through all of the movies friends have watched + + #iterates through all of the friends in the list for friend in list_of_friends: - #friend_movie_list prints all of the movies all friends have watched + #for each friend, iterate to find what each of them has watched for movie in friend["watched"]: - if movie not in list_watched_movies and movie not in friend_unique_watched_movies: + #if the movie isn't something the user has watched and hasn't yet beed added to the friends unique list, add it + if movie not in user_watched_movies and movie not in friend_unique_watched_movies: friend_unique_watched_movies.append(movie) + return friend_unique_watched_movies # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- + def get_available_recs(user_data): + ''' + input: user_data with a field for "subscriptions"; "friends" watchlist now has a field for "host" that outlines streaming service + output: movie recommendations for user if they haven't watched it yet and its a subscription they have + ''' recs = [] friends = user_data['friends'] user_watched_movies = user_data['watched'] service_subscriptions = user_data['subscriptions'] + #iterate through each friend to get a list of the movies they've watched for friend in friends: friend_movie_list = friend['watched'] - + + #iterate through each movie friends have watched to look for the host for movie in friend_movie_list: movie_host = movie['host'] - + #if the movie host is also in the subscriptions that the user has; the user hasn't watched the movie yet if movie_host in service_subscriptions and movie not in user_watched_movies and movie not in recs: + #add movie to recs, guarding for duplicates recs.append(movie) return recs - # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- - + def get_new_rec_by_genre(user_data): - + ''' + input: user_data which includes "friends" list of watched movies + output: a recommended list of movies for the user, if they haven't watched it and it matches their most frequent genre + ''' recommended_movies = [] user_watched_movies = user_data['watched'] user_frequently_watched_genre = get_most_watched_genre(user_data) @@ -227,14 +214,18 @@ def get_new_rec_by_genre(user_data): def get_rec_from_favorites(user_data): + ''' + input: user_data with a "favorites" movie list + output: a recommended list of movies for friends, if it's in the "favorites" list and none of the friends have watched it yet + ''' user_watched_movies = get_unique_watched(user_data) - # was friends have only watched but wanted user has only watched favorite_movies = user_data['favorites'] reccommended_from_favorites = [] + #iterate through each movie in favorites list for movie in favorite_movies: - #for favorite in favorite_movies: - if movie in user_watched_movies : + #append movies to the recommendations if it's in the favorites list and the user has uniquely watched it + if movie in user_watched_movies: reccommended_from_favorites.append(movie) return reccommended_from_favorites \ No newline at end of file