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

Scissors_Gloria_Villa #68

Open
wants to merge 2 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
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{"name":"Python: Current File","type":"python","request":"launch","program":"${file}","console":"integratedTerminal"},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"python.pythonPath": "venv/bin/python",
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
9 changes: 4 additions & 5 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_create_movie_all_params_valid_returns_movie():
new_movie = create_movie(movie_title, genre, rating)

# Assert
assert new_movie["title"] is "Title A"
assert new_movie["genre"] is "Horror"
assert new_movie["rating"] is 3.5
assert new_movie["title"] == "Title A"
assert new_movie["genre"] == "Horror"
assert new_movie["rating"] == 3.5


def test_create_movie_no_title_returns_none():
Expand Down Expand Up @@ -120,7 +120,6 @@ def test_watch_movie_moves_movie_from_watchlist_to_empty_watched():
assert updated_data["watched"][0]["genre"] is "Fantasy"
assert updated_data["watched"][0]["rating"] is 4.8


def test_watch_movie_moves_movie_from_watchlist_to_watched():
# Arrange
movie_to_watch = {
Expand Down Expand Up @@ -186,4 +185,4 @@ def test_watch_movie_does_nothing_if_movie_not_in_watchlist():
assert len(updated_data["watchlist"]) is 1
assert len(updated_data["watched"]) is 1
assert movie_to_watch not in updated_data["watchlist"]
assert movie_to_watch not in updated_data["watched"]
assert movie_to_watch not in updated_data["watched"]
1 change: 1 addition & 0 deletions tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_get_unique_watched_returns_list_of_movies_in_amandas_data_absent_from_t
"title": "Title E"
},
],

