-
Notifications
You must be signed in to change notification settings - Fork 167
C18 Tigers Marie Keefer viewing-party #157
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
base: master
Are you sure you want to change the base?
Changes from all commits
249699a
1d6e2a8
abd61bd
cc86545
5180f02
ace469b
174f4fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,125 @@ | ||
# ----------------------------------------- | ||
# ------------- WAVE 1 -------------------- | ||
# ----------------------------------------- | ||
|
||
def create_movie(title, genre, rating): | ||
pass | ||
movie_dict = {} | ||
if title and genre and rating: | ||
movie_dict.update({"title": title}) | ||
movie_dict.update({"genre": genre}) | ||
movie_dict.update({"rating": rating}) | ||
return movie_dict | ||
else: | ||
return None | ||
|
||
def add_to_watched(user_data, movie): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
user_data["watched"].append(movie) | ||
return user_data | ||
|
||
|
||
def add_to_watchlist(user_data, movie): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
user_data["watchlist"].append(movie) | ||
return user_data | ||
|
||
|
||
def watch_movie(user_data, title): | ||
for movie_dict in user_data["watchlist"]: | ||
if movie_dict["title"] == title: | ||
user_data["watched"].append(movie_dict) | ||
user_data["watchlist"].remove(movie_dict) | ||
return user_data | ||
return user_data | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only need one return statement. But which one? Well, it depends! Do we want to immediately end the function once we've appended and removed one movie? Is there a possibility there could be duplicates of the same movie inside "watched" and "watchlist"? Maybe! Either one of these works in this context, but do pick only one |
||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 2 -------------------- | ||
# ----------------------------------------- | ||
def get_watched_avg_rating(user_data): | ||
rating_list = [] | ||
rating_total = 0 | ||
|
||
for movie in user_data["watched"]: | ||
if len(user_data["watched"]) == 0: | ||
movie["rating"] = 0.0 | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm what is this doing? If there are no movies in "watched", I don't think we can then add a key to a non-existent dictionary. I think this might error out. Let's remove these lines. Also, we don't want to be making modifications to the user's data unless that's the purpose of the function. This function |
||
rating_list.append(movie['rating']) | ||
|
||
for rating in rating_list: | ||
rating_total += rating | ||
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this works fine! How could we do this in one for loop, though? We are already iterating over each movie on line 41. Why not sum up the ratings as we go? If we do that, we don't even need a |
||
|
||
if len(rating_list) == 0: | ||
return 0.0 | ||
else: | ||
final_rating = rating_total / len(rating_list) | ||
return final_rating | ||
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job handling the empty list case. Consider putting this check at the top as a guard clause in order to get it out of the way, which lets the main logic not be under a conditional. if len(movies) < 1: # there are many ways we can check to see if movies is falsy
return 0.0
# remaining logic goes here |
||
|
||
def get_most_watched_genre(user_data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
genre_dict = {} | ||
if user_data["watched"] == []: | ||
return None | ||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swamp these lines, so the guard clause at the tip-top of the function. That way we don't make any unnecessary variables that will just get discarded when line 57 and 58 execute. |
||
for movie_dict in user_data["watched"]: | ||
if movie_dict["genre"] in genre_dict: | ||
genre_dict[movie_dict["genre"]] += 1 | ||
else: | ||
genre_dict[movie_dict["genre"]] = 1 | ||
best_genre = max(genre_dict, key=genre_dict.get) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job! We talked about how this worked in the project review, but do you feel like you can explain this in your own words? When pulling in code from beyond what we've talked about, it's great if you could include a comment about the research that you did, and how you think it works. Something to think about in future projects! |
||
return best_genre | ||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 3 -------------------- | ||
# ----------------------------------------- | ||
def get_unique_watched(user_data): | ||
user_watched_list = [] | ||
friends_movie_list = [] | ||
unique_user_watched = [] | ||
for i in range(len(user_data["friends"])): | ||
for movie in user_data["friends"][i]["watched"]: | ||
friends_movie_list.append(movie) | ||
|
||
for i in range(len(user_data["watched"])): | ||
movie = user_data["watched"][i] | ||
user_watched_list.append(movie) | ||
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would make for a good helper function so we don't have to repeat code, like on lines 75-77 |
||
|
||
for movie in user_watched_list: | ||
if movie not in friends_movie_list: | ||
unique_user_watched.append(movie) | ||
|
||
return unique_user_watched | ||
|
||
def get_friends_unique_watched(user_data): | ||
user_watched_list = [] | ||
friends_movie_list = [] | ||
friends_unique_watched = [] | ||
result = {} | ||
new_list = [] | ||
for i in range(len(user_data["friends"])): | ||
for movie in user_data["friends"][i]["watched"]: | ||
friends_movie_list.append(movie) | ||
|
||
for i in range(len(user_data["watched"])): | ||
movie = user_data["watched"][i] | ||
user_watched_list.append(movie) | ||
Comment on lines
+95
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha! we've done this once already! Sounds like a job for a helper function! |
||
|
||
for movie in friends_movie_list: | ||
if movie not in user_watched_list and movie not in friends_unique_watched: | ||
friends_unique_watched.append(movie) | ||
|
||
|
||
return friends_unique_watched | ||
|
||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 4 -------------------- | ||
# ----------------------------------------- | ||
def get_available_recs(user_data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
friends_unique_movies = get_friends_unique_watched(user_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great job reusing functions! |
||
movie_recommendations = [] | ||
for movie in friends_unique_movies: | ||
if movie["host"] in user_data["subscriptions"]: | ||
movie_recommendations.append(movie) | ||
|
||
return movie_recommendations | ||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 5 -------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest flipping the sense of the condition around to handle the special case (that something is falsy) quickly and get out, rather than having that dangling
else
at the end. This arrangement is referred to as a guard clause or a guard condition.Notice that it lets us move the main focus of the function (creating the new dict) out of an indented block, letting it stand out more clearly.