Skip to content

Sphinx - Vlada Rapaport & Brianna Root #17

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

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

Conversation

vladarap88
Copy link

No description provided.

@yangashley yangashley changed the title Sphinx - Vlada Rapaport Sphinx - Vlada Rapaport & Brianna Root Sep 30, 2024
Copy link

@yangashley yangashley left a comment

Choose a reason for hiding this comment

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

Nice work on viewing-party, Brianna and Vlada!

I also see that you two made frequent commits, nice job! In the future, as you continue to make small, frequent commits, I'd encourage you to practice writing concise and descriptive messages so when someone reviews the commit history there is a clear story of what happened over time.

Let me know if you have any questions about my review comments.

Comment on lines +145 to +153
# Arrange
janes_data = {
"watchlist": [{
"title": MOVIE_TITLE_1,
"genre": GENRE_1,
"rating": RATING_1
}],
"watched": []
}

Choose a reason for hiding this comment

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

Indentation was changed here and on lines 156 - 160. The code should be indented 4 spaces in, but is indented 8 spaces. Be mindful of what changes get added to your commit since we don't want to introduce inconsistencies in a project.

Comment on lines +162 to +163
assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 # added below asserts
assert updated_data["watched"][0]["genre"] == GENRE_1

Choose a reason for hiding this comment

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

If the order of these movies were somehow changed, then the zero-th element might not be equal to MOVIE_TITLE_1. Do we need to specifically test that the first element of the watched list is equal to that title?

A more general way to write this assertion could look like:

assert HORROR_1 in updated_data["watched"]

Line 163-164 don't really affect the test, but they also aren't testing what we're interested in testing. Per the title of this test, we're looking to test that a movie moves from the watchlist to the watched list. Consider removing these two lines to make the test more concise.

assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 # added below asserts
assert updated_data["watched"][0]["genre"] == GENRE_1
assert updated_data["watched"][0]["rating"] == RATING_1
assert updated_data["watchlist"] == []

Choose a reason for hiding this comment

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

Note that we don't need to write an assertion to test that watchlist is empty because the movie was moved to the watched list because the assertion was already provided on line 160. Line 165 could be removed to keep the test concise.

Also, since you wrote an assertion to check that HORROR_1 was in watched, you could test the opposite to make that it is not in watchlist, like:

assert HORROR_1 not in updated_data["watchlist"]

Comment on lines +186 to +187
assert updated_data["watched"][1]["genre"] == movie_to_watch["genre"]
assert updated_data["watched"][1]["rating"] == movie_to_watch["rating"]

Choose a reason for hiding this comment

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

Similar to my comment above, we might consider removing lines 186-187 since this test is not concerned with genre/ratings.

assert updated_data["watched"][1]["title"] == movie_to_watch["title"] # added asserts
assert updated_data["watched"][1]["genre"] == movie_to_watch["genre"]
assert updated_data["watched"][1]["rating"] == movie_to_watch["rating"]
assert updated_data["watchlist"][0] == FANTASY_1

Choose a reason for hiding this comment

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

You check that FANTASY_1 is still in the watchlist and that HORROR_1 was added to the watched list. You might also consider checking that HORROR_1 was not added to watchlist with assert HORROR_1 not in updated_data["watchlist"].

You could also check that FANTASY_2 which was already in the watched list wasn't removed.

# -----------------------------------------
# ------------- WAVE 5 --------------------
# -----------------------------------------

def get_new_rec_by_genre(user_data):

favorite_genre = 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.

👍 great job using a function you already wrote to keep your code DRY.

Comment on lines +119 to +126
if movie["genre"] != favorite_genre:
continue

elif movie in recommended_movies:
continue

elif movie in user_data["watched"]:
continue

Choose a reason for hiding this comment

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

Like my comment above, the three continues give me pause.

You invoked the method to get the most watched genre on line 114. You can also invoke the method get_friends_unique_watched to make the code more concise.

When you have those two values, you can check if each movie in the friends_unique_movies list has a genre equal to the value of the most watched genre. If they're equal, then you can append that movie to recommended_movies.

Something like

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

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

for friend in user_data["friends"]:
for friend_movie in friend["watched"]:
if friend_movie in new_list:
new_list.remove(friend_movie)

Choose a reason for hiding this comment

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

Since remove has linear time complexity, how can we go about writing the logic so that we append a movie to the list instead?

If you get a list of the movies watched by friends (with a helper method like suggested above) and then check that a user's favorite movies are not in that list, then we could append that movie to a new list like recommendations.

Then you wouldn't need a whole copy of user_data["favorites"] and would not incur the linear time complexity of removing an element from a list (you'll have the constant time complexity of append).

This might look like:

def get_rec_from_favorites():
    recommendations = []
    friends_watched = get_friends_watched_movies()

    for favorite in user_data["favorites"]:
        if not favorite in friends_watched:
           recommendations.append(favorite)
    return recommendations

return recommended_movies

def get_rec_from_favorites(user_data):
recommended_list = []

Choose a reason for hiding this comment

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

recommended_list is created but never used. Delete objects that are not accessed.

@@ -1,23 +1,142 @@

Choose a reason for hiding this comment

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

We should take care to not add in unnecessary changes to a commit so that our project stays neat. Looks like an unneeded blank line was added on line 1 here.

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