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 - Nyckolle Lucuab #54

Open
wants to merge 9 commits 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
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
Comment on lines +2 to +6

Choose a reason for hiding this comment

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

For future reference we will be adding files that are specific to your coding environment such as .vscode settings into a .gitignore. This is just to prevent conflicts with other peoples' settings when they work on the same project as you.

"python.testing.pytestEnabled": true
}
2 changes: 1 addition & 1 deletion tests/test_wave_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ def test_get_rec_from_favorites_returns_expected_list_from_valid_input():

# Assert
assert len(recommendations) is 1
assert {"title": "Title A"} in recommendations
assert {"title": "Title A"} in recommendations
8 changes: 8 additions & 0 deletions viewing_party/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
160 changes: 160 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import pytest
from pytest import approx

def create_movie(movie_title, genre, rating):
if movie_title == None or genre == None or rating == None:
return None
return {"title": movie_title, "genre": genre, "rating": rating}
Comment on lines +5 to +7

Choose a reason for hiding this comment

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

Nice! This looks very neat.


def add_to_watched(user_data, movie):
user_data["watched"].append(movie)
return user_data

def add_to_watchlist(user_data, movie):
user_data["watchlist"].append(movie)
return user_data

def watch_movie(user_data, movie):
watchlist = user_data["watchlist"]
watchedlist = user_data["watched"]

for data in watchlist:
if data["title"] == movie:
watchlist.remove(data)
watchedlist.append(data)

Choose a reason for hiding this comment

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

This would be a good spot to call the add_to_watched function

return user_data

def get_most_watched_genre(user_data):
genre_tally = {}
movie_list = user_data["watched"]

for dict in movie_list:
for description, value in dict.items():
if description == "genre":
if value in genre_tally:
genre_tally[value] += 1
else:
genre_tally[value] = 1
elif description == None:
return None
Comment on lines +32 to +39

Choose a reason for hiding this comment

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

Nice use of a frequency map!


for genre, tally_count in genre_tally.items():
if True:
all_values = genre_tally.values()
max_value = max(all_values)
if tally_count == max_value:
return genre

def get_watched_avg_rating(user_data):
rating_total = 0
ratings = []
movie_list = user_data["watched"]

if movie_list != []:
for dict in movie_list:
for description, value in dict.items():
if description == "rating":
rating_total += dict[description]
ratings.append(value)
avg_rating = pytest.approx(rating_total/len(ratings))

Choose a reason for hiding this comment

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

Interesting use of the approx method

return avg_rating
else:
return 0

def get_unique_watched(user_data):
unique_watched_list = []
user_watched_list = []
friends_watched_list = []
user_watched_values = user_data["watched"]
friends_values = user_data["friends"]

for movie in user_watched_values:
user_watched_list.append(movie)

for friend in friends_values:
for movie in friend["watched"]:
friends_watched_list.append(movie)

for movie in user_watched_list:
if movie not in friends_watched_list:
unique_watched_list.append(movie)

return unique_watched_list

def get_friends_unique_watched(user_data):
unique_watched_list = []
user_watched_list = []
friends_watched_list = []
user_watched_values = user_data["watched"]
friends_values = user_data["friends"]

for movie in user_watched_values:
user_watched_list.append(movie)

for friend in friends_values:
for movie in friend["watched"]:
friends_watched_list.append(movie)

for movie in friends_watched_list:
if movie not in user_watched_list:
if movie in unique_watched_list:
continue

Choose a reason for hiding this comment

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

Nice use of continue!

else:
unique_watched_list.append(movie)

return unique_watched_list

def get_available_recs(user_data):
friend_watched_list = (get_friends_unique_watched(user_data))

Choose a reason for hiding this comment

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

Good job using helper functions!

available_recs_list = []

for movie in friend_watched_list:
if movie not in user_data["watched"]:
for product in movie.values():
if product in user_data["subscriptions"]:
available_recs_list.append(movie)

return available_recs_list

"""
get_friends_watched is a funciton that compiles a list
of all the movies that the user's friends have watched
as noted in their 'watched' lists.
"""
def get_friends_watched(user_data):
friends_watched_list = []
user_friends_values = user_data["friends"]

for friend in user_friends_values:
for movie in friend["watched"]:
friends_watched_list.append(movie)

return friends_watched_list

def get_new_rec_by_genre(user_data):
user_watched_list = user_data["watched"]
friends_watched_list = get_friends_watched(user_data)
recommendation_list = []

if user_data["watched"] != []:
for movie in friends_watched_list:
if movie not in user_watched_list:
recommendation_list.append(movie)
return recommendation_list
else:
return recommendation_list

def get_rec_from_favorites(user_data):
friends_watched = get_friends_watched(user_data)
available_recs_list = []
user_favorite_list = user_data["favorites"]

if user_data["watched"] != []:
Comment on lines +139 to +152

Choose a reason for hiding this comment

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

great job checking for an empty list!

for movie in user_favorite_list:
if movie in friends_watched:
continue
else:
available_recs_list.append(movie)
return available_recs_list
else:
return available_recs_list