diff --git a/README.md b/README.md index ba28bf2ab..0e8927822 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # Viewing Party +Fork and Clone -- Complete +Virtual Enviroment -- Complete +Dependencies -- Complete +Comment -- Setting up + +Access needs -- in-person/zoom, maybe mornings +Your learning style -- bringing ideas together and setting goals for working independently +Feedback -- email/slack, in-person +Communcation skill you want to improve with this experience -- meeting with people to improve communication + speaking redundantly, understanding google code + +Wave 01 -- Mon +Wave 02 -- Tues +Wave 03 -- Tues +Wave 04 -- Wed +Wave 05 -- Thurs +Turn in Friday 10am + + ## Skills Assessed Solving problems with... diff --git a/play_tester.py b/play_tester.py index 9e2aecf48..21fc6fb36 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 669efee6a..5852086a1 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_non_empty_user_watched(): # Arrange movie = { @@ -99,7 +99,7 @@ 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() +#@pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -120,7 +120,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_adds_movie_to_non_empty_user_watchlist(): # Arrange movie = { @@ -140,7 +140,7 @@ 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() +#@pytest.mark.skip() failing - needs to add assertions def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -159,12 +159,15 @@ 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.") + + #raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* + assert updated_data["watched"] == [{ "title": MOVIE_TITLE_1, "genre": GENRE_1, + "rating": RATING_1 }] -@pytest.mark.skip() +#@pytest.mark.skip() - failing - need to add assertions def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -183,12 +186,15 @@ 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.") + # raise Exception("Test needs to be completed.") # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* + assert updated_data["watchlist"] == [FANTASY_1] + assert updated_data["watched"] == [FANTASY_2, movie_to_watch] + # order matters ie FANTASY_2, movie_to_watch -@pytest.mark.skip() +#@pytest.mark.skip() #passing 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 19f045c79..64b62729d 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_most_watched_genre_order_mixed(): # Arrange janes_data = clean_wave_2b_data() @@ -51,7 +51,7 @@ def test_most_watched_genre_order_mixed(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2b_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..c993de869 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() @@ -55,12 +55,14 @@ 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 ********** - # ************************************************************************************************** + # raise Exception("Test needs to be completed.") + # ********************************************************************* + # ****** Complete the Assert Portions of these tests ********** + # ********************************************************************* + assert FANTASY_4 in friends_unique_movies + assert INTRIGUE_3 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..79ab18ff7 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 b2ba9ad33..3c7a5d2be 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 = { @@ -53,12 +53,19 @@ def test_new_genre_rec_from_empty_friends(): ] } - raise Exception("Test needs to be completed.") +#Act + recommendations = get_new_rec_by_genre(sonyas_data) + +# Assert + assert len(recommendations) == 0 + + #raise Exception("Test needs to be completed.") # ********************************************************************* # ****** Complete the Act and Assert Portions of these tests ********** # ********************************************************************* -@pytest.mark.skip() + +#@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -72,7 +79,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 +101,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..32ff969d5 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,231 @@ # ------------- WAVE 1 -------------------- - def create_movie(title, genre, rating): - pass + ''' + input: title, genre, rating of a movie + output: movie dictionary with 3 keys + ''' + if not title: + return None + if not genre: + return None + if not rating: + return None + + movie_dict = {'title': title, 'genre': genre, 'rating': rating} + + return movie_dict + + +def add_to_watched(user_data, movie): + ''' + input: user_data with a key for "watched" , movie + output: user_data with movie passed in added + ''' + movies_user_has_watched = user_data["watched"] + # append (represent) movie to list of dict + movies_user_has_watched.append(movie) + + return user_data + + +def add_to_watchlist(user_data, movie): + ''' + input: user_data with a key for "watchlist", movie + output: user_data with movie added to the "watchlist + ''' + movies_user_wants_to_watch = user_data["watchlist"] + + if movies_user_wants_to_watch is None: + # an empty list rep that the user has no movies in their watchlist + movies_user_wants_to_watch = [] + # append (represent) movie to list of dict + movies_user_wants_to_watch.append(movie) + return user_data + + +def watch_movie(user_data, title): + ''' + input: user_data is a dictionary with a "watchlist" and a "watched" list of movies; + output: user_data with a movie that moves from "watchlist" to "watched" + ''' + user_watchlist_movies = user_data["watchlist"] + watched_movies = user_data["watched"] + + # iterate through the watchlist to find if movie in there + for movie in user_watchlist_movies: + #if movie is already in watchlist, remove it and add it to watched movies + if title == movie['title']: + user_watchlist_movies.remove(movie) + watched_movies.append(movie) + + return user_data + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries + output: average rating of all movies in the "watched" list, where empty list has a value of 0.0 + ''' + #initiate sum to 0.0 and guard against an empty watched list + sum = 0.0 + if not user_data['watched']: + return sum + + #grab values of rating from each movie dictionary and add them to the sum + for movie in user_data['watched']: + sum += movie['rating'] + + #return average (sum / # of watched movies) + return sum / len(user_data['watched']) + + +def get_most_watched_genre(user_data): + ''' + input: user_data is a dictionary with a "watched" list of; each movie has a "genre" key + output: genre that's most frequently watched from the watched list. Return None if "watched" is empty + ''' + genre_dict = {} + #guard against an empty watched list + if not user_data['watched']: + return None + + #add genre of each watched movie as a key, adding to its frequency everytime + for movie in user_data['watched']: + movie_genre = movie['genre'] + + #if the genre is not in genre_dict, add it as a key with a value of 1, else, add to genre frequency + if not movie_genre in genre_dict: + genre_dict[movie_genre] = 1 + else: + genre_dict[movie_genre] += 1 + + #return genre with highest value from genre_dict + most_popular_genre = max(genre_dict, key=genre_dict.get) + + return most_popular_genre # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - +def get_unique_watched(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" list + output: list of dictionaries that represents a list of movies that user has uniquely watched, ("friends" have not) + ''' + user_watched_movies = user_data['watched'] + friends_watched_movies = user_data['friends'] + friend_movie_list = [] + + if len(friends_watched_movies) == 0: + return user_watched_movies + + #iterate through the list of movies that friends have watched + for movie in friends_watched_movies: + friend_movie_list += movie["watched"] + #initialize an empty list for unique movies + unique_watched_movies = [] + + #iterate through the list of movies the user has watched + for movie in user_watched_movies: + #if the movie hasn't been watched by friends and it's not yet in the list of unique movies they've watched + if movie not in friend_movie_list and movie not in unique_watched_movies: + #add movie to unique movies, guard against duplicates + unique_watched_movies.append(movie) + + return unique_watched_movies + + +def get_friends_unique_watched(user_data): + ''' + input: user_data is a dictionary with a "watched" list of movies dictionaries and a "friends" list + output: list of movies that at least one friend has watched but user has not + ''' + user_watched_movies = user_data['watched'] + list_of_friends = user_data['friends'] + friend_unique_watched_movies = [] + + #iterates through all of the friends in the list + for friend in list_of_friends: + #for each friend, iterate to find what each of them has watched + for movie in friend["watched"]: + #if the movie isn't something the user has watched and hasn't yet beed added to the friends unique list, add it + if movie not in user_watched_movies and movie not in friend_unique_watched_movies: + friend_unique_watched_movies.append(movie) + + return friend_unique_watched_movies + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + ''' + input: user_data with a field for "subscriptions"; "friends" watchlist now has a field for "host" that outlines streaming service + output: movie recommendations for user if they haven't watched it yet and its a subscription they have + ''' + recs = [] + friends = user_data['friends'] + user_watched_movies = user_data['watched'] + service_subscriptions = user_data['subscriptions'] + + #iterate through each friend to get a list of the movies they've watched + for friend in friends: + friend_movie_list = friend['watched'] + + #iterate through each movie friends have watched to look for the host + for movie in friend_movie_list: + movie_host = movie['host'] + #if the movie host is also in the subscriptions that the user has; the user hasn't watched the movie yet + if movie_host in service_subscriptions and movie not in user_watched_movies and movie not in recs: + #add movie to recs, guarding for duplicates + recs.append(movie) + + return recs + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + ''' + input: user_data which includes "friends" list of watched movies + output: a recommended list of movies for the user, if they haven't watched it and it matches their most frequent genre + ''' + recommended_movies = [] + user_watched_movies = user_data['watched'] + user_frequently_watched_genre = get_most_watched_genre(user_data) + friends_watched_movies = get_friends_unique_watched(user_data) + + # go through the list of movies that only friends have watched + for movie in friends_watched_movies: + #get the genre of the movie + movie_genre = movie['genre'] + # if the movie isn't one that the user has watched and the movie genre matches their favorite: + if not movie in user_watched_movies and movie_genre == user_frequently_watched_genre: + #append the movie to the recommended list + recommended_movies.append(movie) + + return recommended_movies + + +def get_rec_from_favorites(user_data): + ''' + input: user_data with a "favorites" movie list + output: a recommended list of movies for friends, if it's in the "favorites" list and none of the friends have watched it yet + ''' + user_watched_movies = get_unique_watched(user_data) + favorite_movies = user_data['favorites'] + reccommended_from_favorites = [] + + #iterate through each movie in favorites list + for movie in favorite_movies: + #append movies to the recommendations if it's in the favorites list and the user has uniquely watched it + if movie in user_watched_movies: + reccommended_from_favorites.append(movie) + + return reccommended_from_favorites \ No newline at end of file