-
Notifications
You must be signed in to change notification settings - Fork 23
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
Ocelots - McKay #16
base: master
Are you sure you want to change the base?
Ocelots - McKay #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,121 @@ | ||
# ------------- WAVE 1 -------------------- | ||
|
||
from shutil import move | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this line get included? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am actually not sure how this line got into my code! I had never heard of the shutil module until noticing this comment, so this is as much a mystery to me as it is to you! |
||
|
||
|
||
def create_movie(title, genre, rating): | ||
pass | ||
if title and genre and rating: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job making use of "truthiness" to validate against "" and None here |
||
return { | ||
"title": title, | ||
"genre": genre, | ||
"rating": rating, | ||
} | ||
else: | ||
return None | ||
|
||
def add_to_watched(user_data, movie): | ||
user_data.setdefault("watched", []).append(movie) | ||
return user_data | ||
|
||
def add_to_watchlist(user_data, movie): | ||
user_data.setdefault("watchlist", []).append(movie) | ||
return user_data | ||
|
||
def watch_movie(user_data, title): | ||
for movie in user_data["watchlist"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, while this may work here, it's considered dangerous practice to modify the content of a data structure that you're looping over. Especially in more complex code, this can open you up to complex errors. A simple alternative here could be to save a copy of what you get from movie in user_data["watchlist"] and iterate over that, so that as you modify user_data["watchlist"], there's no risk. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be helpful for me to talk through what this alternative would look like in code. Just flagging here that I'll probably swing by your office hours next week to ask about this! |
||
if movie["title"] == title: | ||
add_to_watched(user_data, movie) | ||
user_data["watchlist"].remove(movie) | ||
return user_data | ||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 2 -------------------- | ||
# ----------------------------------------- | ||
|
||
def get_watched_avg_rating(user_data): | ||
total_rating_score = 0 | ||
num_of_movies = len(user_data["watched"]) | ||
for movie in user_data["watched"]: | ||
total_rating_score += movie["rating"] | ||
if num_of_movies == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good check on div by zero |
||
return 0.0 | ||
else: | ||
return total_rating_score / num_of_movies | ||
|
||
def get_most_watched_genre(user_data): | ||
genres = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of a dict as part of your data processing |
||
if user_data["watched"] == []: | ||
return None | ||
for movie in user_data["watched"]: | ||
if movie["genre"] in genres: | ||
genres[movie["genre"]] += 1 | ||
else: | ||
genres[movie["genre"]] = 1 | ||
#review this concept | ||
return max(genres, key=genres.get) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of max() plus using the dict.get() as key to sort your dict! |
||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 3 -------------------- | ||
# ----------------------------------------- | ||
|
||
def get_unique_watched(user_data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could sets have been an alternate to the nested loop logic in these functions? |
||
friends_movies = [] | ||
unique_movies = [] | ||
for friend in user_data["friends"]: | ||
for movie in friend["watched"]: | ||
if movie not in friends_movies: | ||
friends_movies.append(movie) | ||
for movie in user_data["watched"]: | ||
if movie not in friends_movies: | ||
unique_movies.append(movie) | ||
return unique_movies | ||
|
||
def get_friends_unique_watched(user_data): | ||
friends_movies = [] | ||
for friend in user_data["friends"]: | ||
for movie in friend["watched"]: | ||
if movie not in user_data["watched"] and movie not in friends_movies: | ||
friends_movies.append(movie) | ||
return friends_movies | ||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 4 -------------------- | ||
# ----------------------------------------- | ||
|
||
def get_available_recs(user_data): | ||
recommended_movies = [] | ||
for friend in user_data["friends"]: | ||
for movie in friend["watched"]: | ||
if movie not in user_data["watched"] and movie["host"] in user_data["subscriptions"] and movie not in recommended_movies: | ||
recommended_movies.append(movie) | ||
return recommended_movies | ||
|
||
|
||
# ----------------------------------------- | ||
# ------------- WAVE 5 -------------------- | ||
# ----------------------------------------- | ||
|
||
def get_new_rec_by_genre(user_data): | ||
fav_genre = get_most_watched_genre(user_data) | ||
recommended_movies = [] | ||
if fav_genre == None: | ||
return recommended_movies | ||
for friend in user_data["friends"]: | ||
for movie in friend["watched"]: | ||
if movie["genre"] == fav_genre: | ||
if movie not in user_data["watched"] and movie not in recommended_movies: | ||
recommended_movies.append(movie) | ||
return recommended_movies | ||
|
||
def get_rec_from_favorites(user_data): | ||
friends_movies = [] | ||
recommended_movies = [] | ||
for friend in user_data["friends"]: | ||
for movie in friend["watched"]: | ||
friends_movies.append(movie) | ||
for movie in user_data["favorites"]: | ||
if movie not in friends_movies: | ||
recommended_movies.append(movie) | ||
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.
Nice job testing the content, as well