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

Rock YuliyaP final version viewing party #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
131 changes: 131 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# WAVE One
def create_movie(movie_title, genre, rating):

Choose a reason for hiding this comment

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

👍

movie = {}
movie['title'] = movie_title
movie['genre'] = genre
movie['rating'] = rating

for values in movie.values():
if values == None:
return None

return movie
Comment on lines +3 to +12

Choose a reason for hiding this comment

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

this works just fine! but we are creating space in memory with a variable movie that might no even be valid yet! so let's think about checking validation before making variables and running code that MIGHT not be needed

Suggested change
movie = {}
movie['title'] = movie_title
movie['genre'] = genre
movie['rating'] = rating
for values in movie.values():
if values == None:
return None
return movie
if movie_title and genre and rating: # does these values "exist"/are they truthy?
movie = {"title": movie_title, "genre": genre, "rating": rating}
return movie
else:
return None



def add_to_watched(user_data, movie):

Choose a reason for hiding this comment

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

👍

new_entry = user_data["watched"]
new_entry.append(movie)
return user_data


def add_to_watchlist(user_data, movie):

Choose a reason for hiding this comment

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

👍

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


def watch_movie(user_data, title):

Choose a reason for hiding this comment

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

👍

for movie in user_data['watchlist']:
if movie['title'] == title:
user_data['watched'].append(movie)
user_data['watchlist'].remove(movie)
return user_data
else:
return user_data


# Wave Two

def get_watched_avg_rating(user_data):

Choose a reason for hiding this comment

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

👍

if len(user_data["watched"]) == 0:
return 0.0
else:
total = 0
for movie in user_data["watched"]:
total += movie["rating"]
average_rating = total / len(user_data["watched"])
return average_rating
Comment on lines +40 to +47

Choose a reason for hiding this comment

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

this works perfectly! but let's see if we can use only one return statement:

Suggested change
if len(user_data["watched"]) == 0:
return 0.0
else:
total = 0
for movie in user_data["watched"]:
total += movie["rating"]
average_rating = total / len(user_data["watched"])
return average_rating
total = 0.0
if len(user_data["watched"]) > 0:
for movie in user_data["watched"]:
total += movie["rating"]
total = total / len(user_data["watched"])
return total



def get_most_watched_genre(user_data):

Choose a reason for hiding this comment

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

👍

most_watched = {}
popular_genre = None
for movie in user_data["watched"]:
if movie["genre"] not in most_watched:
most_watched[movie["genre"]] = 1
else:
most_watched[movie["genre"]] += 1
popular_genre = max(most_watched, key=most_watched.get)

return popular_genre

# WAVE THREE (version4)

def get_unique_watched(user_data):

Choose a reason for hiding this comment

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

👍

unique_watched = []
friends_movies = []
for friend in user_data['friends']:
for movie in friend['watched']:
if movie not in friends_movies:
friends_movies.append(movie)

for movie in user_data["watched"]:
if movie not in friends_movies:
unique_watched.append(movie)

return (unique_watched)


def get_friends_unique_watched(user_data):

Choose a reason for hiding this comment

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

👍

friend_unique_watched = []
friends_unique_movies = []
for friend in user_data["friends"]:
for movie in friend["watched"]:
if movie not in friends_unique_movies:
friends_unique_movies.append(movie)

for movie in friends_unique_movies:
if movie not in user_data["watched"]:
friend_unique_watched.append(movie)

return (friend_unique_watched)


# Wave Four


def get_available_recs(user_data):

Choose a reason for hiding this comment

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

👍

friends_unique_movies = get_friends_unique_watched(user_data)

Choose a reason for hiding this comment

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

great job reusing a function you've already defined

recommended_movies = []
for movie in friends_unique_movies:
if movie["host"] in user_data["subscriptions"]:
recommended_movies.append(movie)
return recommended_movies


# Wave Five (version3)

def get_new_rec_by_genre(user_data):

Choose a reason for hiding this comment

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

👍

user_freq_genre = get_most_watched_genre(user_data)
friends_unique_movies = get_friends_unique_watched(user_data)
recommended_movies = []

for movie in friends_unique_movies:
if movie["genre"] == user_freq_genre:
recommended_movies.append(movie)

return recommended_movies

def get_rec_from_favorites(user_data):

Choose a reason for hiding this comment

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

👍

friends_movie_list = []
for friend in user_data["friends"]:
for movie in friend["watched"]:
friends_movie_list.append(movie)

recommended_movies_list = []

for movie in user_data["favorites"]:
if movie not in friends_movie_list:
recommended_movies_list.append(movie)

return recommended_movies_list