Skip to content

Commit

Permalink
waves 01-05 complete, added docstrings for further clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
nishatsalsabil committed Mar 25, 2022
1 parent 8fc440f commit bcdcfc8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 22 deletions.
8 changes: 4 additions & 4 deletions play_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# pp.pprint(clean_wave_3_data())

# Wave 04 user data
print("\n-----Wave 04 user_data-----")
pp.pprint(clean_wave_4_data())
# print("\n-----Wave 04 user_data-----")
# 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())
6 changes: 4 additions & 2 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_moves_movie_from_watchlist_to_empty_watched():
# *******************************************************************************************

# Test 8
pytest.mark.skip()
#pytest.mark.skip()
def test_moves_movie_from_watchlist_to_watched():
# Arrange
movie_to_watch = HORROR_1
Expand All @@ -156,10 +156,12 @@ def test_moves_movie_from_watchlist_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"]
# *******************************************************************************************

# Test 9
pytest.mark.skip()
#pytest.mark.skip()
def test_does_nothing_if_movie_not_in_watchlist():
# Arrange
movie_to_watch = HORROR_1
Expand Down
3 changes: 3 additions & 0 deletions tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from viewing_party.party import *
from tests.test_constants import *


# Test 19
#@pytest.mark.skip()
def test_get_available_friend_rec():
Expand Down Expand Up @@ -39,3 +40,5 @@ def test_no_available_friend_recs():

# Arrange
assert len(recommendations) == 0


22 changes: 15 additions & 7 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from viewing_party.party import *
from tests.test_constants import *

@pytest.mark.skip()
# Test 21
#@pytest.mark.skip()
def test_new_genre_rec():
# Arrange
sonyas_data = clean_wave_5_data()
Expand All @@ -17,7 +18,8 @@ def test_new_genre_rec():
assert FANTASY_4b in recommendations
assert sonyas_data == clean_wave_5_data()

@pytest.mark.skip()
# Test 22
#@pytest.mark.skip()
def test_new_genre_rec_from_empty_watched():
# Arrange
sonyas_data = {
Expand All @@ -38,7 +40,8 @@ def test_new_genre_rec_from_empty_watched():
# Assert
assert len(recommendations) == 0

@pytest.mark.skip()
# Test 23
#@pytest.mark.skip()
def test_new_genre_rec_from_empty_friends():
# Arrange
sonyas_data = {
Expand All @@ -52,12 +55,15 @@ def test_new_genre_rec_from_empty_friends():
}
]
}
# Act
recommendations = get_new_rec_by_genre(sonyas_data)

# *********************************************************************
# ****** Complete the Act and Assert Portions of theis tests **********
assert len(recommendations) == 0
# *********************************************************************

@pytest.mark.skip()
# Test 24
# @pytest.mark.skip()
def test_unique_rec_from_favorites():
# Arrange
sonyas_data = clean_wave_5_data()
Expand All @@ -71,7 +77,8 @@ def test_unique_rec_from_favorites():
assert INTRIGUE_2b in recommendations
assert sonyas_data == clean_wave_5_data()

@pytest.mark.skip()
# Test 25
#@pytest.mark.skip()
def test_unique_from_empty_favorites():
# Arrange
sonyas_data = {
Expand All @@ -92,7 +99,8 @@ def test_unique_from_empty_favorites():
# Assert
assert len(recommendations) == 0

@pytest.mark.skip()
# Test 26
#@pytest.mark.skip()
def test_new_rec_from_empty_friends():
# Arrange
sonyas_data = {
Expand Down
100 changes: 91 additions & 9 deletions viewing_party/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
pp = pprint.PrettyPrinter(indent=4)

def create_movie(movie_title, genre, rating):
'''
Create a dictionary that appends key:value pairs
3 parameters: string, string, float are the values
Return dictionary
'''
dict = {}

if movie_title == None or genre == None or rating == None:
return None
else:
Expand All @@ -19,29 +23,47 @@ def create_movie(movie_title, genre, rating):


def add_to_watched(user_data, movie):
'''
2 parameters: dictionary, dictionary
Update and return user_data to include watched movies
'''
user_data["watched"].append(movie)

return user_data


def add_to_watchlist(user_data, movie):
'''
2 parameters: dictionary, dictionary
Update and return user_data to include watchlist movies
'''
user_data["watchlist"].append(movie)

return user_data


def watch_movie(user_data, title):

'''
2 parameters: dictionary, string
Update watchlist to watched and return user_data
'''
for i in user_data["watchlist"]:
if i["title"] == title:
user_data["watched"].append(i)
user_data["watchlist"].remove(i)

return user_data


# -----------------------------------------
# ------------- WAVE 2 --------------------
# -----------------------------------------

def get_watched_avg_rating(user_data):
'''
1 parameter: dictionary
Return the average rating of the movies watched by user
'''
movies = user_data["watched"]
summation = 0

Expand All @@ -55,6 +77,10 @@ def get_watched_avg_rating(user_data):


def get_most_watched_genre(user_data):
'''
1 parameter: dictionary
Return most watched genre by the user
'''
watched_movies = user_data["watched"]
if watched_movies == []:
return None
Expand All @@ -63,7 +89,6 @@ def get_most_watched_genre(user_data):
for movie in watched_movies:
genre = movie["genre"]


if genre in logbook:
logbook[genre] += 1
else:
Expand All @@ -78,6 +103,7 @@ def get_most_watched_genre(user_data):
most_watched_genre = genre

pp.pprint(most_watched_genre)

return most_watched_genre


Expand All @@ -86,6 +112,10 @@ def get_most_watched_genre(user_data):
# -----------------------------------------

def get_unique_watched(user_data):
'''
1 parameter: dictionary
Return movies that user has watched but friends have not
'''
difference_movies = []
watched_movies = user_data["watched"]
friends = user_data["friends"]
Expand All @@ -105,7 +135,12 @@ def get_unique_watched(user_data):

return difference_movies


def get_friends_unique_watched(user_data):
'''
1 parameter: dictionary
Return movies that at least one friend has watched but user has not
'''
movies_not_watched_by_user = []
watched_movies = user_data["watched"]
friends = user_data["friends"]
Expand All @@ -117,7 +152,6 @@ def get_friends_unique_watched(user_data):
if friend_movie not in watched_movies:
if friend_movie in movies_not_watched_by_user:
continue
#else:
movies_not_watched_by_user.append(friend_movie)

return movies_not_watched_by_user
Expand All @@ -128,18 +162,66 @@ def get_friends_unique_watched(user_data):
# -----------------------------------------

def get_available_recs(user_data):
'''
1 parameter: dictionary
Return recommended movies if user has not watched and
at least one friend has watched and host of movie is also
within the user's subscriptions
'''
user_host_recs = []
friends_list = get_friends_unique_watched(user_data)
for i in friends_list:
if i["host"] in user_data["subscriptions"]:
user_host_recs.append(i)
return user_host_recs






# -----------------------------------------
# ------------- WAVE 5 --------------------
# -----------------------------------------
# -----------------------------------------

def get_new_rec_by_genre(user_data):
'''
1 parameter: dictionary
Return movies that user has not watched but friend has that has
a genre the same as user's most frequent genre
'''
new_recs = []
most_watched_genre = get_most_watched_genre(user_data)
#print(most_watched_genre)
friends_watched = get_friends_unique_watched(user_data)
#print(friends_watched)
#for my_movie in most_watched_genre:
for friend_movie in friends_watched:
if most_watched_genre == friend_movie["genre"]:
new_recs.append(friend_movie)
return new_recs


def get_rec_from_favorites(user_data):
'''
1 parameter: dictionary
Return movies that are in user's favorites and none of
friends have watched it
'''
rec_movies = []
friends_watched = get_friends_unique_watched(user_data)
#print(user_data["favorites"])
for movie in user_data["favorites"]:
for friend_movie in friends_watched:
# print("*********MY_MOVIE**********")
# print(movie)
# print("*********FRIEND_MOVIE**********")
# print(friend_movie)
# print("*********REC_MOVIE**********")
# print(rec_movies)
# print()

if movie["title"] == friend_movie["title"]:
break

rec_movies.append(movie)
# print(rec_movies)

#print(rec_movies)
return rec_movies

0 comments on commit bcdcfc8

Please sign in to comment.