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

Maple - Sabrina Lauredan #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viewing Party
<!-- # Viewing Party

## Skills Assessed

Expand Down Expand Up @@ -87,7 +87,7 @@ Summary of one-time project setup:
$ source venv/bin/activate
```

2. Find the test file that contains the test you want to run. Ensure that the test(s) you want to run isn't skipped.
<!-- 2. Find the test file that contains the test you want to run. Ensure that the test(s) you want to run isn't skipped.

- Check the `tests` folder, and find the test file you want to run
- In that test file, read through each test case
Expand Down Expand Up @@ -163,11 +163,11 @@ At submission time, no matter where you are, submit the project via Learn.

This project is designed such that one could puzzle together how to implement this project without many directions. Being able to read tests to understand what is expected of our program is a skill that needs to be developed; programmers often take years to develop this skill competently.

When our test failures leave us confused and stuck, let's use the detailed project requirements below.
When our test failures leave us confused and stuck, let's use the detailed project requirements below. -->

### Wave 1

1. The first four tests are about a `create_movie()` function.
<!-- 1. The first four tests are about a `create_movie()` function.

In `party.py`, there should be a function named `create_movie`. This function should...

Expand All @@ -176,9 +176,9 @@ In `party.py`, there should be a function named `create_movie`. This function sh
- Have three key-value pairs, with specific keys
- The three keys should be `"title"`, `"genre"`, and `"rating"`
- The values of these key-value pairs should be appropriate values
- If `title` is falsy, `genre` is falsy, or `rating` is falsy, this function should return `None`
- If `title` is falsy, `genre` is falsy, or `rating` is falsy, this function should return `None` -->

2. The next two tests are about an `add_to_watched()` function.
<!-- 2. The next two tests are about an `add_to_watched()` function.

In `party.py`, there should be a function named `add_to_watched`. This function should...

Expand All @@ -198,8 +198,8 @@ In `party.py`, there should be a function named `add_to_watched`. This function

3. The next two tests are about an `add_to_watchlist()` function.

In `party.py`, there should be a function named `add_to_watchlist`. This function should...

In `party.py`, there should be a function named `add_to_watchlist`. This function should... -->
<!--
- take two parameters: `user_data`, `movie`
- the value of `user_data` will be a dictionary with a key `"watchlist"`, and a value which is a list of dictionaries representing the movies the user wants to watch
- An empty list represents that the user has no movies in their watchlist
Expand Down Expand Up @@ -228,10 +228,10 @@ In `party.py`, there should be a function named `watch_movie`. This function sho
- 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` --> -->

### Wave 2

<!--
1. The first two tests are about a `get_watched_avg_rating()` function.

In `party.py`, there should be a function named `get_watched_avg_rating`. This function should...
Expand All @@ -241,18 +241,18 @@ In `party.py`, there should be a function named `get_watched_avg_rating`. This f
- This represents that the user has a list of watched movies
- Calculate the average rating of all movies in the watched list
- The average rating of an empty watched list is `0.0`
- return the average rating
- return the average rating -->

2. The next three tests are about a `get_most_watched_genre()` function.
<!-- 2. The next three tests are about a `get_most_watched_genre()` function.

In `party.py`, there should be a function named `get_most_watched_genre`. This function should...

- take one parameter: `user_data`
- the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries. Each movie dictionary has a key `"genre"`.
- take one parameter: `user_data` -->
<!-- - the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries. Each movie dictionary has a key `"genre"`.
- This represents that the user has a list of watched movies. Each watched movie has a genre.
- The values of `"genre"` is a string.
- Determine which genre is most frequently occurring in the watched list
- return the genre that is the most frequently watched
- return the genre that is the most frequently watched -->

### Wave 3

Expand Down
3 changes: 2 additions & 1 deletion tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from viewing_party.party import *


def test_create_movie_all_params_valid_returns_movie():
def test_create_movie_all_params_valid_returns_movie():
## create function that returns new dict to contain ratings, etc
# Arrange
movie_title = "Title A"
genre = "Horror"
Expand Down
129 changes: 129 additions & 0 deletions viewing_party/party.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#wave 1

def create_movie(title, genre, rating):

Choose a reason for hiding this comment

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

👍

if title == None:
return None
if genre == None:
return None
if rating == None:
return None

Choose a reason for hiding this comment

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

since all of these if statements will produce the same return statement, let's combine them!

Suggested change
if title == None:
return None
if genre == None:
return None
if rating == None:
return None
if title == None or genre == None or rating == None:
return None

else:
movie = {"title": title, "genre": genre, "rating": rating}
return movie

