# downloads and unzips dataset from MovieLens 
#'http://files.grouplens.org/datasets/movielens/ml-latest-small.zip'
dataset_folder = os.path.join(os.getcwd(), 'data')
dataset_folder_ready = utils.load_dataset(dataset_folder)

"""
Explanation: Download and load the data from MovieLens
End of explanation
"""


# Export IMDB ratings to the right format 
imdb_ratings = os.path.join(dataset_folder,'ratings-imdb.csv')
links_file = os.path.join(dataset_folder, 'ml-latest-small', 'links.csv')
ratings_file = os.path.join(dataset_folder, 'ml-latest-small','ratings-merged.csv')
utils.import_imdb_ratings(imdb_ratings, links_file, ratings_file)

# adds personal ratings to original dataset ratings file.
[ratings, my_customer_number] = utils.merge_datasets(dataset_folder_ready, ratings_file)

"""
Explanation: How to export your IMDb ratings

Go to IMDb and make an account if you don't have one
If you have no ratings in your account, rate at least 10 movies you liked and 10 movies you didn't like. 
Go to your account (top right) and click on "your Ratings"
Go to the bottom of the page, next to the "next" button, you will find an "Export this list" button. It will export your ratings to your Downloads folder. 
Move the file inside your /data folder in this repo and name it ratings-imdb.csv
End of explanation
"""


# the data is stored in a long pandas dataframe
# we need to pivot the data to create a [user x movie] matrix
ratings_matrix = ratings.pivot_table(index='customer', columns='movie', values='rating', fill_value=0)
ratings_matrix = ratings_matrix.transpose()

# the personal ratings are now stored together with the rest of the ratings
ratings.loc[ratings.customer == my_customer_number]

# A list with some of the movies in the dataset
movie_list = pd.DataFrame(ratings_matrix.index)
movie_list.head(20)

"""
Explanation: Understand the data
End of explanation
"""


