From eca7e4052cb151c34652dfdebd70f972025691ce Mon Sep 17 00:00:00 2001 From: Jessica Date: Wed, 21 Sep 2022 14:58:53 -0700 Subject: [PATCH 1/4] Modified wave 1 --- viewing_party/party.py | 77 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..5beac0ac8 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,12 +1,81 @@ # ------------- WAVE 1 -------------------- +from distutils.file_util import move_file + + def create_movie(title, genre, rating): - pass + new_movie = {} + if title == None or genre == None or rating == None: + return None + else: + new_movie["title"] = title + new_movie["genre"] = genre + new_movie["rating"] = rating + + return new_movie + +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 + +""" +Create a function named watch_movie. This function should... +take two parameters: user_data, title +the value of user_data will be a dictionary with a "watchlist" and a "watched" +This represents that the user has a watchlist and a list of watched movies +the value of title will be a string +This represents the title of the movie the user has watched +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 +If the title is not a movie in the user's watchlist: +return the user_data +Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions should not modify user_data. +""" + +# watch_movie(janes_data, "Non-Existent Movie Title") + +def watch_movie(user_data, title): + movie_to_move = None + # dict_movie name of each dictionary in "watchlist" + for dict_movie in user_data["watchlist"]: + # if the tittle in that dictionary evaluate to the same then do the following + if title == dict_movie["title"]: + # create a new varaible + movie_to_move = dict_movie + else: + return user_data + +# you can't remove a dict from a for loop + user_data["watchlist"].remove(movie_to_move) + user_data["watched"].append(movie_to_move) + return user_data + + + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- - +# def get_watched_avg_rating(user_data): +# # user has a list of watched movies: to calculate all movies average +# # user_data["watched"]["rating"] +# rating = 0 +# # empty watched list == 0.0 +# for movie_rating in user_data["watched"]: +# if user_data["watched"]["rating"] == None: +# user_data["watched"]["rating"] == 0.0 +# rating += user_data["watched"]["rating"] + +# average_rating = rating/len(user_data["watched"]) +# return average_rating + +# # return average_rating # ----------------------------------------- # ------------- WAVE 3 -------------------- @@ -21,3 +90,7 @@ def create_movie(title, genre, rating): # ------------- WAVE 5 -------------------- # ----------------------------------------- + + + + From ebe67ad2d1d072c826d22f22b357c99ca740cd73 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 22 Sep 2022 16:15:08 -0700 Subject: [PATCH 2/4] Modified wave 1 and 2 --- tests/test_wave_01.py | 37 +++++++++----- tests/test_wave_02.py | 8 ++-- viewing_party/party.py | 106 +++++++++++++++++++++++------------------ 3 files changed, 89 insertions(+), 62 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6be6994a5..6e88643a8 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 = { @@ -119,15 +119,22 @@ 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.") + assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 + assert updated_data["watched"][0]["genre"] == GENRE_1 + assert updated_data["watched"][0]["rating"] == RATING_1 # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange + # assign a HORR0R_1 to movie_to_watch movie_to_watch = HORROR_1 + # janes_data is a dictionary that has two key values + # watchlist + # watched + # They each have a list as the value of the keys janes_data = { "watchlist": [ FANTASY_1, @@ -143,25 +150,33 @@ 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.") + assert updated_data["watched"][1] == movie_to_watch # ******************************************************************************************* # ****** 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 + # The variable movie_to_watch is assigned to HORROR_1 movie_to_watch = HORROR_1 + # the dictionary about janes_data that has two keys + # "watchlist" and "watched" janes_data = { "watchlist": [FANTASY_1], "watched": [FANTASY_2] } # Act + # name of the person janes_data and the name of the movie "Non-Existent Movie Title") updated_data = watch_movie(janes_data, "Non-Existent Movie Title") # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 1 + + # Is this checking for none of the varaibles are iny the updated dictionary + # checks if movie_to_watch variable is not in updated_data["watchlist"] assert movie_to_watch not in updated_data["watchlist"] + # checks if movie_to_watch variable is not in updated_data["watched"] assert movie_to_watch not in updated_data["watched"] 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/viewing_party/party.py b/viewing_party/party.py index 5beac0ac8..b38fe1dcf 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,6 +1,7 @@ # ------------- WAVE 1 -------------------- from distutils.file_util import move_file +from pickle import FALSE def create_movie(title, genre, rating): @@ -22,60 +23,71 @@ def add_to_watchlist(user_data, movie): user_data["watchlist"].append(movie) return user_data -""" -Create a function named watch_movie. This function should... -take two parameters: user_data, title -the value of user_data will be a dictionary with a "watchlist" and a "watched" -This represents that the user has a watchlist and a list of watched movies -the value of title will be a string -This represents the title of the movie the user has watched -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 -If the title is not a movie in the user's watchlist: -return the user_data -Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions should not modify user_data. -""" - -# watch_movie(janes_data, "Non-Existent Movie Title") - def watch_movie(user_data, title): - movie_to_move = None - # dict_movie name of each dictionary in "watchlist" - for dict_movie in user_data["watchlist"]: - # if the tittle in that dictionary evaluate to the same then do the following - if title == dict_movie["title"]: - # create a new varaible - movie_to_move = dict_movie - else: - return user_data - -# you can't remove a dict from a for loop - user_data["watchlist"].remove(movie_to_move) - user_data["watched"].append(movie_to_move) - return user_data - - + if user_data["watchlist"] == None: + return user_data + else: + movie_to_move = None + # dict_movie name of each dictionary in "watchlist" + for dict_movie in user_data["watchlist"]: + # if the tittle in that dictionary evaluate to the same then do the following + if title == dict_movie["title"]: + # create a new varaible it becomes none when user_data["watchlist"] is removed + movie_to_move = dict_movie + # need to add this to a diffrent dictionary + # error here because condition needs to be true + if movie_to_move: + user_data["watched"].append(movie_to_move) + user_data["watchlist"].remove(movie_to_move) + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- -# def get_watched_avg_rating(user_data): -# # user has a list of watched movies: to calculate all movies average -# # user_data["watched"]["rating"] -# rating = 0 -# # empty watched list == 0.0 -# for movie_rating in user_data["watched"]: -# if user_data["watched"]["rating"] == None: -# user_data["watched"]["rating"] == 0.0 -# rating += user_data["watched"]["rating"] - -# average_rating = rating/len(user_data["watched"]) -# return average_rating + +def get_watched_avg_rating(user_data): + + all_ratings_added = 0 + if user_data["watched"] == []: + return 0 + for movie in user_data["watched"]: + rating = 0 + rating = movie["rating"] + all_ratings_added += rating + + average_rating = all_ratings_added/len(user_data["watched"]) + return average_rating + + +""" +Create a function named get_most_watched_genre. This function should... +take one parameter: user_data +the value of user_data will be a dictionary with a "watched" list of movie dictionaries. +Each movie dictionary has a key "genre". +This represents that the user has a list of watched movies. Each watched movie has a genre. +The values of "genre" is a string. +Determine which genre is most frequently occurring in the watched list +return the genre that is the most frequently watched +If the value of "watched" is an empty list, get_most_watched_genre should return None. +""" +def get_most_watched_genre(user_data): + genres_map = {} + for movie in user_data["watched"]: + if movie["genre"] not in genres_map: + genres_map[movie["genre"]] = 1 + else: + genres_map[movie["genre"]] += 1 -# # return average_rating + # iterate over the genre_map + maximum_key = None + maximum_value = 0 + for genre, quanity in genres_map.items(): + if quanity > maximum_value: + maximum_value = quanity + maximum_key = genre + return maximum_key + # ----------------------------------------- # ------------- WAVE 3 -------------------- From b0d7dfd2627170820462ce124dbf5cff72b58971 Mon Sep 17 00:00:00 2001 From: Jessica Date: Fri, 23 Sep 2022 09:35:54 -0700 Subject: [PATCH 3/4] Modified way 3 --- tests/test_wave_03.py | 18 +++++++------- viewing_party/party.py | 56 +++++++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..692d874ea 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Assert assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,10 +43,11 @@ 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() + # amandas_data in dictionary "friends" in first friend added a movie to watched list amandas_data["friends"][0]["watched"].append(INTRIGUE_3) # Act @@ -54,13 +55,12 @@ 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.") - # ************************************************************************************************* - # ****** 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 b38fe1dcf..5df1514df 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -59,18 +59,6 @@ def get_watched_avg_rating(user_data): average_rating = all_ratings_added/len(user_data["watched"]) return average_rating - -""" -Create a function named get_most_watched_genre. This function should... -take one parameter: user_data -the value of user_data will be a dictionary with a "watched" list of movie dictionaries. -Each movie dictionary has a key "genre". -This represents that the user has a list of watched movies. Each watched movie has a genre. -The values of "genre" is a string. -Determine which genre is most frequently occurring in the watched list -return the genre that is the most frequently watched -If the value of "watched" is an empty list, get_most_watched_genre should return None. -""" def get_most_watched_genre(user_data): genres_map = {} for movie in user_data["watched"]: @@ -79,7 +67,6 @@ def get_most_watched_genre(user_data): else: genres_map[movie["genre"]] += 1 - # iterate over the genre_map maximum_key = None maximum_value = 0 for genre, quanity in genres_map.items(): @@ -93,7 +80,48 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- - +def get_unique_watched(user_data): + # # compare movies of friends with user + # # create a list of dictionaries of the movies that have not been seen by the friends + # # return the list of dictionaries that friends have not watched + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_movies.append(movie["title"]) + + movie_list = [] + for movie in user_data["watched"]: + if movie["title"] not in friends_movies: + movie_list.append(movie) + + return movie_list + +""" +Create a function named get_friends_unique_watched. This function should... +take one parameter: user_data +the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" +This represents that the user has a list of watched movies and a list of friends +The value of "friends" is a list +Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. +Each movie dictionary has a "title". +Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies at least one of the user's friends have watched, but the user has not watched. +Return a list of dictionaries, that represents a list of movies +""" +def get_friends_unique_watched(user_data): + # user + movie_list = [] + for movie in user_data["watched"]: + movie_list.append(movie["title"]) + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] not in movie_list: + if movie not in friends_movies: + friends_movies.append(movie) + return friends_movies + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From 43e92cfa80835cabce9fedd7d799fb6edd0fd973 Mon Sep 17 00:00:00 2001 From: Jessica Date: Fri, 23 Sep 2022 09:55:37 -0700 Subject: [PATCH 4/4] Modified wave 4 and tried to pass test 1 in wave 4 --- tests/test_wave_04.py | 2 +- viewing_party/party.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..7524dc3d5 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() diff --git a/viewing_party/party.py b/viewing_party/party.py index 5df1514df..9984e5d72 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -97,19 +97,7 @@ def get_unique_watched(user_data): return movie_list -""" -Create a function named get_friends_unique_watched. This function should... -take one parameter: user_data -the value of user_data will be a dictionary with a "watched" list of movie dictionaries, and a "friends" -This represents that the user has a list of watched movies and a list of friends -The value of "friends" is a list -Each item in "friends" is a dictionary. This dictionary has a key "watched", which has a list of movie dictionaries. -Each movie dictionary has a "title". -Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies at least one of the user's friends have watched, but the user has not watched. -Return a list of dictionaries, that represents a list of movies -""" -def get_friends_unique_watched(user_data): - # user +def get_friends_unique_watched(user_data): movie_list = [] for movie in user_data["watched"]: movie_list.append(movie["title"]) @@ -121,11 +109,31 @@ def get_friends_unique_watched(user_data): if movie not in friends_movies: friends_movies.append(movie) return friends_movies - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + # user has access to + # iterate over subscriptions access a string + movie_list = [] + for movie in user_data["watched"]: + movie_list.append(movie["title"]) + + for subscription in user_data["subscriptions"]: + pass + # each friend has watched list + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + for host in movie["host"]: + if movie["title"] not in movie_list: + if movie not in friends_movies: + if host in movie_list: + friends_movies.append(movie) + + # ----------------------------------------- # ------------- WAVE 5 -------------------- # -----------------------------------------