From 203169c82fe74bb757de3e2223d482733f489a45 Mon Sep 17 00:00:00 2001 From: San Date: Fri, 25 Mar 2022 11:42:19 -0500 Subject: [PATCH 1/2] keeptrying --- play_tester.py | 12 ++--- tests/test_wave_01.py | 18 +++---- tests/test_wave_02.py | 9 ++-- tests/test_wave_03.py | 8 +-- viewing_party/party.py | 110 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 132 insertions(+), 25 deletions(-) diff --git a/play_tester.py b/play_tester.py index 9e2aecf48..6928c964b 100644 --- a/play_tester.py +++ b/play_tester.py @@ -9,16 +9,16 @@ 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()) -#print("\n-----Wave 03 user_data-----") -#pp.pprint(clean_wave_3_data()) +print("\n-----Wave 03 user_data-----") +pp.pprint(clean_wave_3_data()) # Wave 04 user data #print("\n-----Wave 04 user_data-----") diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c033af09f..2274225c4 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"] is 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"] is GENRE_1 assert updated_data["watched"][0]["rating"] is 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"] is GENRE_1 assert updated_data["watchlist"][0]["rating"] is RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -123,7 +123,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** 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 @@ -146,7 +146,7 @@ def test_moves_movie_from_watchlist_to_watched(): # ****** 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..74e47d66e 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,8 @@ 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 +15,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 +28,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 +40,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 7c42a63c4..9f3c915b3 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(): # Arrange 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() diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..a571de14a 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,18 +1,124 @@ # ------------- WAVE 1 -------------------- -def create_movie(title, genre, rating): - pass +from logging.handlers import RotatingFileHandler +from re import U +from tests.test_constants import MOVIE_TITLE_1, USER_DATA_2 +import statistics +def create_movie(movie_title, genre, rating): + if not movie_title or not genre or not rating: + return None + new_movie = { + "title" : movie_title, + "genre": genre, + "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 + +def watch_movie(user_data, title): + for movie_to_watch in user_data["watchlist"]: + if movie_to_watch["title"] == title: + user_data["watchlist"].remove(movie_to_watch) + user_data["watched"].append(movie_to_watch) + return user_data + +def watched_movie(user_data, title): + for movie_to_watch in user_data["watched"]: + if movie_to_watch["title"] == movie_to_watch["title"]: + user_data["watchlist"].remove(movie_to_watch) + user_data["watched"].append(movie_to_watch) + return user_data + +def nonexistent_movie(user_data, title): + for movie_to_watch in user_data["watched"]: + if movie_to_watch["title"] != movie_to_watch["title"]: + return None + + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + avg_rating_list= [] + check_empty = [] + default_to_zero = 0 + if bool(user_data["watched"]) == False: + avg_rating_list.append(default_to_zero) + avg = sum(avg_rating_list)/len(avg_rating_list) + return avg + else: + for movie in user_data["watched"]: + avg_rating_list.append(movie["rating"]) + avg = sum(avg_rating_list)/len(avg_rating_list) + return avg + + +def get_most_watched_genre(user_data): + get_most_watched = [] + if bool(user_data["watched"]) == False: + get_most_watched.append(None) + popular_genre = statistics.mode(get_most_watched) + return popular_genre + + else: + for movie in user_data["watched"]: + get_most_watched.append(movie["genre"]) + popular_genre = statistics.mode(get_most_watched) + return popular_genre # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +# get list of all friends movies(titles) +# check if each users movie is in list of movie(title) + +def get_unique_watched(user_data): + unique_list = [] + friends_titles= [] + + for friends_data in user_data["friends"]: + for friends_movie in friends_data["watched"]: + friends_titles.append(friends_movie["title"]) + + + for movie in user_data["watched"]: + if movie["title"] not in friends_titles: + unique_list.append(movie) + + return unique_list + +def get_friends_unique_watched(user_data): + user_unique_list = [] + friends_titles= [] + friend_unique_list =[] + + for friends_data in user_data["friends"]: + for friends_movie in friends_data["watched"]: + friends_titles.append(friends_movie) + + + for movie in user_data["watched"]: + user_unique_list.append(movie) + for movie in friends_titles: + if movie not in user_unique_list: + friend_unique_list.append(movie) + + return friend_unique_list + + + + + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- From ba1d83efb36e95f7444fee3f46ce680651cc7791 Mon Sep 17 00:00:00 2001 From: San Date: Fri, 25 Mar 2022 19:04:15 -0500 Subject: [PATCH 2/2] updated --- tests/test_wave_03.py | 2 +- tests/test_wave_04.py | 4 +- tests/test_wave_05.py | 12 ++--- viewing_party/party.py | 102 ++++++++++++++++++++++++++++++++--------- 4 files changed, 89 insertions(+), 31 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 9f3c915b3..9771935b9 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -59,7 +59,7 @@ def test_friends_unique_movies_not_duplicated(): # ****** 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 72888410f..8cb037a87 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 = { diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 8ce5b57db..6ff912ca9 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 = { @@ -57,7 +57,7 @@ def test_new_genre_rec_from_empty_friends(): # ****** 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() @@ -71,7 +71,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 = { @@ -92,7 +92,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 a571de14a..705a77e7c 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,10 +1,14 @@ # ------------- WAVE 1 -------------------- +from enum import unique from logging.handlers import RotatingFileHandler -from re import U +from re import L, U +import re from tests.test_constants import MOVIE_TITLE_1, USER_DATA_2 +import copy import statistics + def create_movie(movie_title, genre, rating): if not movie_title or not genre or not rating: return None @@ -48,7 +52,7 @@ def nonexistent_movie(user_data, title): def get_watched_avg_rating(user_data): avg_rating_list= [] - check_empty = [] + # check_empty = [] default_to_zero = 0 if bool(user_data["watched"]) == False: avg_rating_list.append(default_to_zero) @@ -96,34 +100,88 @@ def get_unique_watched(user_data): return unique_list def get_friends_unique_watched(user_data): - user_unique_list = [] - friends_titles= [] - friend_unique_list =[] - - for friends_data in user_data["friends"]: - for friends_movie in friends_data["watched"]: - friends_titles.append(friends_movie) + friends_movie_list =[] + for friend_data in user_data["friends"]: + for friends_movie in friend_data["watched"]: + if friends_movie not in user_data["watched"] and friends_movie not in friends_movie_list: + friends_movie_list.append(friends_movie) + return friends_movie_list - for movie in user_data["watched"]: - user_unique_list.append(movie) - - - for movie in friends_titles: - if movie not in user_unique_list: - friend_unique_list.append(movie) - - return friend_unique_list +# ----------------------------------------- +# ------------- WAVE 4 -------------------- +# ----------------------------------------- +def get_available_recs(user_data): + recommendations = [] + unique_watch_list = get_friends_unique_watched(user_data) + + for user_sub in range(len(user_data["subscriptions"])): + for sub in range(len(unique_watch_list)): + if user_data["subscriptions"][user_sub] == unique_watch_list[sub]["host"]: + recommendations.append(unique_watch_list[sub]) - -# ----------------------------------------- -# ------------- WAVE 4 -------------------- -# ----------------------------------------- + return recommendations # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + + mode_genre = get_most_watched_genre(user_data) + new_recommendations = [] + rec_recommendations = get_friends_unique_watched(user_data) + + for user_movie in rec_recommendations: + if rec_recommendations[rec_recommendations.index(user_movie)]["genre"] == mode_genre: + new_recommendations.append(user_movie) + + return new_recommendations + + + +def get_rec_from_favorites(user_data): + rec_recommendations = [] + unique_watch_list = get_unique_watched(user_data) + + for user_movie in unique_watch_list: + if user_movie in user_data["favorites"]: + rec_recommendations.append(user_movie) + + return rec_recommendations + + + + + #refactored code + + # user_unique_list = [] + # friends_titles= [] + # friend_unique_list = [] + + # for friends_data in user_data["friends"]: + # for friends_movie in friends_data["watched"]: + # friends_titles.append(friends_movie) + + + # for movie in user_data["watched"]: + # user_unique_list.append(movie) + + + # for movie in friends_titles: + # if movie not in user_unique_list: + # friend_unique_list.append(movie) + + + # return friend_unique_list + + # for friends_data in user_data["friends"]: + # for friends_movie in friends_data["watched"]: + # friends_titles.append(friends_movie["title"]) + + # for movie in user_data["watched"]: + # if movie["title"] not in friends_titles: + # unique_list.append(movie) \ No newline at end of file