"friends": [
{
"watched": [
Expand Down
13 changes: 13 additions & 0 deletions viewing_party/jared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from random import randrange

number = randrange(10)

guess = -1
while number != guess:
guess = int(input('Please enter a guess between 0-10 ==>'))
if guess < number:
print(f"{guess} is too low")
elif number > guess:
print(f"{guess} is too high")
else:
print("You guessed it!")
Comment on lines +1 to +13

Choose a reason for hiding this comment

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

In the future you can leave extra files like this (and the vscode files) out by just not adding them when you are using git add

237 changes: 237 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@

def create_movie(title, genre, rating):
if title == None:
return None
elif genre == None:
return None
elif rating == None:
return None
Comment on lines +3 to +8

Choose a reason for hiding this comment

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

This is totally fine, but could be a little more succinct by using or to but all this on one line, since the result is the same in any case.

Copy link
Author

@ggrossvi ggrossvi Mar 31, 2021

Choose a reason for hiding this comment

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

if title == None or genre == None etc...

else:
movie_dict = {
'title': title,
'genre': genre,
'rating': rating
}
print("movie dictionary:",movie_dict)

Choose a reason for hiding this comment

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

As you noted, its usually best to remove "debugging" print statements like this before submitting.

return movie_dict

def add_to_watched(user_data, movie):

'''
the value of `movie` will be a dictionary in this format:

{
"title": "Title A",
"genre": "Horror",
"rating": 3.5
}
'''
#the value of `user_data` will be a dictionary \n
# with a key `"watched"`, and a value `[]`
user_data["watched"] = []

Choose a reason for hiding this comment

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

This clears out any items that were already on the watched list. Unfortunately we didn't have a test to catch this issue, but its still good to be on the lookout for bugs like this.

Copy link
Author

Choose a reason for hiding this comment

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

Don't even need line 31. Just wipes out data in this.

user_data["watched"].append(movie)
return user_data

# Test 3
def add_to_watchlist(user_data,movie):
# movie["title"]
# print("movie:", movie)
user_data_watchlist = user_data["watchlist"]
# print("user")
user_data["watchlist"].append(movie)
return user_data
#Test 4

def watch_movie(user_data,title):
#iterate through the watchlist of the user
for movie in user_data["watchlist"]:
# print("movie:", movie)
if movie["title"] == title:
#add to watched list
user_data["watched"].append(movie)
#remove from watch list
user_data["watchlist"].remove(movie)
# print(user_data)
return user_data



#Wave 3
"""
# - Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies the user has watched, but none of their friends have watched.
# - Return a list of dictionaries, that represents a list of movies
"""
def get_unique_watched(user_data):
if not user_data["watched"]:
return []

# get movies watched by user
# get movies watched by friends
# get unique movies the user has watched but friends have not watched.
# compare movies watched by friends to amanda's watched
user_watched_movie_titles = user_data["watched"]
friends_watched_movie_titles = user_data["friends"]
user_unique_movies_titles = []
# for movie in amanda_watched_movie_titles:

#FOR name_of_individual_thing_in_array IN array_you_want_to_loop_through:
for title in user_watched_movie_titles:
count = 0 #unique movie is Zero
for friend in friends_watched_movie_titles:
if count > 0:
break
if title in friend["watched"]:
count += 1
if count == 0:
user_unique_movies_titles.append(title)
Comment on lines +80 to +86

Choose a reason for hiding this comment

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

This totally works, but there are more succinct ways to solve this without the need for a count variable, since it doesn't really matter what the count is if it's above 0.

Suggested change
for friend in friends_watched_movie_titles:
if count > 0:
break
if title in friend["watched"]:
count += 1
if count == 0:
user_unique_movies_titles.append(title)
for friend in friends_watched_movie_titles:
if title not in friend["watched"]:
user_unique_movies_titles.append(title)


return user_unique_movies_titles # list of dictionaries



def get_watched_avg_rating(user_data):
#user_data = { 'watched': [{..},{..}] }
var_watched = user_data["watched"]
if user_data["watched"] == []:
return 0
#var_watched = [ {..} , {..} ]
rating_sum = 0.0
rating_avg = 0.0

for element in var_watched:
# element = {...} , {...} , {...} //Now you get each element in the list
#element = { 'genre': , 'rating':, 'title':}
# print("element:", element)
my_rating = element['rating'] # 4.8 or 2.0 or 3.9

if my_rating == None:
my_rating = 0.0
# print("my_rating:",my_rating )
rating_sum += my_rating
# print("rating_sum:", rating_sum)

rating_avg = rating_sum/len(var_watched)
# print("rating_avg:", rating_avg) # 0
return rating_avg

#does this parameter have to be the exact name
def get_most_watched_genre(user_data):
# print(user_data)
if user_data["watched"] == []:
return None
movie_type = {}
for movie in user_data["watched"]:
genre = movie["genre"]
# print("genre:", genre)
if genre not in movie_type:
movie_type[genre] = 1
else:
movie_type[genre] +=1

print("$$$$$$$$$$$$$$:0", movie_type)
# [i]["genre"]

# print(movie_type)
most_watched_genre_key = max(movie_type, key = movie_type.get)
print(most_watched_genre_key)
return most_watched_genre_key




def get_friends_unique_watched(user_data):
movie_list_of_dict = []
user_movies = user_data["watched"]
friends = user_data["friends"]
for friend in friends:
movie_lst_friend_watched = friend["watched"]
for element in movie_lst_friend_watched:
# print()
if element not in user_movies and element not in movie_list_of_dict:
# {"title": "Title A"}
# print(f"{} is unique")
Comment on lines +151 to +152

Choose a reason for hiding this comment

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

comments like these are also good to remove before turning in the assignment in the future.

movie_list_of_dict.append(element)
# print("movie_list_of_dict>>", movie_list_of_dict)
return movie_list_of_dict

#Wave 4

def get_available_recs(user_data):
friends_watched_movie_titles = get_friends_unique_watched(user_data)
print("############################")
print("friends_watched_movie_titles>>",friends_watched_movie_titles)
print("############################")
# recommendations = [{"title":[],"host":[]}]
recommendations = []

for movie in friends_watched_movie_titles:
#movie = {title1, host1}
if movie["host"] in user_data['subscriptions']:
recommendations.append(movie)

print(recommendations)
return recommendations


#Wave 5 Get recommendations by genre
def get_new_rec_by_genre(user_data):
recommendation = []
final_recommendation = []
user_movies = user_data["watched"]

# print("user_movies>>",user_movies)
# print()
friends_list = user_data["friends"]
# print("friends>>",friends_list)
# print()
# most frequently watched genre
fav_genre = get_most_watched_genre(user_data)
# print("fav_genre>>> ", fav_genre)
if user_movies == []:
return []
for friend in friends_list:
for movie in friend["watched"]:
if movie["genre"] == fav_genre and movie not in user_movies:
recommendation.append(movie)
return recommendation

def get_rec_from_favorites(user_data):
# - The movie is in the user's `"favorites"`
# - None of the user's friends have watched it
# - Return the list of recommended movies
friends = user_data["friends"]
user_movies = user_data["watched"]
user_favorites = user_data["favorites"]
recommendation = []
if friends == []:
return []
# if user_movies == []: # and no unique movies
# return []

for favorite in user_favorites:
if favorite in user_movies:
has_been_watched_by_friends = False
for friend in friends:
if favorite in friend["watched"]:
has_been_watched_by_friends = True
break
if has_been_watched_by_friends == False:
recommendation.append(favorite)
return recommendation

















43 changes: 43 additions & 0 deletions viewing_party/playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from main import *
sonyas_data = {
"watched": [
{
"title": "Title A",
"genre": "Intrigue"
},
{
"title": "Title B",
"genre": "Intrigue"
},
{
"title": "Title C",
"genre": "Fantasy"
}
],
"friends": [
{
"watched": [
{
"title": "Title D",
"genre": "Intrigue"
}
]
},
{
"watched": [
{
"title": "Title C",
"genre": "Fantasy"
},
{
"title": "Title E",
"genre": "Intrigue"
}
]
}
]
}

# Act
recommendations = get_new_rec_by_genre(sonyas_data)
print(recommendations)