diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..d8e767e8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..be630e4d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/viewing-party.iml b/.idea/viewing-party.iml new file mode 100644 index 00000000..a3166aba --- /dev/null +++ b/.idea/viewing-party.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index ba28bf2a..bf4ab2c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Viewing Party - -## Skills Assessed - +## Comment by Sarah --> 'Hello, i dont know how to comment' +## Skills Assessed --> Solving problems with... - Conditional logic diff --git a/play_tester.py b/play_tester.py index 9e2aecf4..21fc6fb3 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_01.py b/tests/test_wave_01.py index 669efee6..0fc36996 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,6 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +18,6 @@ def test_create_successful_movie(): assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +30,6 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +42,6 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +54,6 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +74,6 @@ 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() def test_adds_movie_to_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +93,6 @@ 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() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -120,7 +113,6 @@ 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() def test_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -140,7 +132,6 @@ 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() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -158,13 +149,10 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert 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" ********** - # ******************************************************************************************* + 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 -@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -182,13 +170,10 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - - raise Exception("Test needs to be completed.") - # ******************************************************************************************* - # ****** Add assertions here to test that the correct movie was added to "watched" ********** - # ******************************************************************************************* + assert updated_data["watched"][1]["title"] == movie_to_watch["title"] + assert updated_data["watched"][1]["genre"] == movie_to_watch["genre"] + assert updated_data["watched"][1]["rating"] == movie_to_watch["rating"] -@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 19f045c7..0119c781 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +13,6 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +25,6 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +36,6 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() def test_most_watched_genre_order_mixed(): # Arrange janes_data = clean_wave_2b_data() @@ -51,7 +47,6 @@ def test_most_watched_genre_order_mixed(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2b_data() -@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 04642936..214c6ed3 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +15,6 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +26,6 @@ def test_my_not_unique_movies(): # Assert assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,7 +40,6 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -54,13 +50,10 @@ 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 ********** - # ************************************************************************************************** - -@pytest.mark.skip() + assert INTRIGUE_3 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 49966907..8431f307 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,6 @@ 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 +15,6 @@ 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 +36,6 @@ 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 b2ba9ad3..03f4b922 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +16,6 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +36,6 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -53,12 +50,12 @@ def test_new_genre_rec_from_empty_friends(): ] } - raise Exception("Test needs to be completed.") - # ********************************************************************* - # ****** Complete the Act and Assert Portions of these tests ********** - # ********************************************************************* + # Act + recommendations = get_new_rec_by_genre(sonyas_data) -@pytest.mark.skip() + # Assert + assert len(recommendations) == 0 + def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -72,7 +69,6 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -94,7 +90,6 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@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 6d34a6b5..f1386cac 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,180 @@ # ------------- WAVE 1 -------------------- - def create_movie(title, genre, rating): - pass + ''' + Creates a dictionary representing a movie with the given title, genre, + and rating. + ''' + if not (title and genre and rating): + return None + return {'title': title, 'genre': genre, 'rating': rating} + +def add_to_watched(user_data, movie): + ''' + Adds a movie to the user's watched list. + ''' + user_data['watched'].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + ''' + Adds a movie to the user's watchlist. + ''' + user_data['watchlist'].append(movie) + return user_data + +def watch_movie(user_data, title): + ''' + Moves a movie from the user's watchlist to the watched list if the + movie title is found. + ''' + + for movie in user_data['watchlist']: + if title == movie['title']: + user_data['watched'].append(movie) + user_data['watchlist'].remove(movie) + break + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + ''' + Calculates the average rating of all movies watched by the user. If + no movies are watched, returns 0.0. + ''' + total_ratings = 0.0 + + if not user_data['watched']: + return total_ratings + + for movie in user_data['watched']: + total_ratings += movie['rating'] + return total_ratings / len(user_data['watched']) + +def get_most_watched_genre(user_data): + ''' + Determines the genre most frequently watched by the user. Returns + None if no movies are watched. + ''' + if not user_data['watched']: + return None + + genre_count = {} + for movie in user_data['watched']: + genre = movie['genre'] + genre_count[genre] = genre_count.get(genre, 0) + 1 + + most_watched_genre = None + max_count = 0 + for genre, count in genre_count.items(): + if count > max_count: + max_count = count + most_watched_genre = genre + + return most_watched_genre # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + ''' + Retrieves a list of movies that the user has watched, but their + friends have not. + ''' + friends_watched_list = get_friends_watched_list(user_data) + return get_unique_list(user_data['watched'], friends_watched_list) + +def get_friends_unique_watched(user_data): + ''' + Retrieves a list of movies that the user's friends have watched, but + the user has not. + ''' + friends_watched_list = get_friends_watched_list(user_data) + unique_watched_list = get_unique_list(friends_watched_list, user_data['watched']) + + unique_movies_list = [] + movies_seen = set() + + for movie in unique_watched_list: + movie_tuple = tuple(movie.items()) + if movie_tuple not in movies_seen: + movies_seen.add(movie_tuple) + unique_movies_list.append(movie) + + return unique_movies_list + + +def get_friends_watched_list(user_data): + ''' + Retrieves a list of all movies watched by the user's friends. + ''' + return ([movie for friend in user_data['friends'] + for movie in friend['watched']]) + +def get_unique_list(source_list, exclusion_list): + ''' + Returns a list of items found in the source list, excluding those + from the exclusion list. + ''' + return [item for item in source_list if item not in exclusion_list] - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + ''' + Retrieves a list of recommended movies that friends have watched and + are available on the streaming services the user has access to. + ''' + friends_unique_watched = get_friends_unique_watched(user_data) + + return ([movie for movie in friends_unique_watched + if movie['host'] in user_data['subscriptions']]) # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + ''' + Compiles a list of recommended movies for the user. Movies added to + this list will match the user's most frequent genre, will have been + watched by at least one of the user's friends, and will not have been + watched yet by the user. + ''' + if (not user_data['watched'] or not any(friend['watched'] + for friend in user_data['friends'])): + return [] + + available_recs = get_available_recs(user_data) + most_watched_genre = get_most_watched_genre(user_data) + + return ([rec for rec in available_recs + if rec['genre'] == most_watched_genre + and not any(movie['title'] == rec['title'] + for movie in user_data['watched'])]) + +def get_rec_from_favorites(user_data): + ''' + Compiles a list of recommended movies from the user's favorites that + no friends have watched. + ''' + + if not user_data['favorites']: + return [] + + if not user_data['friends']: + return user_data['favorites'] + + friends_watched_titles = ({ + movie['title'] for friend in user_data['friends'] + for movie in friend['watched'] + }) + + rec_from_favorites = ([ + favorite for favorite in user_data['favorites'] + if favorite['title'] not in friends_watched_titles + ]) + return rec_from_favorites \ No newline at end of file