Skip to content

Gricelda Viewing-Party#103

Open
GitHub4Gigi wants to merge 3 commits into
ada-c17:masterfrom
GitHub4Gigi:master
Open

Gricelda Viewing-Party#103
GitHub4Gigi wants to merge 3 commits into
ada-c17:masterfrom
GitHub4Gigi:master

Conversation

@GitHub4Gigi
Copy link
Copy Markdown

No description provided.

Comment thread party.py
@@ -0,0 +1,147 @@
# ------------- WAVE 1 --------------------

from tests.test_constants import GENRE_1, MOVIE_TITLE_1, RATING_1
Copy link
Copy Markdown

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.

Copy link
Copy Markdown

@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.

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 🟢

Comment thread party.py
"rating": RATING_1
}

if not title or not genre or not rating:
Copy link
Copy Markdown

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.

Comment thread party.py

if not title or not genre or not rating:
return None
else:
Copy link
Copy Markdown

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.

Comment thread party.py
new_movie["title"] = title
new_movie["genre"] = genre
new_movie["rating"] = rating
return new_movie
Copy link
Copy Markdown

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        
    }

Comment thread party.py


def watch_movie(user_data, title):
for key in user_data["watchlist"]:
Copy link
Copy Markdown

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.

Comment thread party.py
avg_rating = total_rating/len(user_data["watched"])
return avg_rating
else:
return 0.0
Copy link
Copy Markdown

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

Comment thread party.py
friends_watched.append(movie)

for movie in friends_watched:
if movie not in user_watched and movie not in total_list:
Copy link
Copy Markdown

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:

Comment thread party.py
Comment on lines +111 to +117
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
Copy link
Copy Markdown

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!

Comment thread party.py
user_genre = []

for movie in get_friends_unique_watched(user_data):
if movie["genre"] == get_most_watched_genre(user_data):
Copy link
Copy Markdown

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:

Comment thread party.py
# -----------------------------------------
#
def get_new_rec_by_genre(user_data):
user_genre = []
Copy link
Copy Markdown

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

Comment thread party.py
return user_genre

def get_rec_from_favorites(user_data):
user_favorite = []
Copy link
Copy Markdown

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

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.

2 participants