-
Notifications
You must be signed in to change notification settings - Fork 117
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
Gricelda Viewing-Party #103
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,147 @@ | |||
# ------------- WAVE 1 -------------------- | |||
|
|||
from tests.test_constants import GENRE_1, MOVIE_TITLE_1, RATING_1 |
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.
In general, we don't want to import values from a test file into our main python files. For our functions in party.py we won't need values from GENRE_1, MOVIE_TITLE_1, RATING_1. We can get our data from the parameters.
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.
Great work on your first project! You hit the learning goals and passed the tests 🙂
I left a few comments about renaming variables to be a little more descriptive, ways that you can simplify your code, and an optimization. Let me know if you have any questions about my comments.
Feel free to improve and refactor!
I noticed that you missed adding the assert statements into the test files so your project is currently a 🟡
I'd love to have you update the test files where we ask for additional assert statements to test your code and I can review them. It shouldn't take very long! You'll see the call out to add assertions surrounded by lots of *************
April 4 Update: Thank you for pushing up your test assertions! You've earned a 🟢
"rating": RATING_1 | ||
} | ||
|
||
if not title or not genre or not rating: |
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.
Nice use of a guard clause here! Since we don't need lines 7-11, you can delete them and make your guard clause the first thing that executes in the create_movie function.
|
||
if not title or not genre or not rating: | ||
return None | ||
else: |
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.
Your guard clause returns None which will stop the rest of the method from executing when params are not valid. Since that's the case, we can safely assume that lines 15-20 will execute only when there are valid parameters so we can remove else
.
new_movie["title"] = title | ||
new_movie["genre"] = genre | ||
new_movie["rating"] = rating | ||
return new_movie |
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.
You can directly build your literal dictionary in the return statement here. Taking my comments into account, your refactored method would look like:
def create_movie(title, genre, rating):
if not title or not genre or not rating:
return None
return {
"title": title,
"genre": genre,
"rating": rating
}
|
||
|
||
def watch_movie(user_data, title): | ||
for key in user_data["watchlist"]: |
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.
When this function runs 'key' evaluates to a dictionary which represents a movie. You could rename 'key' to 'movie' for clarity.
avg_rating = total_rating/len(user_data["watched"]) | ||
return avg_rating | ||
else: | ||
return 0.0 |
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.
To express your intent a little more clearly here, you could return 0.0 in a guard clause as the first line of this function.
if not user_data["watched"]:
return 0.0
Then you can proceed with the rest of your function and you won't need to check if user_data["watched"]:
on line 45 before executing the rest of your function
friends_watched.append(movie) | ||
|
||
for movie in friends_watched: | ||
if movie not in user_watched and movie not in total_list: |
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.
user_watched is a list and then you iterate through user_data["watched"] and add each movie into this list. To optimize your function you could write:
user_watched = user_data["watched"]
without iterating and appending on lines 91 and 93
or you could have your if statement directly access user_data["watched"]. That would look like
if movie not in user_data["watched"] and movie not in total_list:
def get_available_recs(user_data): | ||
recommended_movies = [] | ||
|
||
for movie in get_friends_unique_watched(user_data): | ||
if movie["host"] in user_data["subscriptions"]: | ||
recommended_movies.append(movie) | ||
return recommended_movies |
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.
Really nicely written and concise!
user_genre = [] | ||
|
||
for movie in get_friends_unique_watched(user_data): | ||
if movie["genre"] == get_most_watched_genre(user_data): |
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 recommend using a variable to point to the result of get_most_watched_genre() outside the for loop to help optimize your code like on line 128.
I say this because every time we loop through a friend's movie, we will execute get_most_watched_genre() and this method also does looping. So every iteration now runs another loop (even though we can't tell just by reading if movie["genre"] == get_most_watched_genre(user_data)
.
Line 130 would look like if movie["genre"] == most_watched_genre:
# ----------------------------------------- | ||
# | ||
def get_new_rec_by_genre(user_data): | ||
user_genre = [] |
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.
You could rename user_genre to something like user_recs_by_genre for clarity
return user_genre | ||
|
||
def get_rec_from_favorites(user_data): | ||
user_favorite = [] |
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.
Could rename user_favorite to something like user_recs_from_faves for clarity
No description provided.