Exemplo n.º 1
0
def get_products():
    if request.method == 'POST':
        request_json = request.get_json()
        filters = request_json["filter"]
        conn = ConnectionHelper()
        products = dao.get_products(conn, filters)
        return dumps(products), 200
Exemplo n.º 2
0
def update_recommendation():
    conn = ConnectionHelper()
    table, labels = dao.get_recommended_tribe_table(conn)
    df_tribe, data_recommend_tribe = recommend.get_recommended_item(
        table, labels)
    table, labels = dao.get_recommended_products_table(conn)
    df_prod, data_recommend_prod = recommend.get_recommended_item(
        table, labels)
    return df_prod, data_recommend_prod, df_tribe, data_recommend_tribe
Exemplo n.º 3
0
def get_recommended_tribe(user_id):
    if request.method == 'GET':
        global data_recommend_tribe, df_tribe
        conn = ConnectionHelper()
        recommended_item = data_recommend_tribe.loc[df_tribe['user'] ==
                                                    user_id]
        recommended_category_id = recommended_item["1"].values[0]
        recommended_tribe = dao.get_tribe_by_id(conn, recommended_category_id)
        return dumps(recommended_tribe), 200
Exemplo n.º 4
0
def get_recommended_products(user_id):
    if request.method == 'GET':
        global data_recommend_prod, df_prod
        conn = ConnectionHelper()
        recommended_item = data_recommend_prod.loc[df_prod['user'] == user_id]
        recommended_category_id = recommended_item["1"].values[0]
        recommended_product = dao.get_product_by_id(conn,
                                                    recommended_category_id)
        return dumps(recommended_product), 200
Exemplo n.º 5
0
def get_recommended_tribe(user_id):
    if request.method == 'GET':
        global data_recommend_tribe, df_tribe
        conn = ConnectionHelper()
        table, labels = dao.get_recommended_tribe_table(conn)
        recommended_item_id = recommend.get_recommended_item(
            user_id, table, labels)
        recommended_tribe = dao.get_tribe_by_id(conn, recommended_item_id)
        return dumps(recommended_tribe), 200
Exemplo n.º 6
0
def get_recommended_product_by_product(user_id):
    if request.method == 'GET':
        conn = ConnectionHelper()
        table, labels = dao.get_recommended_products_table(conn)
        recommended_item_id = recommend.get_recommended_item(
            user_id, table, labels)
        recommended_product = dao.get_product_by_product_id(
            conn, recommended_item_id)
        return dumps(recommended_product), 200
Exemplo n.º 7
0
def declare_interest():
    if request.method == 'POST':
        request_json = request.get_json()
        conn = ConnectionHelper()
        interest = {}
        interest['user_id'] = request_json['user_id']
        interest['product_id'] = request_json['product_id']
        interest['category_id'] = request_json['category_id']
        interest['tribe_id'] = request_json['tribe_id']
        return dumps(interest), 200
Exemplo n.º 8
0
def get_most_purchased():
    if request.method == 'GET':
        conn = ConnectionHelper()
        table, labels = dao.get_recommended_products_table(conn)
        purchases_list = []
        for column in range(1, len(table[0])):
            total = 0
            for row in range(len(table)):
                total += table[row][column]
            purchases_list.append(total)
        purchase_number = max(purchases_list)
        labels.pop(0)
        recommended_item_id = labels[purchases_list.index(purchase_number)]
        recommended_product = dao.get_product_by_product_id(
            conn, recommended_item_id)
        return dumps(recommended_product), 200
Exemplo n.º 9
0
def register():
    request_json = request.get_json()
    conn = ConnectionHelper()
    user = {}
    user['name'] = request_json['name']
    user['email'] = request_json['email']
    user['password'] = request_json['password']
    user_db = dao.create_user(conn, user['name'], user['password'],
                              user['email'])
    res = {
        'user': {
            "id": user_db["id"],
            "name": user_db["name"],
            "email": user_db["email"],
        }
    }
    return dumps(res), 200
Exemplo n.º 10
0
def user_login():
    if request.method == 'POST':
        request_json = request.get_json()
        user = {}
        user['email'] = request_json['email']
        user['password'] = request_json['password']
        conn = ConnectionHelper()
        user_db = dao.get_user(conn, user['email'])
        if user:
            if user['password'] == user_db["password"]:
                res = {
                    'user': {
                        "id": user_db["id"],
                        'name': user_db["name"],
                        "email": user_db["email"],
                    }
                }
                return dumps(res), 200

        return 'Not acceptable', 406
Exemplo n.º 11
0
def get_category():
    if request.method == 'GET':
        conn = ConnectionHelper()
        category = dao.get_category(conn)
        return dumps(category), 200
Exemplo n.º 12
0
def get_tribes():
    if request.method == 'GET':
        conn = ConnectionHelper()
        tribes = dao.get_tribes(conn)
        return dumps(tribes), 200
Exemplo n.º 13
0
from connection_helper import ConnectionHelper
from random import uniform, randint
import unicodedata
import json
from pprint import pprint

conn = ConnectionHelper()


def read_file_items(file_name):
    categories = []
    dict_value = None
    value = None
    with open(file_name) as f:
        while True:
            value = f.readline().strip()
            if value == "-":
                categories.append(f.readline().strip())
            elif value == ".":
                break
    return categories


def read_file_json(file_name):
    with open(file_name) as json_data:
        d = json.load(json_data)
        return d


def read_file_indians(file_name):
    value = None