Esempio n. 1
0
def main():
    # h  = input("Prosze wybrac dzialanie programu, producent/klient:")
    # if h == 'p':
    #     wtiproj02_producer.panproducer('test')
    # elif h == 'k2':
    #     wtiproj02_consumer_v2.consumer('test')
    # elif h == 'k':
    #     wtiproj02_consumer.consumer('test')
    wtiproj03_ETL.jjpd()
Esempio n. 2
0
def load_data():
    r2.flushdb()
    df, lista = w.jjpd()
    print(df)
    print(df.shape)
    lista.insert(0, 'movieID')
    lista.insert(1, 'rating')
    for index, row in df.iterrows():
        r2.rpush(row['userID'], row[lista].to_json())
    print("completed")
Esempio n. 3
0
class api():
    df, list1 = w.jjpd()
    df = df.fillna(0)

    def get(self):
        value = self.df.sample(n=1)
        jsonfiles = json.dumps(value.to_dict('index'))
        return jsonfiles

    def post(self, data):
        dict1 = {}
        columns = []
        for k, v in data.items():
            try:
                dict1[k] = int(v)
                columns.append(k)
            except:
                columns.append(k)
                dict1[k] = float(v)
        dict1.update()
        print(dict1)
        df2 = pd.DataFrame([dict1], columns=dict1.keys())
        self.df = self.df.append(df2,
                                 ignore_index=True,
                                 verify_integrity=False,
                                 sort=None)
        return data

    def get_all(self):
        jsonfiles = json.dumps(self.df.to_dict('index'))
        return jsonfiles

    def delet(self):
        self.df = self.df.iloc[0:0]
        return json.dumps(self.df.to_json(orient='records'))

    def avg_usr(self, user):
        df1 = self.df.sample(n=1)
        self.df.replace(0, np.nan, inplace=True)
        mean = ww.user_mean(df1, self.list1, int(user))
        dict = {}
        for key in range(len(self.list1)):
            dict[self.list1[key]] = mean[key]
        dict['userID'] = user
        self.df = self.df.fillna(0)
        return dict

    def avg_all(self):
        self.df.replace(0, np.nan, inplace=True)
        mean, _ = ww.mean_genres(self.df, self.list1, True)
        dict = {}
        for key in range(len(self.list1)):
            dict[self.list1[key]] = mean[key]
        return dict
Esempio n. 4
0
    session.row_factory = dict_factory
    rows = session.execute("SELECT * FROM user_ratings.user_avg_rating ;")
    ret = secrets.choice(list(rows))
    return ret


def delete_table(session, keyspace, table):
    session.execute("DROP TABLE " + keyspace + "." + table + ";")


def clear_table(session, keyspace, table):
    session.execute("TRUNCATE " + keyspace + "." + table + ";")


if __name__ == '__main__':
    keyspace = "user_ratings"
    table = "user_avg_rating"
    keyspace2 = "usr_profiles"
    table2 = "profiles"
    df, _ = w.jjpd()
    names = df.userID.unique()
    create_keyspace(session, keyspace)
    # create_data_table(session, keyspace, table)
    push_data_table(session, keyspace, table, df)
    # print(get_data_table(session, keyspace, table))
    # create_keyspace(session,keyspace2)
    # create_usr_profile_table(session)
    push_usr_table(session)
    # # print(get_data_table(session, keyspace2, table2))
    print(get_usr_table(session, 78.0))
Esempio n. 5
0
from flask import Flask, request, jsonify
import json
import wtiproj03_ETL
import random

api = Flask(__name__)
api.config['JSON_SORT_KEYS'] = False

df, list1 = wtiproj03_ETL.jjpd()
df = df.fillna(0)


@api.route('/rating', methods=['GET', 'POST', 'DELETE'])
def app():
    if request.method == 'POST':
        value = request.form
        global df
        df = df.append(value, ignore_index=True)
        return json.dumps(value)
    if request.method == 'GET':
        if df.empty:
            return jsonify('empty')
        else:
            value = df.sample(n=1)
            jsonfiles = json.loads(value.to_json(orient='records'))
            return jsonify(jsonfiles)
    if request.method == 'DELETE':
        df = df.iloc[0:0]
        if df.empty:
            return jsonify('')
        else: