Exemplo n.º 1
0
def get_user_profile(user_id):
    session = client.create_session()
    client.create_keyspace(session, keyspace)
    session.set_keyspace(keyspace)
    session.row_factory = dict_factory

    ratings = client.get_data_table(session, keyspace, table)

    if ratings.empty:
        return empty_json

    ratings = ratings.drop(columns="rating_id")

    avg_ratings = calculate_avg_ratings(ratings, converted_genres)
    avg_user_ratings = pd.read_json(get_user_avg_rating(user_id),
                                    orient='records')

    appended_avg_ratings = avg_ratings.append(avg_user_ratings,
                                              ignore_index=True,
                                              sort=False)
    profile = pd.DataFrame(columns=converted_genres)

    # FIXME: Change profile
    profile.loc[0] = [
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    ]
    for genre in converted_genres:
        profile.iloc[0, profile.columns.get_loc(genre)] = appended_avg_ratings.iloc[0][genre] - \
                                                          appended_avg_ratings.iloc[1][genre]

    return profile.to_json(orient='records')
Exemplo n.º 2
0
def get_ratings():
    session = client.create_session()
    client.create_keyspace(session, keyspace)
    session.set_keyspace(keyspace)
    session.row_factory = dict_factory

    df = client.get_data_table(session, keyspace, table)
    if df.empty:
        return empty_json
    df = df.drop(columns="rating_id")
    return df.to_json(orient='records')
Exemplo n.º 3
0
 def avg_all(self):
     df = cc.get_data_table(session,keyspace,table)
     list1 = df.columns.values.tolist()
     df.fillna(value=pd.np.nan, inplace=True)
     list1.remove("movieid")
     list1.remove("rating")
     list1.remove("userid")
     mean, _ = w.mean_genres(df, list1, True)
     dict = {}
     for key in range(len(list1)):
         dict[list1[key]] = mean[key]
     return dict
Exemplo n.º 4
0
def get_user_avg_rating(user_id):
    session = client.create_session()
    client.create_keyspace(session, keyspace)
    session.set_keyspace(keyspace)
    session.row_factory = dict_factory

    ratings = client.get_data_table(session, keyspace, table)

    ratings = ratings.sort_values(by=['userid'])
    ratings.set_index('userid')
    ratings = ratings[int(user_id) == ratings['userid']]
    return calculate_avg_ratings(ratings,
                                 converted_genres).to_json(orient=records)
Exemplo n.º 5
0
def get_avg_ratings():
    session = client.create_session()
    client.create_keyspace(session, keyspace)
    session.set_keyspace(keyspace)
    session.row_factory = dict_factory

    ratings = client.get_data_table(session, keyspace, table)

    if ratings.empty:
        return empty_json

    ratings = ratings.drop(columns="rating_id")
    return calculate_avg_ratings(ratings,
                                 converted_genres).to_json(orient=records)
Exemplo n.º 6
0
 def avg_usr(self, user):
     df = cc.get_data_table(session,keyspace,table)
     list1 = df.columns.values.tolist()
     df.fillna(value=pd.np.nan, inplace=True)
     list1.remove("movieid")
     list1.remove("rating")
     list1.remove("userid")
     id = float(user)
     mean = w.user_mean2(df, list1, id)
     dict = {}
     for key in range(len(list1)):
         dict[list1[key]] = mean[key]
     dict['userid'] = user
     return dict
Exemplo n.º 7
0
 def get_all(self):
     r = cc.get_data_table(session,keyspace,table)
     r.fillna(0)
     dc = r.to_dict('r')
     jsonfiles = json.dumps(dc)
     return jsonfiles