Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scissors - Terah Bruce #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"*test.py"
],
"python.testing.pytestEnabled": true,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestArgs": [
"tests"
]
}
1 change: 1 addition & 0 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def test_watch_movie_moves_movie_from_watchlist_to_watched():

# Act
updated_data = watch_movie(janes_data, movie_to_watch["title"])
print(movie_to_watch["title"])

# Assert
assert len(updated_data["watchlist"]) is 1
Expand Down
153 changes: 153 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
def create_movie(movie_title, genre, rating):
if movie_title == None:
return None
elif genre == None:
return None
elif rating == None:
return None
else:
movie = {"title": movie_title,
"genre": genre,
"rating": rating}
return 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, movie_title):
# print("****** before execution *****")
# print(user_data)
watchlist = user_data["watchlist"]
for i in range(len(watchlist)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the for movie in watchlist style for loop here.

if watchlist[i]["title"] == movie_title:
movie = watchlist[i]
add_to_watched(user_data, movie)
#remove from watchlist
watchlist.remove(movie)
return user_data
else:
return user_data

def get_watched_avg_rating(user_data):
watchedlist = user_data["watched"]
ratings = []
if len(watchedlist) == 0:
return 0.0
else:
for i in range(len(watchedlist)):
ratings.append(watchedlist[i]["rating"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ratings_sum += watchlist[i]["rating"]

ratings_sum = 0
for i in ratings:
ratings_sum = ratings_sum + i
average = ratings_sum/len(ratings)
print(average)
return average

def get_most_watched_genre(user_data):
genres = {}
watchedlist = user_data["watched"]
if len(watchedlist) == 0:
return None
else:
for i in range(len(watchedlist)):
if watchedlist[i]["genre"] not in genres:
genres[watchedlist[i]["genre"]] = 1
else:
genres[watchedlist[i]["genre"]] += 1
sort_genres = sorted(genres.items(), key=lambda x: x[1], reverse=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could you find the maximum if you didn't have access this function?

return sort_genres[0][0]

def get_unique_watched(user_data):
userwatched = user_data["watched"]
friendswatched = user_data["friends"]
unique_watched = []
friendtitlelist = []
for friend in friendswatched:
watched = friend["watched"]
for title in watched:
friendtitlelist.append(title["title"])
for title in userwatched:
if title["title"] not in friendtitlelist:
unique_watched.append(title)
return unique_watched

def get_friends_unique_watched(user_data):
userwatched = user_data["watched"]
friendswatched = user_data["friends"]
userlist = []
unique_watched = []
for title in userwatched:
userlist.append(title["title"])
for friend in friendswatched:
watched = friend["watched"]
for title in watched:
if title["title"] not in userlist:
if title not in unique_watched:
Comment on lines +91 to +92

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style of chained if statements can be combined into one by and-ing the conditionals together:
if title["title"] not in userlist and title not in unique_watched:

unique_watched.append(title)
print(unique_watched)
return unique_watched


def get_available_recs(user_data):
user_hosts_list = user_data["subscriptions"]
user_watched_list = user_data["watched"]
friends_dictkey_watched_list_of_dicts = user_data["friends"]
users_list_of_watched_titles = []
recommendations = []
for title in user_watched_list:
users_list_of_watched_titles.append(title["title"])
Comment on lines +104 to +105

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section of code is doing the same thing as lines 86 & 87 above, making this a great candidate for a helper function. Whenever the same code chunk is showing up multiple places consider pulling it out into a helper function.

for friend in friends_dictkey_watched_list_of_dicts:
friends_watched_list_of_dicts = friend["watched"]
for movie in friends_watched_list_of_dicts:
if movie["title"] not in users_list_of_watched_titles:
if movie["host"] in user_hosts_list:
if movie not in recommendations:
recommendations.append(movie)

return recommendations


def get_new_rec_by_genre(user_data):
most_watched_genre = get_most_watched_genre(user_data)
user_watched_list = user_data["watched"]
friends_dictkey_watched_list_of_dicts = user_data["friends"]
users_list_of_watched_titles = []
recommendations = []
for title in user_watched_list:
users_list_of_watched_titles.append(title["title"])
for friend in friends_dictkey_watched_list_of_dicts:
friends_watched_list_of_dicts = friend["watched"]
for movie in friends_watched_list_of_dicts:
if movie["title"] not in users_list_of_watched_titles:
if movie["genre"] is most_watched_genre:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this conditional statement use ==. For an explanation of is vs ==: https://www.geeksforgeeks.org/difference-operator-python/

if movie not in recommendations:
recommendations.append(movie)
print(recommendations)
return recommendations

def get_rec_from_favorites(user_data):
#creating variables for easier access to nested data
user_fave_dictkey_list_of_dicts = user_data["favorites"]
friends_dictkey_watched_list_of_dicts = user_data["friends"]
friends_list_of_watched_titles = []
recommendations = []

#putting titles into list for easier sorting/comparison.
for friend in friends_dictkey_watched_list_of_dicts:
friends_watched_list_of_dicts = friend["watched"]
for movie in friends_watched_list_of_dicts:
friends_list_of_watched_titles.append(movie["title"])
#comparing movies in user favorites to friends watched movies
for movie in user_fave_dictkey_list_of_dicts:
#checking if movies in users faves are not in friends watched
if movie["title"] not in friends_list_of_watched_titles:
recommendations.append(movie)
print(recommendations)
return recommendations