Skip to content

Final changes for the project#9

Open
smchavan wants to merge 2 commits intoada-ac2:masterfrom
smchavan:master
Open

Final changes for the project#9
smchavan wants to merge 2 commits intoada-ac2:masterfrom
smchavan:master

Conversation

@smchavan
Copy link
Copy Markdown

@smchavan smchavan commented Nov 9, 2022

No description provided.

Copy link
Copy Markdown

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

🎉 Congrats on completing your first project at Ada! 🎉 I’ve added some suggestions & questions, let me know if there's anything I can clarify.

Comment thread tests/test_wave_01.py
Comment on lines +121 to +123
assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1
assert updated_data["watched"][0]["genre"] == GENRE_1
assert updated_data["watched"][0]["rating"] == 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.

Great checks for all the movie data!

Comment thread tests/test_wave_01.py
# Assert
assert len(updated_data["watchlist"]) == 1
assert len(updated_data["watched"]) == 2
assert updated_data["watched"][1]["title"] == "It Came from the Stack Trace"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The README isn't explicit about what order we should add movies to the list watched. If we want our tests to be independent from a specific implementation that adds movies to a particular location in the watched list, we could use the in keyword to check if the variable movie_to_watch is in the watched list instead of looking at a specific index. By checking for the whole dictionary, there's a side benefit that we don't need to check each key independently:

assert movie_to_watch in updated_data["watched"]

# Another option:
assert HORROR_1 in updated_data["watched"]

Comment thread tests/test_wave_03.py
assert len(friends_unique_movies) == 3

raise Exception("Test needs to be completed.")
#raise Exception("Test needs to be completed.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We're missing adding new asserts for this test. What assertions could you make to ensure the exact movies that we expect are in the list friends_unique_movies?

Comment thread tests/test_wave_03.py Outdated
Comment on lines +9 to +43
'''
#-----WAVE 3--------

USER_DATA_2 = {
"watched": [
FANTASY_1,
FANTASY_2,
FANTASY_3,
ACTION_1,
INTRIGUE_1,
INTRIGUE_2
],
}
USER_DATA_3 = copy.deepcopy(USER_DATA_2)

USER_DATA_3["friends"] = [
{
"watched": [
FANTASY_1,
FANTASY_3,
FANTASY_4,
HORROR_1,
]
},
{
"watched": [
FANTASY_1,
ACTION_1,
INTRIGUE_1,
INTRIGUE_3,
]
}
]

'''
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's all good to add commented out test data like this while we're actively working on tests, but we want to remove it before committing and pushing our changes to keep our test code concise and uncluttered.

Comment thread tests/test_wave_05.py
Comment on lines +56 to +59
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) == 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.

Great act & assert steps!

Comment thread viewing_party/party.py
#print(friends_movie_list)
my_unique_watched_list = []
for my_unique_movie in user_data["watched"]:
if my_unique_movie not in friends_movie_list and my_unique_movie not in my_unique_watched_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.

This line gets a bit long. We might want to drop it over a couple lines or create variables to hold the comparisons that we then use in an if statement:

is_movie_in_friends = my_unique_movie in friends_movie_list
is_movie_in_unique_list = my_unique_movie in my_unique_watched_list
if not is_movie_in_friends and not is_movie_in_unique_list:
    my_unique_watched_list.append(my_unique_movie)

Comment thread viewing_party/party.py
return my_unique_watched_list
###+++++++++++++++++++++

def get_friends_unique_watched(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.

Nice implementation!

Comment thread viewing_party/party.py

###### Wave 4++++++++++++++++++++++++++++
def get_available_recs(user_data):
friends_unique_watched_movies = get_friends_unique_watched(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.

Great code reuse!

Comment thread viewing_party/party.py
Comment on lines +89 to +92
recommended_movies_for_me = []
for movie in friends_unique_watched_movies:
if movie["host"] in user_data["subscriptions"]:
recommended_movies_for_me.append(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.

Nice algorithm! Another way we could approach filtering the unique_watched list is with a list comprehension:

# list comprehension
result = [movie for movie in friends_unique_watched_movies if movie["host"] in user_data["subscriptions"]]

This line is a bit long, in practice we would split a statement like this across lines, use some extra variables, or shorten some naming to keep under the PEP8 guide of 79 characters max per line:

# list comprehension
result = [movie for movie in friends_unique_watched_movies 
         if movie["host"] in user_data["subscriptions"]]

Comment thread viewing_party/party.py Outdated
Comment on lines +108 to +111
friends_movie_list = []
for friend in user_data["friends"]:
for movie in friend["watched"]:
friends_movie_list.append(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.

It looks like we duplicate some code that creates a list of our friends movies between get_unique_watched and this function. How could we use a helper function to remove the duplication?

@smchavan
Copy link
Copy Markdown
Author

smchavan commented Nov 11, 2022 via email

@kelsey-steven-ada
Copy link
Copy Markdown

Since the project is "Green" on the grading scale (the green/yellow/red grade is shared in Learn), you do not need to make any changes, but you are always welcome to if there is something you want to practice =]

@smchavan
Copy link
Copy Markdown
Author

smchavan commented Nov 11, 2022 via email

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