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

Sapphire - Niambi P. #64

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Sapphire - Niambi P. #64

wants to merge 35 commits into from

Conversation

Lemmi-C
Copy link

@Lemmi-C Lemmi-C commented Mar 31, 2023

No description provided.

hannahredfive and others added 30 commits March 27, 2023 12:08
…in Wave 3, also defined helper function get_friends_movie_titles
…cated in wave_03 tests & passed test_friends_not_unique_movies.
@hannahredfive
Copy link

Sapphire - Hannah Chandley Wohllaib also worked on this project.

Another note: when using live share in VS code we can only commit from the machine of whoever is sharing, but we did take turns writing code and doing commits and pushes during this time even though for periods it looks like just one of us. Once we realized this we tried to switch who was live sharing more and then stopped using live share.

Copy link

@tildeee tildeee left a comment

Choose a reason for hiding this comment

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

Tagging @Lemmi-C for visibility

Nice work on this project, y'all! The project is marked as a "green" for me.

Overall, the code is great. I followed the logic, it's very readable, and it hits all of the requirements. It's very apparent to me that you two practiced iteration and accessing dictionaries and lists :) Most of my comments are around different lines of code that I would continue to refactor or think about. I hope the feedback carries with you into future projects, or you ask me any questions that come up :D

Also, your git hygiene is great! Keep up the good, descriptive commit messages and commit frequency. In addition, the tests looked good, and both of your team reflections looked great and I appreciate them.

Again, good work on the project, and keep it up!

Comment on lines +4 to +8
if title == None or genre == None or rating == None:
new_movie = None
else:
new_movie = {"title": title, "genre": genre, "rating": rating}
return new_movie
Copy link

Choose a reason for hiding this comment

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

Nicely done!

def add_to_watched(user_data, movie):
watched_list = user_data["watched"]
watched_list.append(movie)
user_data["watched"] = watched_list
Copy link

Choose a reason for hiding this comment

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

If we delete/comment this line out, we can actually see that the tests still pass-- we don't need to re-assign user_data["watched"] = watched_list. That's because watched_list is a reference to user_data["watched"]-- anything we change on watched_list will change on user_data["watched"], because they're both pointing to the same thing. Let me know if you have questions on this!

def add_to_watchlist(user_data, movie):
watchlist = user_data["watchlist"]
watchlist.append(movie)
user_data["watchlist"] = watchlist
Copy link

Choose a reason for hiding this comment

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

Similar to above, watchlist and user_data["watchlist"] refer/point to the same thing, so we don't need to re-assign watchlist back.

tracker_dict = None
for movie_dict in user_data["watchlist"]:
if movie == movie_dict["title"]:
add_to_watched(user_data, movie_dict)
Copy link

Choose a reason for hiding this comment

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

Great decision to use the add_to_watched function here! A lot of people didn't think to do this, but I think it's ideal code to reuse it.

Comment on lines +42 to +43
for i in range(len(user_data["watched"])):
sum += user_data["watched"][i]["rating"]
Copy link

Choose a reason for hiding this comment

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

In this situation, I think it's better to use a for loop on each item in user_data["watched"], rather than i over a range. I think that because we use i to access the user_data. I'd choose to use i if we needed to use it as a number.

Consider the following refactor, which passes the tests!

        for movie in user_data["watched"]:
            sum += movie["rating"]

for movie in user_data["watched"]:
user_movie_titles.add(movie["title"])

friends_unique = friends_movie_titles - user_movie_titles
Copy link

Choose a reason for hiding this comment

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

Nice way to find the difference between them! I like the use of sets, too.

Comment on lines +99 to +103
for friend in user_data["friends"]:
for movie in friend["watched"]:
if movie["title"] in friends_unique:
if movie not in friends_unique_movies:
friends_unique_movies.append(movie)
Copy link

Choose a reason for hiding this comment

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

Your code is correctly indented. However, the loops and conditionals are getting pretty deeply nested here-- We can't avoid every nested loop, but when I am 3+ levels in, I'd look for a way to refactor the code. As a starting point, I would try to combine the most inner ifs.

Comment on lines +115 to +126
if "subscriptions" in user_data:
user_subs = user_data["subscriptions"]
recs = []

for movie in friends_watched:
if movie["host"] in user_subs:
recs.append(movie)

return recs

else:
return []
Copy link

Choose a reason for hiding this comment

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

Your function logic is correct here. If you had time, I would encourage thinking about how to refactor this code.

I'm pretty enthusiastic about refactoring, so I'll describe my own process of refactoring here:

First, I notice three interesting lines:recs = [], return recs, and return []. These three lines stand out to me because they all feel kind of similar. I think about how return [] is the same as return recs if recs is an empty array, which it starts off as!

Then, I'd just try to change small pieces of code. I'd replace the return in the else clause with return recs.

After that, seeing that the line return recs is repeated, I'd delete the else, move a return recs line outside of the conditional, and delete all other return recs

Then, I'd move my definition of recs (the line recs = []) to the beginning of the function, so it is on the same indentation as when we return it.

Consider this, which passes the tests:

def get_available_recs(user_data):
    friends_watched = get_friends_unique_watched(user_data)
    recs = []

    if "subscriptions" in user_data:
        user_subs = user_data["subscriptions"]
        for movie in friends_watched:
            if movie["host"] in user_subs:
                recs.append(movie)

    return recs

This refactored code uses only code you two wrote, but by moving a variable definition, we can get rid of the whole else clause.

PS: Sorry if I'm too enthusiastic or nerdy about this and wrote too much, I only hope it's helpful!

for favorite in favorites:
if favorite not in friends_watchlist:
recs.append(favorite)
return recs
Copy link

Choose a reason for hiding this comment

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

Nicely done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants