diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6be6994a5..b46781d26 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 @@ -15,11 +15,11 @@ def test_create_successful_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie["title"] == MOVIE_TITLE_1 - assert new_movie["genre"] == GENRE_1 - assert new_movie["rating"] == pytest.approx(RATING_1) + assert new_movie["title"] == movie_title + assert new_movie["genre"] == genre + assert new_movie["rating"] == pytest.approx(rating) -@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,16 @@ 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']==[{'title': 'It Came from the Stack Trace', 'genre': 'Horror', 'rating': 3.5}] + + + - 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 +145,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"] ==[{'title': 'The Lord of the Functions: The Two Parameters', 'genre': 'Fantasy', 'rating': 4.0}, {'title': 'It Came from the Stack Trace', 'genre': 'Horror', 'rating': 3.5}] - 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 @@ -163,5 +167,5 @@ def test_does_nothing_if_movie_not_in_watchlist(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 1 - assert movie_to_watch not in updated_data["watchlist"] - assert movie_to_watch not in updated_data["watched"] + assert updated_data['watchlist']==[{'title': 'The Lord of the Functions: The Fellowship of the Function', 'genre': 'Fantasy', 'rating': 4.8}] + assert updated_data['watched']==[{'title': 'The Lord of the Functions: The Two Parameters', 'genre': 'Fantasy', 'rating': 4.0}] \ No newline at end of file diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..4a9749c89 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..36f9a4575 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..67f432045 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() + 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() + 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() + 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..7d81641cf 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,27 +52,30 @@ def test_new_genre_rec_from_empty_friends(): } ] } + recommendations = get_new_rec_by_genre(sonyas_data) - raise Exception("Test needs to be completed.") + # Assert + assert len(recommendations) == 0 + + #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() # Act recommendations = get_rec_from_favorites(sonyas_data) - # Assert assert len(recommendations) == 2 assert FANTASY_2b in recommendations 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 +97,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..3e40f0e5c 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,232 @@ + # ------------- WAVE 1 -------------------- +#------------------------------------------ def create_movie(title, genre, rating): - pass + if title ==None: + return None + elif genre ==None: + return None + elif rating== None: + return None + else: + new_movie = {'title': title, 'genre': genre, 'rating': rating} + return new_movie + + +def add_to_watched(user_data, movie): + + #begin list of watched movies + updated_data=user_data.copy() + watch_list=[] + + #add new movie to list + watch_list.append(movie) + print(watch_list) + + #add list to dictionary + updated_data['watched']=watch_list + + #OUTPUT IS dictionary of list. Key is 'Watched" value is list of movies [index, movie] + return updated_data + +def add_to_watchlist(user_data, movie): + + updated_data=user_data.copy() + + #create list of watched movies + watch_list=[] + watch_list.append(movie) + print(watch_list) + + #add list to dictionary + updated_data['watchlist']=watch_list + print(updated_data) + return updated_data + +def watch_movie(user_data, title): + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watched"].append(movie) + user_data["watchlist"].remove(movie) + return user_data + + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + + sum=0 + total_movies_in_list=0 + if len(user_data['watched'])==0: + return sum + else: + for movie in user_data["watched"]: + sum+=movie['rating'] + total_movies_in_list+=1 + return sum/total_movies_in_list +def get_most_watched_genre(user_data): + + fantasy_count=0 + action_count=0 + intrigue_count=0 + horror_count=0 + genre_dict=dict() + + #create genre_count by genre, add to genre_dict[genre][genre_count] + for movie in user_data["watched"]: + if movie['genre']=='Fantasy': + fantasy_count+=1 + genre_dict['Fantasy']= fantasy_count + elif movie['genre']=='Action': + action_count+=1 + genre_dict['Action']=action_count + elif movie['genre']=='Intrigue': + intrigue_count+=1 + genre_dict['Intrigue']=intrigue_count + elif movie['genre']=='Horror': + horror_count+=1 + genre_dict['Horror']= horror_count + + #find max_count=max(genre_dict.values()) + if len(genre_dict)==0: + return None + else: + popular_genre=max(genre_dict, key=genre_dict.get) + return popular_genre + + + + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - +def get_unique_watched(user_data): + + #create total list of movies + list_of_watched_movies=[] + for friend in user_data['friends']: + for movie in friend['watched']: + list_of_watched_movies.append(movie) + + list_of_unique_movies=[] + #create list of unique movies + for watched_movie in user_data['watched']: + if watched_movie not in list_of_watched_movies: + list_of_unique_movies.append(watched_movie) + + return list_of_unique_movies +#write helper function + + +def get_friends_unique_watched(user_data): + + #create total list of all watched_movies + list_of_watched_movies=[] + for friend in user_data['friends']: + for movie in friend['watched']: + list_of_watched_movies.append(movie) + + + #create list of unique movies for user + list_of_unique_movies=[] + for watched_movie in user_data['watched']: + if watched_movie not in list_of_watched_movies: + list_of_unique_movies.append(watched_movie) + + #from list_of_watched_movies subtract list_of_unique_movies + friends_unique_movies=[] + for unique_movie in list_of_watched_movies: + if unique_movie not in user_data['watched']: + friends_unique_movies.append(unique_movie) + + #ensure no duplicates in friends_unique_movie_list + result=[] + for i in friends_unique_movies: + if i not in result: + result.append(i) + print(len(result)) + friends_unique_movies=result + + return friends_unique_movies + + + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + + #create list of all movies like wave 3 (movies_to_recommend) + movies_to_recommend=[] + for friend in user_data['friends']: + for movie in friend['watched']: + movies_to_recommend.append(movie) + + #create list of all hosts that are available (all_available_hosts) + all_available_hosts=[] + for host in user_data["subscriptions"]: + all_available_hosts.append(host) + + #create recommended_movie_list to return + recommended_movie_list=[] + + #checks 2 conditions for recommended movie (wave 3 function) + friends_unique_watched=get_friends_unique_watched(user_data) + + #check movies_to_recommend meet conditions for being recommended + if len(movies_to_recommend)>0: + for movie_to_recommend in movies_to_recommend: + + #if host is available in friends["subscriptions"]_list + if movie_to_recommend['host'] not in all_available_hosts: + continue + + #if not in user['watched'] and is in user['friends']['watched'] + if movie_to_recommend in friends_unique_watched: + recommended_movie_list.append(movie_to_recommend) + + return recommended_movie_list + # ----------------------------------------- # ------------- WAVE 5 -------------------- -# ----------------------------------------- +# ---------------------------------------- + +def get_new_rec_by_genre(user_data): + #get most_popular genre from user_data['watched']['genre'] + fav_genre=get_most_watched_genre(user_data) + + #call get_friends_unique_watched(user_data) to check conditions for recommendation_list + friends_unique_watched=get_friends_unique_watched(user_data) + + #filter list of friends_unique_watched by genre to generate recommended movie list by genre + rec_movie_list_by_genre=[] + for movie in friends_unique_watched: + if movie['genre']==fav_genre: + rec_movie_list_by_genre.append(movie) + return rec_movie_list_by_genre + +# ---------------------------------------------- +# is sim to get_friends_unique_watched function with user_data['favorites'], instead of user_data['watched'] +def get_rec_from_favorites(user_data): + + #get total list of all friends' watched_movies + movies_friends_have_watched=[] + for friend in user_data['friends']: + for movie in friend['watched']: + movies_friends_have_watched.append(movie) + + #create list of user's favorite movies that is not in friends' watched movie_list + favorite_movies_list=[] + for favorite_movie in user_data['favorites']: + if favorite_movie not in movies_friends_have_watched: + favorite_movies_list.append(favorite_movie) + + return favorite_movies_list