Skip to content

Instantly share code, notes, and snippets.

@gabraganca
Last active April 5, 2019 01:22
Show Gist options
  • Save gabraganca/0259784918b760ae617e701a62a01376 to your computer and use it in GitHub Desktop.
Save gabraganca/0259784918b760ae617e701a62a01376 to your computer and use it in GitHub Desktop.
Wife ratings
def add_rating(userId:str, movie_name:str, rating:float):
"""
Adiciona a nota de um userId referente a filme.
Parameters:
userId: Id do usuário.
movie_name: Nome do filme. Aceita Expressão Regular
rating: Nota de 0.5 a 5 de 0.5 em 0.5.
"""
# Procura o filme
movie_details = df_movies[df_movies['title'].str.contains(movie_name)]
if movie_details.shape[0] == 0:
raise Exception('Não foi encontrado filme com este nome')
elif movie_details.shape[0] >= 2:
msg = 'Foram encontrados mais de um filme.\n'
msg += '\n'.join(movie_details.title)
raise Exception(msg)
last_index = max(df_ratings.index) + 1
df_ratings.loc[last_index, 'userId'] = userId
df_ratings.loc[last_index, 'movieId'] = movie_details['movieId'].values[0]
df_ratings.loc[last_index, 'rating'] = rating
df_ratings.reset_index(inplace=True, drop=True)
esposa_notas = [
['Hidden Figures', 4],
['Sing .2016.', 4],
['Inside Out.*2015', 4],
['King.s Speech.*2010.', 5],
['A.I. Artificial Intelligence', 4],
['Pursuit of Happyness', 5],
['Incredibles.*2004', 5],
['Bicentennial Man', 4],
['Babe.*1995', 3],
['Star Trek.*2009', 3],
['Cast Away', 3],
['Life of Pi', 2],
['Hugo', 4],
['Harry Potter.*Stone', 4],
['Harry Potter.*Chamber', 3],
['Harry Potter.*Prisoner', 2],
['Avatar', 4],
['Twilight.*2008', 2],
['Central do Brasil', 3],
['Batman Returns', 2],
['Matrix.*99', 3],
['Matrix Reload', 1],
['Matrix Rev', 0.5],
['Theory.*Every', 4],
['Brave.*12', 3],
['Shrek.*2001', 4],
['Shrek 2', 4]
]
for movie_name, rating in esposa_notas:
add_rating('Esposa', movie_name, rating)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment