From 5c99229243831038ae4b75faaab47f336b19a75c Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Sat, 17 Sep 2022 12:04:19 -0700 Subject: [PATCH 1/9] wave one completed --- tests/test_wave_01.py | 24 +++++++++++++----------- viewing_party/party.py | 28 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6be6994a5..9979b9e4a 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_user_watchlist(): # Arrange movie = { @@ -100,7 +100,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_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -118,13 +118,14 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 + assert updated_data["watched"][0]["title"] == MOVIE_TITLE_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" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -142,13 +143,14 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 + assert updated_data["watched"][1]["title"] == MOVIE_TITLE_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" ********** # ******************************************************************************************* -@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 6d34a6b5f..db952a32a 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,7 +1,33 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + if title and genre and rating: + new_movie = {} + new_movie["title"] = title + new_movie["genre"] = genre + new_movie["rating"] = rating + return new_movie + if not title or not genre or not rating: + return None + +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + user_data["watchlist"].append(movie) + return user_data + +def watch_movie(user_data, title): + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watchlist"].remove(movie) + user_data["watched"].append(movie) + return user_data + return user_data + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- From f16a4a9ab930fc8e56dcce19ef5ac3795d649a2e Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Tue, 20 Sep 2022 09:39:26 -0700 Subject: [PATCH 2/9] passed first part of wave 2 --- tests/test_wave_02.py | 8 +++--- tests/test_wave_03.py | 2 +- viewing_party/party.py | 60 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..198e395b3 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_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..1d7d3f654 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() diff --git a/viewing_party/party.py b/viewing_party/party.py index db952a32a..88e345135 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -27,17 +27,70 @@ def watch_movie(user_data, title): return user_data - - # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + sum = 0 + average = 0 + + for i in range(len(user_data["watched"])): + sum += (user_data["watched"][i]["rating"]) + average = sum/len(user_data["watched"]) + return average + +def get_most_watched_genre(user_data): + # if user_data == {"watched": []}: + # return None + # else: + index = 0 + genres = [] + least_popular = [] + most_popular = [] + if user_data == {"watched":[]}: + return None + else: + for movie in user_data["watched"]: + index +=1 + genres.append(user_data["watched"][index-1]["genre"]) + for item in genres: + if item not in least_popular: + least_popular.append(item) + else: + most_popular.append(item) + return (most_popular[0]) # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + # user data = dict("watched" & "friends") + #Create a set of movies friends have watched + friend_set=set() + for friend in user_data["friends"]: + for movie in friend["watched"]: + friend_set.add(movie["title"]) + + unique_list=[] + + # + for movie in user_data["watched"]: + if movie["title"] not in friend_set: + unique_list.append(movie) + + return unique_list + + + + + + + + # what movies has the "watched" compared to "friends" + # return the list + # ----------------------------------------- # ------------- WAVE 4 -------------------- @@ -45,5 +98,4 @@ def watch_movie(user_data, title): # ----------------------------------------- # ------------- WAVE 5 -------------------- -# ----------------------------------------- - +# ----------------------------------------- \ No newline at end of file From 43dc64855563a5a8a15ec53d87d44f25dfd7a07c Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Tue, 20 Sep 2022 14:59:31 -0700 Subject: [PATCH 3/9] updated unique watched to use a list instead of set --- tests/test_wave_03.py | 10 ++++----- viewing_party/party.py | 47 +++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 1d7d3f654..e80cbe183 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -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 88e345135..9746fccdf 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -64,16 +64,19 @@ def get_most_watched_genre(user_data): # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - +''' def get_unique_watched(user_data): # user data = dict("watched" & "friends") #Create a set of movies friends have watched - friend_set=set() + + # first attemp using a set + + friend_set = set() for friend in user_data["friends"]: for movie in friend["watched"]: friend_set.add(movie["title"]) - unique_list=[] + unique_list = [] # for movie in user_data["watched"]: @@ -81,15 +84,45 @@ def get_unique_watched(user_data): unique_list.append(movie) return unique_list - - +''' + # second attempt using a list +def get_unique_watched(user_data): + unique = [] + not_unique = [] + total_movies_list = [] + users_movies = [] + friends_movies = [] + for movie in user_data["watched"]: + users_movies.append(movie) + + for movie in user_data["friends"]: + for item in movie["watched"]: + friends_movies.append(item) + + total_movies_list = users_movies + friends_movies + + for item in total_movies_list: + if item not in friends_movies: + unique.append(item) + else: + not_unique.append(item) + return unique + +# def get_friends_unique_watched(user_data): + # will need to access watched inside user_data + # user_list = [] + + # and compare it to friends["watched"] + # create a new list left_to_watch + # left_to_watch = [] + # if movie in friends["watched"] is not in user_data["watched"] + # we append to a list left_to_watch - # what movies has the "watched" compared to "friends" - # return the list + # returning a list of what the user_data["watched"] has not seen # ----------------------------------------- From fdbdc7d7ae2e9a81e4becad04f1941d9f1f422c3 Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Wed, 21 Sep 2022 09:33:30 -0700 Subject: [PATCH 4/9] finished wave 3 --- tests/test_wave_03.py | 3 +++ viewing_party/party.py | 52 +++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index e80cbe183..343d0c503 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 INTRIGUE_3 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies # raise Exception("Test needs to be completed.") # ************************************************************************************************* diff --git a/viewing_party/party.py b/viewing_party/party.py index 9746fccdf..366856551 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -87,43 +87,49 @@ def get_unique_watched(user_data): ''' # second attempt using a list - -def get_unique_watched(user_data): +# part 1 +def get_unique_watched(user_data): # get a list of the movies that user has seen, and friend still has to see unique = [] - not_unique = [] - total_movies_list = [] + total_movies_list = [] # the addition of user movies and friend movies users_movies = [] friends_movies = [] for movie in user_data["watched"]: - users_movies.append(movie) - - for movie in user_data["friends"]: - for item in movie["watched"]: - friends_movies.append(item) + users_movies.append(movie) # the new value of user_movies - total_movies_list = users_movies + friends_movies + for movie in user_data["friends"]: # iterating and get the dict of the friends + for item in movie["watched"]: # iterate to the to the list of movies the friend has seen + friends_movies.append(item) # new value of friends_movies - for item in total_movies_list: - if item not in friends_movies: - unique.append(item) - else: - not_unique.append(item) + total_movies_list = users_movies + friends_movies # add the new values of user_movies & friends_movies +# to total_movies_list (both user + friends) + for item in total_movies_list: # iterate through total_movies_list + if item not in friends_movies: # if the movie is not in the friend's movie list + unique.append(item) # we add it to the list of the user_data["watched"] return unique - -# def get_friends_unique_watched(user_data): + + # part 2 +def get_friends_unique_watched(user_data): # will need to access watched inside user_data - # user_list = [] + user_movies= [] + friends_movies = [] + # create a new list left_to_watch + left_to_watch = [] # and compare it to friends["watched"] - # create a new list left_to_watch - # left_to_watch = [] - # if movie in friends["watched"] is not in user_data["watched"] - # we append to a list left_to_watch + for movie in user_data["watched"]: + user_movies.append(movie) #user_movies has a list of the movies the user has seen - # returning a list of what the user_data["watched"] has not seen + for movie in user_data["friends"]: # reaching into the list of dictionaries + for item in movie["watched"]: + friends_movies.append(item) # this is now a list of the friend's movies + for item in friends_movies: # iterate through the list of friend's movies + if item not in user_movies: # if movie in friends["watched"] is not in user_data["watched"] + if item not in left_to_watch: + left_to_watch.append(item) + return left_to_watch # ----------------------------------------- # ------------- WAVE 4 -------------------- From 71404ad366d634151981c1ffaeaabd078a7c1777 Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Thu, 22 Sep 2022 09:42:04 -0700 Subject: [PATCH 5/9] passed all of the tests for wave 4 --- tests/test_wave_04.py | 6 +++--- viewing_party/party.py | 46 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..0b0b3c7e2 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { @@ -38,7 +38,7 @@ def test_no_available_friend_recs(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_no_available_friend_recs_watched_all(): # Arrange amandas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 366856551..3e3351a26 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -41,9 +41,6 @@ def get_watched_avg_rating(user_data): return average def get_most_watched_genre(user_data): - # if user_data == {"watched": []}: - # return None - # else: index = 0 genres = [] least_popular = [] @@ -135,6 +132,47 @@ def get_friends_unique_watched(user_data): # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + user_movies = [] + friends_movies = [] + unique = [] + + for movie in user_data["watched"]: # this is to help create the user watch list + user_movies.append(movie) #user_movies has a list of the movies the user has seen + + for movie in user_data["friends"]: # reaching into the list of dictionaries + for item in movie["watched"]: + friends_movies.append(item) # this is now a list of the friend's movies + + for item in friends_movies: # we are accesing the list we created of movies watched by friends + if item not in user_movies: # it the friends movie is not in the movies the user has seen + if item not in unique: # if that movie is also not in our list of unique movies, we add to unique + if item["host"] in user_data["subscriptions"]: # if streaming service is in subscription + unique.append(item) # if streaming service is found, add to unique + + return unique + + # ----------------------------------------- # ------------- WAVE 5 -------------------- -# ----------------------------------------- \ No newline at end of file +# ----------------------------------------- + +def get_new_rec_by_genre(user_data): + user_movies = [] + friends_movies = [] + unique = [] + + for movie in user_data["watched"]: # this is to help create the user watch list + user_movies.append(movie) #user_movies has a list of the movies the user has seen + + for movie in user_data["friends"]: # reaching into the list of dictionaries + for item in movie["watched"]: + friends_movies.append(item) # this is now a list of the friend's movies + + for item in friends_movies: # we are accesing the list we created of movies watched by friends + if item not in user_movies: # it the friends movie is not in the movies the user has seen + if item not in unique: # if that movie is also not in our list of unique movies, we add to unique + if item["host"] in user_data["subscriptions"]: # if streaming service is in subscription + unique.append(item) # if streaming service is found, add to unique + + return unique \ No newline at end of file From 53c05ed3c952707d4c0d592dd73e175ae5bd4eef Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Thu, 22 Sep 2022 16:03:06 -0700 Subject: [PATCH 6/9] finished wave 5 --- tests/test_wave_05.py | 17 +++++++++-------- viewing_party/party.py | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 85ebb8b18..c75c8c696 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +38,7 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -52,13 +52,14 @@ def test_new_genre_rec_from_empty_friends(): } ] } - - raise Exception("Test needs to be completed.") + actual = get_new_rec_by_genre(sonyas_data) + assert actual == [] + # raise Exception("Test needs to be completed.") # ********************************************************************* # ****** Complete the Act and Assert Portions of theis tests ********** # ********************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -72,7 +73,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 +95,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 3e3351a26..7b55faec8 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -160,10 +160,18 @@ def get_available_recs(user_data): def get_new_rec_by_genre(user_data): user_movies = [] friends_movies = [] - unique = [] + most_genre = [] + recommended_movies = [] for movie in user_data["watched"]: # this is to help create the user watch list user_movies.append(movie) #user_movies has a list of the movies the user has seen + most_genre.append(movie["genre"]) # to get to the genre + + if len(user_movies) == 0: + return friends_movies # if the list of user is completely empty + + max(set(most_genre), key=most_genre.count) # will get the most watched genre, will + # shorten the list to only one for movie in user_data["friends"]: # reaching into the list of dictionaries for item in movie["watched"]: @@ -171,8 +179,34 @@ def get_new_rec_by_genre(user_data): for item in friends_movies: # we are accesing the list we created of movies watched by friends if item not in user_movies: # it the friends movie is not in the movies the user has seen - if item not in unique: # if that movie is also not in our list of unique movies, we add to unique + if item not in most_genre: # if that movie is also not in our list of unique movies, we add to unique if item["host"] in user_data["subscriptions"]: # if streaming service is in subscription - unique.append(item) # if streaming service is found, add to unique + if most_genre[0] in item["genre"]: # if the most popular genre is in the friends dict list + recommended_movies.append(item) # if streaming service is found, add to recommended movies + return recommended_movies + +def get_rec_from_favorites(user_data): + recommended_movies = [] + user_movies = [] + friend_movies = [] + + for movie in user_data["watched"]: # this will add to the user movie list + user_movies.append(movie) + + if len(user_movies) == 0: + return friend_movies # if the list of user is completely empty + + for movie in user_data["friends"]: # this will add to the friend movies + for item in movie["watched"]: + friend_movies.append(item) + + for item in user_data["favorites"]: # this accesses favorites in the user data + if item not in friend_movies: # if that favorite is not in friends movies + recommended_movies.append(item) # append the item to the recommended movies + return recommended_movies + + + + + - return unique \ No newline at end of file From 118b456b18a7fa7ff6ef3bac8f1629a0d97015e6 Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Tue, 11 Oct 2022 10:52:30 -0700 Subject: [PATCH 7/9] working from scratch on wave 2 on my own --- viewing_party/party.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 7b55faec8..2929ee65d 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -31,12 +31,28 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- +# my own work +def get_watched_ave_rating(user_data): + count = 0 + average_rating = 0 + + for i in user_data["watched"]: + count += (user_data[i]["rating"]) + count = count/len(average_rating) + return average_rating + +# def get_most_watched_genre(user_data): + + + +""" +# THIS IS THE WORK OF A GROUP def get_watched_avg_rating(user_data): sum = 0 average = 0 for i in range(len(user_data["watched"])): - sum += (user_data["watched"][i]["rating"]) + sum += (user_data["watched"][i]["rating"]) average = sum/len(user_data["watched"]) return average @@ -57,6 +73,7 @@ def get_most_watched_genre(user_data): else: most_popular.append(item) return (most_popular[0]) +""" # ----------------------------------------- # ------------- WAVE 3 -------------------- From bd2146bbbeb5dfaffa47ca19f12fd4911b8054d8 Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Fri, 14 Oct 2022 20:14:04 -0700 Subject: [PATCH 8/9] finished part 1 and half of part 2 from wave 2 --- viewing_party/party.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 2929ee65d..7d724a9a5 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -32,18 +32,20 @@ def watch_movie(user_data, title): # ----------------------------------------- # my own work -def get_watched_ave_rating(user_data): +def get_watched_avg_rating(user_data): count = 0 average_rating = 0 - for i in user_data["watched"]: - count += (user_data[i]["rating"]) - count = count/len(average_rating) + for i in range(len(user_data["watched"])): + count += (user_data["watched"][i]["rating"]) + average_rating = count/len(user_data["watched"]) return average_rating -# def get_most_watched_genre(user_data): - - +def get_most_watched_genre(user_data): + for i in range(len(user_data["watched"])): + popular_genre = [] + if popular_genre == []: + return None """ # THIS IS THE WORK OF A GROUP From 0623e860fd14b0df0aa972e406b8aa4715dead24 Mon Sep 17 00:00:00 2001 From: Nancy Lee Date: Sun, 16 Oct 2022 11:23:34 -0700 Subject: [PATCH 9/9] redid wave 2 with the help of tutor --- viewing_party/party.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 7d724a9a5..5775d9b00 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -31,7 +31,7 @@ def watch_movie(user_data, title): # ------------- WAVE 2 -------------------- # ----------------------------------------- -# my own work +# my own work with the help of tutor def get_watched_avg_rating(user_data): count = 0 average_rating = 0 @@ -42,13 +42,34 @@ def get_watched_avg_rating(user_data): return average_rating def get_most_watched_genre(user_data): - for i in range(len(user_data["watched"])): - popular_genre = [] - if popular_genre == []: - return None + genre_fave = [] # ['Fantasy', 'Fantasy', 'Fantasy', 'Action', 'Intrigue', 'Intrigue'] + count = 0 + current_highest = "" + + for users_list in user_data["watched"]: + genre_fave.append(users_list["genre"]) + + for element in genre_fave: + if count < genre_fave.count(element): # count = 0 vs action=1 + current_highest = element + count = genre_fave.count(element) # =1 + + if len(user_data["watched"]) == 0: + return None + + return current_highest + # print(count, current_highest) + # for i in range(len(user_data["watched"])): + # popular_genre = [] + # if popular_genre == []: + # return None + # elif i not in popular_genre: + # popular_genre.append(i) + + # return popular_genre """ -# THIS IS THE WORK OF A GROUP +THIS IS THE WORK OF A GROUP def get_watched_avg_rating(user_data): sum = 0 average = 0 @@ -61,7 +82,6 @@ def get_watched_avg_rating(user_data): def get_most_watched_genre(user_data): index = 0 genres = [] - least_popular = [] most_popular = [] if user_data == {"watched":[]}: return None @@ -70,10 +90,7 @@ def get_most_watched_genre(user_data): index +=1 genres.append(user_data["watched"][index-1]["genre"]) for item in genres: - if item not in least_popular: - least_popular.append(item) - else: - most_popular.append(item) + most_popular.append(item) return (most_popular[0]) """