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

Nancy - Lions #161

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
48 changes: 42 additions & 6 deletions viewing_party/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,57 @@ def watch_movie(user_data, title):
# ------------- WAVE 2 --------------------
# -----------------------------------------

# my own work with the help of tutor
def get_watched_avg_rating(user_data):
count = 0
average_rating = 0

for i in range(len(user_data["watched"])):
count += (user_data["watched"][i]["rating"])
average_rating = count/len(user_data["watched"])
return average_rating
Comment on lines +35 to +42

Choose a reason for hiding this comment

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

This works great! You could also consider using a a for-each loop here:
for movie in user_data["watched"]

Then, we could just get movie["rating"] instead of user_data["watched"][i]["rating"], a lot easier to work with!


def get_most_watched_genre(user_data):
genre_fave = [] # ['Fantasy', 'Fantasy', 'Fantasy', 'Action', 'Intrigue', 'Intrigue']
count = 0
current_highest = ""

for users_list in user_data["watched"]:
genre_fave.append(users_list["genre"])

for element in genre_fave:
if count < genre_fave.count(element): # count = 0 vs action=1
current_highest = element
count = genre_fave.count(element) # =1

if len(user_data["watched"]) == 0:
return None

return current_highest
Comment on lines +44 to +60

Choose a reason for hiding this comment

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

This works great! A few notes:

  • Consider putting lines 57-58 at the beginning of the function. It's often a good idea to do our input validation at the beginning.
  • I like the use of the for-each loop on line 49, but I think the variable name is a bit misleading. user_list is actually a dictionary representing a movie, not a user or a list.

# print(count, current_highest)
# for i in range(len(user_data["watched"])):
# popular_genre = []
# if popular_genre == []:
# return None
# elif i not in popular_genre:
# popular_genre.append(i)

# return popular_genre

"""
THIS IS THE WORK OF A GROUP
def get_watched_avg_rating(user_data):
sum = 0
average = 0

for i in range(len(user_data["watched"])):
sum += (user_data["watched"][i]["rating"])
sum += (user_data["watched"][i]["rating"])
average = sum/len(user_data["watched"])
return average

def get_most_watched_genre(user_data):
index = 0
genres = []
least_popular = []
most_popular = []
if user_data == {"watched":[]}:
return None
Expand All @@ -52,11 +90,9 @@ def get_most_watched_genre(user_data):
index +=1
genres.append(user_data["watched"][index-1]["genre"])
for item in genres:
if item not in least_popular:
least_popular.append(item)
else:
most_popular.append(item)
most_popular.append(item)
return (most_popular[0])
"""

# -----------------------------------------
# ------------- WAVE 3 --------------------
Expand Down