-
Notifications
You must be signed in to change notification settings - Fork 167
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
Nancy - Lions #161
base: master
Are you sure you want to change the base?
Nancy - Lions #161
Conversation
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.
Hi Nancy, great job! There's a lot of really good logic here and your comments especially in the later waves are super helpful. I really appreciate you being so forthcoming about the parts of the code you still have challenges understanding. The code here makes for a green project, but we can chat about how to go back and make sure you can get a fuller understanding of the earlier waves 🙂
@@ -142,13 +143,14 @@ def test_moves_movie_from_watchlist_to_watched(): | |||
# Assert | |||
assert len(updated_data["watchlist"]) == 1 | |||
assert len(updated_data["watched"]) == 2 | |||
assert updated_data["watched"][1]["title"] == MOVIE_TITLE_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.
Consider checking that the whole movie matches instead of just the title so that we make sure the other attributes are copied over as well.
actual = get_new_rec_by_genre(sonyas_data) | ||
assert actual == [] |
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 act and assert!
if title and genre and rating: | ||
new_movie = {} | ||
new_movie["title"] = title | ||
new_movie["genre"] = genre | ||
new_movie["rating"] = rating | ||
return new_movie | ||
if not title or not genre or not rating: | ||
return None |
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 logic! A few quick notes:
- Consider making the whole dictionary at once:
new_movie = {
"title": title,
"genre": genre,
"rating": rating
}
- Consider removing line 10. If line 4 is False, then line 10 must be True, so we don't need to check it again.
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 |
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 and concise functions!
viewing_party/party.py
Outdated
def get_watched_avg_rating(user_data): | ||
sum = 0 | ||
average = 0 | ||
|
||
for i in range(len(user_data["watched"])): | ||
sum += (user_data["watched"][i]["rating"]) | ||
average = sum/len(user_data["watched"]) | ||
return average |
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.
- Consider using a for-each instead of a for here; the index is unimportant.
- The parentheses on line 39 are unneeded.
- Consider calculating the average only once at the end instead of at every iteration of the loop.
for item in friends_movies: # we are accesing the list we created of movies watched by friends | ||
if item not in user_movies: # it the friends movie is not in the movies the user has seen | ||
if item not in unique: # if that movie is also not in our list of unique movies, we add to unique | ||
if item["host"] in user_data["subscriptions"]: # if streaming service is in subscription | ||
unique.append(item) # if streaming service is found, add to unique |
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 logic! Consider combining the if statements here.
if len(user_movies) == 0: | ||
return friends_movies # if the list of user is completely empty | ||
|
||
max(set(most_genre), key=most_genre.count) # will get the most watched genre, will |
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.
This is neat and works! That being said, I'd encourage you as we're learning to also be thinking about how to do things in the less fancy way.
def get_new_rec_by_genre(user_data): | ||
user_movies = [] | ||
friends_movies = [] | ||
most_genre = [] | ||
recommended_movies = [] | ||
|
||
for movie in user_data["watched"]: # this is to help create the user watch list | ||
user_movies.append(movie) #user_movies has a list of the movies the user has seen | ||
most_genre.append(movie["genre"]) # to get to the genre | ||
|
||
if len(user_movies) == 0: | ||
return friends_movies # if the list of user is completely empty | ||
|
||
max(set(most_genre), key=most_genre.count) # will get the most watched genre, will |
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.
Consider re-using earlier functions as helpers here.
for item in friends_movies: # we are accesing the list we created of movies watched by friends | ||
if item not in user_movies: # it the friends movie is not in the movies the user has seen | ||
if item not in most_genre: # if that movie is also not in our list of unique movies, we add to unique | ||
if item["host"] in user_data["subscriptions"]: # if streaming service is in subscription | ||
if most_genre[0] in item["genre"]: # if the most popular genre is in the friends dict list | ||
recommended_movies.append(item) # if streaming service is found, add to recommended movies | ||
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.
I like a lot of the logic here! I think there's a couple of lines that might not be doing what we hope though.
- Line 182 checks whether a movie dictionary is not inside a string. This will always be True (it's impossible for a string to hold a dictionary inside it, strings only hold letters, numbers, etc.)
- Line 184 checks whether the first letter of the most common genre is in the movie's genre. This might return a false positive. For example, if
most_genre
was "fantasy" and the item's genre was "sci-fi", thisif
statement would incorrectly consider it a match because the first letter ofmost_genre
, 'f', is present in "sci-fi".
for item in user_data["favorites"]: # this accesses favorites in the user data | ||
if item not in friend_movies: # if that favorite is not in friends movies | ||
recommended_movies.append(item) # append the item to the 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.
Great logic!
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.
Thanks for revisiting this! This logic looks great!
def get_watched_avg_rating(user_data): | ||
count = 0 | ||
average_rating = 0 | ||
|
||
for i in range(len(user_data["watched"])): | ||
count += (user_data["watched"][i]["rating"]) | ||
average_rating = count/len(user_data["watched"]) | ||
return average_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.
This works great! You could also consider using a a for-each loop here:
for movie in user_data["watched"]
Then, we could just get movie["rating"]
instead of user_data["watched"][i]["rating"]
, a lot easier to work with!
def get_most_watched_genre(user_data): | ||
genre_fave = [] # ['Fantasy', 'Fantasy', 'Fantasy', 'Action', 'Intrigue', 'Intrigue'] | ||
count = 0 | ||
current_highest = "" | ||
|
||
for users_list in user_data["watched"]: | ||
genre_fave.append(users_list["genre"]) | ||
|
||
for element in genre_fave: | ||
if count < genre_fave.count(element): # count = 0 vs action=1 | ||
current_highest = element | ||
count = genre_fave.count(element) # =1 | ||
|
||
if len(user_data["watched"]) == 0: | ||
return None | ||
|
||
return current_highest |
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.
This works great! A few notes:
- Consider putting lines 57-58 at the beginning of the function. It's often a good idea to do our input validation at the beginning.
- I like the use of the for-each loop on line 49, but I think the variable name is a bit misleading.
user_list
is actually a dictionary representing a movie, not a user or a list.
Even though I completed all the waves, after reviewing the code I completely forgot how my group and I ended up solving Wave 2.