diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..d1cde35ea --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..e3cea6a8c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "python.pythonPath": "venv/bin/python", + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index d2c0c834d..3cb041723 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -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(): @@ -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 = { @@ -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"] \ No newline at end of file diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 1a90bd0de..758b12599 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -22,6 +22,7 @@ def test_get_unique_watched_returns_list_of_movies_in_amandas_data_absent_from_t "title": "Title E" }, ], + "friends": [ { "watched": [ diff --git a/viewing_party/jared.py b/viewing_party/jared.py new file mode 100644 index 000000000..a8ec39d94 --- /dev/null +++ b/viewing_party/jared.py @@ -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!") \ No newline at end of file diff --git a/viewing_party/main.py b/viewing_party/main.py index e69de29bb..7afc89bef 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -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 + else: + movie_dict = { + 'title': title, + 'genre': genre, + 'rating': rating + } + print("movie dictionary:",movie_dict) + 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"] = [] + 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) + + 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") + 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 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/viewing_party/playground.py b/viewing_party/playground.py new file mode 100644 index 000000000..73bb5c02d --- /dev/null +++ b/viewing_party/playground.py @@ -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) \ No newline at end of file