Skip to content

Commit

Permalink
Uncomments Wave 05 user data in play_tester.py, comments out all othe…
Browse files Browse the repository at this point in the history
…r waves. Comments out all skip decorators in test_wave_05.py, completes test code for test_new_genre_rec_from_empty_friends(). Adds new function get_new_rec_by_genre() to Wave 5 in party.py, passing first 3 wave 5 tests. Cleans up inconsistent whitespace between functions in party.py.
  • Loading branch information
svankoch committed Sep 26, 2024
1 parent ee3431f commit ab10bec
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
16 changes: 8 additions & 8 deletions play_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
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 02 user_data-----")
# pp.pprint(clean_wave_2_data())

#print("\n-----Wave 03 user_data-----")
#pp.pprint(clean_wave_3_data())
Expand All @@ -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())
20 changes: 13 additions & 7 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -53,12 +53,18 @@ 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()
Expand All @@ -72,7 +78,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 = {
Expand All @@ -94,7 +100,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 = {
Expand Down
47 changes: 41 additions & 6 deletions viewing_party/party.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# ------------- WAVE 1 --------------------

def create_movie(title, genre, rating):
if title is None or genre is None or rating is None:
return None
return {'title': title, 'genre': genre, 'rating': rating}


def add_to_watched(user_data, movie):
watched_list = user_data["watched"]
watched_list.append(movie)
return user_data


def add_to_watchlist(user_data: dict, movie: dict):

movie_list = user_data["watchlist"]
movie_list.append(movie)
return user_data


def watch_movie(user_data, title):
watchlist = user_data['watchlist']
watched = user_data['watched']
Expand All @@ -31,7 +27,6 @@ def watch_movie(user_data, title):
# -----------------------------------------
# ------------- WAVE 2 --------------------
# -----------------------------------------

def get_watched_avg_rating(user_data):
'''
Calculates the average rating of all movies watched by the user.
Expand Down Expand Up @@ -181,4 +176,44 @@ def get_available_recs(user_data):
# -----------------------------------------
# ------------- 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.
Parameters:
user_data (dict): A dictionary with a "watched" list of movie
dictionaries. Each movie dictionary contains information on the
genre, rating, and title of the movie.
Returns:
recs_by_genre (list): A list of dictionaries that represents a
list of movies recommended for the user.
'''
if not user_data['watched']:
return []

for friend in user_data['friends']:
is_friends_empty = True
if friend['watched']:
is_friends_empty = False
break
if is_friends_empty:
return []

recs_by_genre = []
available_recs = get_available_recs(user_data)
most_watched_genre = get_most_watched_genre(user_data)

for rec in available_recs:
if rec['genre'] == most_watched_genre:
is_rec_found = False
for movie in user_data['watched']:
if rec['title'] == movie['title']:
is_rec_found = True
break
if not is_rec_found:
recs_by_genre.append(rec)

return recs_by_genre

0 comments on commit ab10bec

Please sign in to comment.