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 - Mai Truong #55

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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

Choose a reason for hiding this comment

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

In the future if you use git add main.py instead of git add . you can leave files like this out of your commits.

// 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"
}
]
}
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": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ In `main.py`, there should be a function named `watch_movie`. This function shou
- add that movie to watched
- return the `user_data`
- If the title is not a movie in the user's watchlist:
- return the `user_data`
- return the `user_data`w

### Wave 2

Expand All @@ -239,7 +239,7 @@ In `main.py`, there should be a function named `get_watched_avg_rating`. This fu
- The average rating of an empty watched list is `0.0`
- return the average rating

2. The next two tests are about a `get_most_watched_genre()` function.
2. The asnext two tests are about a `get_most_watched_genre()` function.

In `main.py`, there should be a function named `get_watched_avg_rating`. This function should...

Expand Down Expand Up @@ -279,7 +279,6 @@ In `main.py`, there should be a function named `get_friends_unique_watched`. Thi
- Return a list of dictionaries, that represents a list of movies

### Wave 4

1. There are two tests about a `get_available_recs` function

Create a function named `get_available_recs`
Expand Down
1 change: 1 addition & 0 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import pytest
from viewing_party.main import *

Expand Down
179 changes: 179 additions & 0 deletions viewing_party/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# --------------------Wave 1--------------------------

def create_movie(movie_title, genre, rating):
# create dictionary
new_movies = {

Choose a reason for hiding this comment

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

Since this is only one movie, it'd be more appropriately named new_movie

"title": movie_title,
"genre": genre,
"rating": rating
}
# if title, genre, rating are true:
if movie_title and genre and rating:
return new_movies
# return dictionary
else:
return None
# else:
# return None

def add_to_watched(user_data, movie):
# add the new movie to the users data's watched dictionary
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, title):
# loop through user_data:
for movie in user_data["watchlist"]:
if title == movie["title"]:
# remove movie_title from watchlist
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):

watched_list = user_data["watched"]
rating_list = []

for movie in watched_list:
rating_list.append(movie["rating"])
if len(rating_list) == 0:
avg_rating = 0.0
return avg_rating
else:
avg_rating = sum(rating_list)/ len(rating_list)
return avg_rating

def get_most_watched_genre(user_data):

most_watched = {}
popular_genre = None

for movie in user_data["watched"]:
if movie["genre"] not in most_watched:
most_watched[movie["genre"]] = 1
else:
most_watched[movie["genre"]] += 1
popular_genre = max(most_watched, key = most_watched.get)

Choose a reason for hiding this comment

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

Because of the indentation, popular_genre is currently being calculated at each iteration of the loop even though you don't need it until the end.

Suggested change
popular_genre = max(most_watched, key = most_watched.get)
popular_genre = max(most_watched, key = most_watched.get)

return popular_genre


# # -------------------Wave 3---------------------------


def get_unique_watched(user_data):

users_unique_movies = []
friends_movies = []

for friend in user_data["friends"]:
for movie in friend["watched"]:
friends_movies.append(movie)

for movie in user_data["watched"]:
if movie not in friends_movies:
users_unique_movies.append(movie)

return users_unique_movies

def get_friends_unique_watched(user_data):

friends_unique_movies = []
users_movies = []

for movie in user_data["watched"]:
users_movies.append(movie)

for friend in user_data["friends"]:
for movie in friend["watched"]:
if movie not in users_movies:
if movie not in friends_unique_movies:
friends_unique_movies.append(movie)

return friends_unique_movies


# ---------------------Wave 4---------------------------

def get_available_recs(user_data):

friends_movies = user_data["friends"]
subscriptions = user_data["subscriptions"]
recommendations = []

for friend in friends_movies:
for movie in friend["watched"]:
if movie not in user_data["watched"] and\
movie not in recommendations and\
movie["host"] in subscriptions:
recommendations.append(movie)

for movie in recommendations:
# if host, service not in recommendations:
if movie["host"] not in subscriptions:
recommendations.remove(movie)
# if len(user_data["watched"]) == 0:
# return []
Comment on lines +122 to +123

Choose a reason for hiding this comment

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

In the future, your submissions can be a little cleaner by removing old code like this


return recommendations

# ---------------------Wave 5---------------------------

def get_new_rec_by_genre(user_data):

# assign results of get_most_watched_genre to a variable
user_genre = get_most_watched_genre(user_data)
friends_movies = user_data["friends"]
recommendations = []

for friend in user_data["friends"]:
for movie in friend["watched"]:
if movie["genre"] == user_genre:
recommendations.append(movie)

return recommendations

def get_rec_from_favorites(user_data):

user_favories = user_data["favorites"]
friends_movies = user_data["friends"]
favorites = []
user_rec = []

for movie in user_favories:
favorites.append(movie)

for movie in favorites:
for movie in friends_movies["watched"]:
# if movie not in friends_movies["watched"]:
user_rec.append(movie)

return user_rec

def get_rec_from_favorites(user_data):

user_favories = user_data["favorites"]
friends_movies = user_data["friends"]
favorites = []
friend_watched = []
user_rec = []

for movie in user_favories:
favorites.append(movie)

for friend in friends_movies:
for movie in friend["watched"]:
friend_watched.append(movie)

for movies in favorites:
if movies not in friend_watched:
user_rec.append(movies)

return user_rec
Comment on lines +143 to +179

Choose a reason for hiding this comment

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

I'm curious why this same function is defined twice.
In this case the first function definition will just get overwritten by the 2nd one.