def bringData(userID):
    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile)

    user = jsonData["user"]
    password = jsonData["password"]
    host = jsonData["host"]
    port = jsonData["port"]
    DB = jsonData["database"]

    conn = PostgreConn(user, password, host, port, DB)

    result = conn.select(
        f"select a,b,c,d,e,f,g,h,i,j,k,l,m,n,o from CONSUMPTION where userID = {userID} order by consumeDate desc limit 90;"
    )
    vector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    for j in range(90):
        for k in range(15):
            vector[k] += result[j][k] * (2 - 0.02 * j)

    vecSum = sum(vector)
    for i in range(15):
        vector[i] /= vecSum

    conn.close()
    # vector는 카테고리에 대한 비중을 나타낸다.

    return vector
Пример #2
0
def bringData(count):
    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile);

    user = jsonData["user"];
    password = jsonData["password"];
    host = jsonData["host"];
    port = jsonData["port"];
    DB = jsonData["database"];
    
    conn = PostgreConn(user, password, host, port, DB);
    
    consumptions = [];
    for i in range(1, count + 1):
        result = conn.select(f"select a,b,c,d,e,f,g,h,i,j,k,l,m,n,o from CONSUMPTION where userID = {i} order by consumeDate desc limit 90;");
        vector = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
        
        for j in range(90):
            for k in range(15):
                vector[k] += result[j][k] * (2 - 0.02 * j);
        
        consumptions.append(vector);
        
    conn.close();
    
    return consumptions;
Пример #3
0
def storeToDB(inputData):
    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile);

    user = jsonData["user"];
    password = jsonData["password"];
    host = jsonData["host"];
    port = jsonData["port"];
    DB = jsonData["database"];
    
    conn = PostgreConn(user, password, host, port, DB);
    
    conn.insert(sql="insert into LOGS(ip, accessTime, method, url, statusCode, referer, userID) values(%s, %s, %s, %s, %s, %s, %s)", bulk=True, records=inputData);
    
    conn.saveJSON("LOGS", "logs.json");
    conn.close();
Пример #4
0
def bringData(count):
    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile);

    user = jsonData["user"];
    password = jsonData["password"];
    host = jsonData["host"];
    port = jsonData["port"];
    DB = jsonData["database"];
    
    conn = PostgreConn(user, password, host, port, DB);
	
    interestDict = {};
    
    for i in range(1, count + 1):
        interestDict[i] = [];
        result = conn.select(f"select userID, url from logs where userID = {i} and url like '%chatbot%';");
        for item in result:
            interestDict[item[0]].append(item[1]);
    
    conn.close();
    
    return interestDict;
Пример #5
0
def storeToDB(inputData):
    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile)

    user = jsonData["user"]
    password = jsonData["password"]
    host = jsonData["host"]
    port = jsonData["port"]
    DB = jsonData["database"]

    conn = PostgreConn(user, password, host, port, DB)

    conn.insert(
        sql=
        "insert into CONSUMPTION(userID, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, consumeDate) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
        bulk=True,
        records=inputData)

    print("Data is inserted to DB successfully.")
    conn.close()
def main(configFile, number, outFile):

    with open(configFile) as jsonFile:
        jsonData = json.load(jsonFile)

    user = jsonData["user"]
    password = jsonData["password"]
    host = jsonData["host"]
    port = jsonData["port"]
    DB = jsonData["database"]

    conn = PostgreConn(user, password, host, port, DB)

    actionData = []

    for i in range(1, number + 1):
        result = conn.select(
            f"select url from LOGS where userID = {i} and method = 'GET' and url != '/';"
        )
        actionData.append(result)

    preprocessed = []

    for action in actionData:
        # action은 한사람 데이터
        a = b = c = d = e = f = g = h = I = 0

        for i in range(len(action)):
            actNum = int(action[i][0][7:])

            if actNum < 100:
                a += 1
            elif actNum < 200:
                b += 1
            elif actNum < 300:
                c += 1
            elif actNum < 400:
                d += 1
            elif actNum < 500:
                e += 1
            elif actNum < 600:
                f += 1
            elif actNum < 700:
                g += 1
            elif actNum < 800:
                h += 1
            elif actNum < 900:
                I += 1

        preprocessed.append([a, b, c, d, e, f, g, h, I])

    for i in range(1, number + 1):
        result = conn.select(
            f"select job, gender, age, hasCar, hasHouse, getMarried, children, incomeLevel, assetsLevel from CUSTOMER where userID = {i};"
        )
        for item in result[0]:
            if item in list("ABCDEFGHIJKLMNO"):
                stop = alphaToNum[item]
                for j in range(15):
                    if j == stop:
                        preprocessed[i - 1].append(1)
                    else:
                        preprocessed[i - 1].append(0)
            else:
                preprocessed[i - 1].append(item)

    saveArr = np.asarray(preprocessed)

    print(saveArr)

    np.save(outFile, saveArr)

    conn.close()
def main(userID):
    models = [tf.keras.models.load_model(f"model_{i}.h5") for i in range(15)]

    with open("config.json") as jsonFile:
        jsonData = json.load(jsonFile)

    user = jsonData["user"]
    password = jsonData["password"]
    host = jsonData["host"]
    port = jsonData["port"]
    DB = jsonData["database"]

    conn = PostgreConn(user, password, host, port, DB)

    result = conn.select(
        f"select a,b,c,d,e,f,g,h,i,j,k,l,m,n,o from CONSUMPTION where userID = {userID} order by consumeDate desc limit 90;"
    )
    vector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    for j in range(90):
        for k in range(15):
            vector[k] += result[j][k] * (2 - 0.02 * j)

    result = conn.select(
        f"select job, gender, age, hasCar, getMarried, children, incomeLevel, assetsLevel from CUSTOMER where userID = {userID};"
    )
    userFeature = []
    for i in range(len(result[0])):
        if i == 0:
            stop = alphaToNum[result[0][i]]
            for j in range(14):
                if j == stop:
                    userFeature.append(1)
                else:
                    userFeature.append(0)
        elif i == 2:
            for l in range(2, 8):
                if ageToAger(result[0][i]) == l:
                    userFeature.append(1)
                else:
                    userFeature.append(0)
        else:
            userFeature.append(result[0][i])

    vecSum = sum(vector)
    for i in range(15):
        vector[i] /= vecSum

    X = np.asarray([vector + userFeature])

    conn.close()

    interests = [models[i].predict(X)[0] for i in range(15)]

    first = interests.index(max(interests))
    interests[interests.index(max(interests))] -= 1

    second = interests.index(max(interests))
    interests[interests.index(max(interests))] -= 1

    third = interests.index(max(interests))

    result = [first, second, third]

    for i in range(3):
        result[i] = convToInterest[result[i]]

    print(result[0])
    print(result[1])
    print(result[2])