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

Rock - Abigail C #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "venv/bin/python"
}
135 changes: 135 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# wave 1
def create_movie(movie_title, genre, rating):
new_movie = {}
if movie_title == None or genre == None or rating == None:
new_movie = None
else:

Choose a reason for hiding this comment

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

you could also rewrite to build the dictionary like so

new_move = {
"title": movie_title,
"genre": genre,
"rating": rating
}

new_movie["title"] = movie_title
new_movie["genre"] = genre
new_movie["rating"] = rating
return new_movie

def add_to_watched(user_data, movie):
user_data = {
"watched":[
movie
]
}
return user_data

def add_to_watchlist(user_data, movie):
user_data = {
"watchlist":[
movie
]
}
return user_data
Comment on lines +12 to +26

Choose a reason for hiding this comment

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

One way to refactor this so the movie is actually being added is user_data["watched"].append(movie)


def watch_movie(user_data,title):
for movie in user_data['watchlist']:
if title == movie['title']:
user_data['watchlist'].remove(movie)
user_data['watched'].append(movie)
return user_data
return user_data

# Wave 2

def get_watched_avg_rating(user_data):
value = []
for movie in user_data["watched"]:
rating_num = movie['rating']
value.append(rating_num)
total = sum(value)
if total != 0:
average = total/len(value)
else:
average = 0.0
return average

def get_most_watched_genre(user_data):
genre_list = []
if len(user_data['watched']) == 0:
popular_genre = None
return popular_genre
for movie in user_data['watched']:
genre = movie['genre']
genre_list.append(genre)
popular_genre = max(set(genre_list), key = genre_list.count)

Choose a reason for hiding this comment

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

Hey Abigail, that is great! I'm glad you're utilizing more advanced methods and data structures. However, in the future, please add a comment that describes code that isn't covered in our curriculum.

return popular_genre

# Wave 3

def get_friend_titles(user_data):
friends = user_data["friends"]
friends_titles = []
for watched_movies in friends:
for movie in watched_movies["watched"]:
friends_titles.append(movie)
return friends_titles

def get_user_titles(user_data):
user_titles = []
for movie in user_data["watched"]:
user_titles.append(movie)
return user_titles

def get_unique_watched(user_data):
friends_titles = get_friend_titles(user_data)
user_titles = get_user_titles(user_data)
user_unique_titles = []
for title in user_titles:
if title not in friends_titles:
user_unique_titles.append(title)
return user_unique_titles

def remove_duplicates(titles):
new_friends_titles = []
for i in range(len(titles)-1):
if titles[i] != titles[i+1:]:
new_friends_titles.append(titles[i+1])
return new_friends_titles

def get_friends_unique_watched(user_data):
user_titles = get_user_titles(user_data)
friends_unique_titles = []
new_friends_titles = remove_duplicates(get_friend_titles(user_data))
for title in new_friends_titles:
if title not in user_titles:
friends_unique_titles.append(title)
return friends_unique_titles

# Wave 4
def get_available_recs(user_data):
friend_data = get_friend_titles(user_data)
recommendations = []
friend_data = remove_duplicates(friend_data)
for data in friend_data:
if data['host'] in user_data["subscriptions"]:
recommendations.append(data)
return recommendations

# Wave 5
def get_new_rec_by_genre(user_data):
user_titles = get_user_titles(user_data)
friends_titles = get_friend_titles(user_data)
recommendations = []
if user_titles == []:
recommendations = []
else:
for title in friends_titles:
if title not in user_titles:
recommendations.append(title)
return recommendations

def get_rec_from_favorites(user_data):
user_titles = get_user_titles(user_data)
friends_titles = get_friend_titles(user_data)
for movie in friends_titles:
Comment on lines +104 to +128

Choose a reason for hiding this comment

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

great use of helper functions!

if movie in user_titles:
user_titles.remove(movie)
if user_titles in user_data["favorites"]:
return user_titles
return user_titles