def add_to_watched(user_data, movie):

Choose a reason for hiding this comment

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

👍

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

def add_to_watchlist(user_data, movie):

Choose a reason for hiding this comment

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

👍

user_data['watchlist'].append(movie)
return user_data

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

Choose a reason for hiding this comment

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

so, if user_data["watched"] is empty, no worries! it will still append the appropriate movie from the watchlist to the watched list on line 26. So we don't need this extra checking if statement:

Suggested change
if user_data['watched'] == []:
user_data["watched"].append(movie)


return user_data

#wave 2 pt 1

def get_watched_avg_rating(user_data):
if len(user_data["watched"]) == 0:
return 0
else:
ratings = []
for movie in user_data['watched']:
ratings.append(movie["rating"])
average = sum(ratings)/len(ratings)
return average
Comment on lines +31 to +35

Choose a reason for hiding this comment

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

👍 this looks great! but I think we can do both the summing and the for loop in one! behind the scenes, sum() is running another for loop, so let's cut it out:

Suggested change
ratings = []
for movie in user_data['watched']:
ratings.append(movie["rating"])
average = sum(ratings)/len(ratings)
return average
ratings = 0
for movie in user_data['watched']:
ratings += movie["rating"]
average = ratings/len(ratings)
return average


# wave 2 pt 2

def get_most_watched_genre(user_data):
genres_watched = []

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

Choose a reason for hiding this comment

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

careful with too many spaces! len is a function, and it's being called here. so keep the len and the ( together! len(). it won't break anything if you don't, but it is standard practice

return None

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

freq = {}

for genre in genres_watched:
if not genre in freq:
freq.update({genre:1})

Choose a reason for hiding this comment

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

oh funky! never used update on a dictionary before! I think creating it like freq[genre] = 1 also works! likely you will see the latter one more often, but they both work!

else:
freq[genre] += 1
Comment on lines +43 to +52

Choose a reason for hiding this comment

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

nicely done! let's see if we can combine these together:

Suggested change
for movie in user_data["watched"]:
genres_watched.append(movie["genre"])
freq = {}
for genre in genres_watched:
if not genre in freq:
freq.update({genre:1})
else:
freq[genre] += 1
freq = {}
for movie in user_data["watched"]:
if movie["genre"] in freq:
freq[genre] += 1
else:
freq[genre] = 1
popular_genre = max(freq, key = freq.get)

both of these work just fine! we can, though, discard genre_watched in this alternate solution since we are doing everything at once


popular_genre = max(freq, key = freq.get)

return popular_genre

#wave 3 pt 1

def get_unique_watched(user_data):
user_watched = user_data["watched"]
friends_watched = user_data["friends"]
Comment on lines +61 to +62

Choose a reason for hiding this comment

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

I like that you created variables to make it easier to isolate the data you are working with

friend_titles = []
unique = []
for friend in friends_watched:
for title in friend["watched"]:
friend_titles.append(title["title"])
for title in user_watched:
if title['title'] not in friend_titles:
unique.append(title)
return unique

#wave 3 pt 2

def get_friends_unique_watched(user_data):
unique_movies = []
for friend in user_data["friends"]:
for movie in friend["watched"]:
if not is_movie_in_list(user_data["watched"], movie) and not is_movie_in_list(unique_movies, movie):

Choose a reason for hiding this comment

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

👍 I see a helper function! noice!

unique_movies.append(movie)
return unique_movies

# wave 4

def get_available_recs(user_data):

Choose a reason for hiding this comment

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

👍

host_list = []
user_subscriptions = user_data["subscriptions"]
rec = []
friends_unique = get_friends_unique_watched(user_data)
for movie in friends_unique:
if movie["host"] in user_subscriptions:
rec.append(movie)
return rec


# #wave 5 pt1

def get_new_rec_by_genre(user_data):

Choose a reason for hiding this comment

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

👍

fav = get_most_watched_genre(user_data)
friends_unique = get_friends_unique_watched(user_data)
rec =[]
for movie in friends_unique:
if movie["genre"] == fav and not is_movie_in_list(rec, movie):
rec.append(movie)
return rec

# wave 5 pt 2

def get_rec_from_favorites(user_data):

Choose a reason for hiding this comment

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

👍

unique_watched = get_unique_watched(user_data)
favorites = user_data['favorites']
return [movie for movie in unique_watched if movie in favorites]

# helper

def is_movie_in_list(list, movie):

Choose a reason for hiding this comment

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

👍

for item in list:
if item["title"] == movie["title"]:
return True
return False