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/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..343d0c503 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Assert assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,7 +43,7 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -54,13 +54,16 @@ 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.") + # 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/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/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 6d34a6b5f..5775d9b00 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,248 @@ # ------------- 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 -------------------- # ----------------------------------------- +# my own work with the help of tutor +def get_watched_avg_rating(user_data): + count = 0 + average_rating = 0 + + 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): + 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 +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): + index = 0 + genres = [] + 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: + 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 + + # 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 = [] + + # + for movie in user_data["watched"]: + if movie["title"] not in friend_set: + unique_list.append(movie) + + return unique_list +''' + + # second attempt using a list +# 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 = [] + 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) # the new value of user_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 + + 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 + # part 2 +def get_friends_unique_watched(user_data): + # will need to access watched inside user_data + user_movies= [] + friends_movies = [] + # create a new list left_to_watch + left_to_watch = [] + + # and compare it to friends["watched"] + for movie in user_data["watched"]: + 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: # 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 -------------------- # ----------------------------------------- +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 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + user_movies = [] + friends_movies = [] + 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"]: + 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 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 + 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 + + + + + +