Ejemplo n.º 1
0
def select_menu():
    get_session = request.cookies.get('room_session')
    room_id = get_room_id_from_session(get_session)
    pr_session = request.cookies.get('pr_session')
    user_id = get_id_from_db(pr_session)

    host_id = get_host_id_from_roomid(room_id)

    query = "select restaurant_id from room where room_id = '%d'"
    restaurant_id = select_one(query % (room_id))

    query = "select food_name, food_price from pr_food where restaurant_id = '%d'"
    food_table = select_all(query % int(restaurant_id[0]))
    food_List = list()
    for table_one in food_table:
        food_dic = {'food_name': table_one[0], 'food_price': table_one[1]}
        food_List.append(food_dic)

    uinfo = list()

    if host_id == user_id:
        info = 0
        uinfo.append(info)
    else:
        query = "select user_name from pr_user where user_id = '%d'"
        get_table = select_one(query % user_id)
        info = get_table[0]
        uinfo.append(info)

    return jsonify(results = food_List, results2 = uinfo)
Ejemplo n.º 2
0
def show_total():
    pr_session = request.cookies.get('pr_session')
    user_id = get_id_from_db(pr_session)

    query = "select taker, price from total_price where giver = '%d'"    #내가 줘야되는 돈
    query2 = "select user_name from pr_user where user_id = '%d'"
    query3 = "select giver, price from total_price where taker = '%d'"   #내가 받아야되는 돈
    table_all = select_all(query % user_id)
    get_table = select_one(query2 % user_id)
    myname = get_table[0]

    pay_list = list()
    for table_one in table_all:
        name = select_one(query2 % table_one[0])
        taker_name = name[0]
        pay_dic = {'giver': myname, 'taker':taker_name, 'price': table_one[1]}
        pay_list.append(pay_dic)

    payed_list = list()
    table_all = select_all(query3 % user_id)
    for table_one in table_all:
        name = select_one(query2 % table_one[0])
        giver_name = name[0]
        pay_dic = {'giver': giver_name, 'taker': myname, 'price': table_one[1]}
        payed_list.append(pay_dic)
    return jsonify(results = pay_list, results2 = payed_list)
Ejemplo n.º 3
0
def calculateTotal(room_id):
    query = "select payer_id from room where room_id = '%d'"
    get_table = select_one(query % room_id)
    payer_id = get_table[0]

    query = "select user_id from room_list where room_id = '%d' and user_present = 1"
    get_table = select_all(query % room_id)
    user_list = list()
    query = "select sum(food_price) from user_orderlist where room_id = '%d' and user_id = '%d' group by user_id"
    for one_table in get_table:
        user_id = one_table[0]
        if payer_id == user_id:
            continue
        price = select_one(query % (room_id, user_id))
        user_price = price[0]
        user_dic = {'user_id': user_id, 'user_price': user_price}
        user_list.append(user_dic)

    list_length = len(user_list)
    i = 0
    query = "insert into total_price (giver, taker, price, room_id) values ('%d', '%d', '%d', '%d')"
    while i < list_length:
        insert(query % (user_list[i]['user_id'], payer_id, user_list[i]['user_price'], room_id))
        i+=1

    return ""
Ejemplo n.º 4
0
def save_user_menu(uid, rid, request_data):
    restaurant_id = get_restaurant_id_from_roomid(rid)
    query = "insert into user_orderlist values ('%d', '%d', '%s', '%d', '%d');"
    query2 = "select food_id from pr_food where restaurant_id = '%d' and food_name = '%s'"
    query3 = "select food_price from pr_food where food_id = '%d'"
    query4 = "delete from user_orderlist where room_id = '%d' and user_id = '%d'"
    insert(query4 % (rid, uid))
    for i in range(1, request_data[0] + 1):
        food_id = select_one(query2 % (restaurant_id, request_data[i]))
        food_price = select_one(query3 % int(food_id[0]))
        insert(
            query %
            (rid, uid, request_data[i], int(food_id[0]), int(food_price[0])))

    return ""
Ejemplo n.º 5
0
def getPayerInfo(room_id):
    query = "select payer_id from room where room_id = '%d'"
    get_table = select_one(query % room_id)
    if get_table is None:
        return None
    else:
        return get_table[0]
Ejemplo n.º 6
0
def check_room_token(room_id):
    if 'room_session' in request.cookies:
        session_key = request.cookies['room_session']
        query = "select room_id from room_session where session_key = '%s'"
        table = select_one(query % (session_key))
        if room_id == int(table[0]):
            return True
    return False
Ejemplo n.º 7
0
def CompleteOrder(room_id):
    query = "select room_exist from room where room_id = '%d'"
    get_table = select_one(query % room_id)
    room_exist = get_table[0]

    if(room_exist == 0):
        return None

    query = "update room set room_exist = 0 where room_id = '%d'"
    insert(query % room_id)
    return ""
Ejemplo n.º 8
0
def getRoom(request_data):
    room = Room()
    room.room_pw = request_data['passwd']
    room.room_id = request_data['roomid']

    query = "select room_pw from room where room_id = '%d'"
    table = select_one(query % int(room.room_id))

    if table[0] != room.room_pw:
        room = None

    return room
Ejemplo n.º 9
0
def show_room(room_id):
    if check_token():
        if check_room_token(room_id):
            query = "select chief_id from room where room_id = '%d'"
            host_id = select_one(query % room_id)

            query = "select user_name from pr_user where user_id = '%d'"
            host_name = select_one(query % host_id[0])

            query2 = "select restaurant_name, restaurant_location, restaurant_phone, r1.restaurant_id from pr_restaurant as r1, (select restaurant_id from room where room_id = '%d') as r2 where r1.restaurant_id = r2.restaurant_id;"
            restaurant_info = select_one(query2 % room_id)

            query3 = "select room_title from room where room_id = '%d'"
            room_title = select_one(query3 % room_id)

            query4 = "select created from room where room_id = '%d'"
            created = select_one(query4 % room_id)

            query5 = "select room_inwon from room where room_id = '%d'"
            room_inwon = select_one(query5 % room_id)

            menu_table = showingMenu_from_rid(restaurant_info[3])

            return render_template("room.html", host_name = host_name[0], rname = restaurant_info[0], rlocation = restaurant_info[1], rphone = restaurant_info[2], menu_table = menu_table, room_title = room_title[0], created = created[0], room_inwon = int(room_inwon[0])), 200

        return render_template("password.html", room_id = room_id), 200
Ejemplo n.º 10
0
def room_member():
    room_session = request.cookies.get('room_session')
    room_id = get_room_id_from_session(room_session)

    menu_list = list()

    query1 = "select user_id from room_list where room_id = '%d' and user_present = 1"
    user_table = select_all(query1 % (room_id))

    restaurant_id = get_restaurant_id_from_roomid(room_id)
    query2 = "select food_name, food_price from user_orderlist where user_id = '%d' and room_id = '%d' order by user_id" #음식 정보 가져오기
    query3 = "select user_name from pr_user where user_id = '%d'"   #유저이름 가져오기
    query4 = "select user_ready from room_list where room_id = '%d' and user_id = '%d' and user_present = 1"    #유저 레디 정보 가져오기
    ftable_dic = dict()

    for utable_one in user_table:
        total_price = 0
        food_list = list()
        food_table = select_all(query2 % (int(utable_one[0]), room_id))
        for ftable_one in food_table:
            ftable_dic = {'food_name': ftable_one[0], 'food_price': ftable_one[1]}
            total_price += int(ftable_one[1])
            food_list.append(ftable_dic)

        user_name = select_one(query3 % utable_one[0])
        ready = select_one(query4 % (room_id, utable_one[0]))
        utable_dic = {'user_name': user_name[0], 'user_choice': food_list, 'user_pay': total_price, 'user_ready': ready[0]}
        menu_list.append(utable_dic)

    uinfo = list()
    for table_one in user_table:
        query = "select user_name from pr_user where user_id = '%d'"
        uname = select_one(query % table_one[0])
        p_dic = {'user_name': uname[0], 'user_id': table_one[0]}
        uinfo.append(p_dic)

    return jsonify(results = menu_list, results2 = uinfo)
Ejemplo n.º 11
0
def order_ready():
    pr_session = request.cookies.get('pr_session')
    user_id = get_id_from_db(pr_session)
#유저 id와 방 id를 가지고 RoomList에서 user_ready를 1로 바꿔주면 땡
    room_session = request.cookies.get('room_session')
    room_id = get_room_id_from_session(room_session)

    query = "select user_ready from room_list where user_present = 1 and room_id = '%d' and user_id = '%d'"
    ready = select_one(query % (room_id, user_id))

    if ready[0]:
        query2 = "update room_list set user_ready = 0 where room_id = '%d' and user_id = '%d' and user_present = 1"
        insert(query2 % (room_id, user_id))
    else:
        query2 = "update room_list set user_ready = 1 where room_id = '%d' and user_id = '%d' and user_present = 1"
        insert(query2 % (room_id, user_id))

    return jsonify(results = ready[0])
Ejemplo n.º 12
0
def user_recommend():
    get_session = request.cookies.get('pr_session')
    user_id = get_id_from_db(get_session)

    query = "select chief_id, room_title, restaurant_id, created, room_id from room as r1, (select e2.location_id as location_id from (select univ_id from pr_user where user_id = '%d') as e1, pr_university as e2 where e1.univ_id = e2.univ_id) as r2 where r1.location_id = r2.location_id order by created desc;"
    table_all = select_all(query % user_id)
    room_List = list()
    for table_one in table_all:
        username = get_username_from_db(table_one[0])
        rname = get_restaurantname_from_db(table_one[2])
        room_dic = { 'user_name':username,'room_title': table_one[1], 'restaurant_name':rname,'created':table_one[3], 'room_id':table_one[4]}
        room_List.append(room_dic)

    myindex = 0
    query = "select user_id from pr_user"
    userAll = select_all(query)

    userList = list()
    for index in userAll:
        userList.append(index[0])

    sets = [set() for _ in range(0, len(userList))]

    for index in range(0, len(userList)):
        if (userList[index] == user_id):
            myindex = index
        query = "select food_id from user_orderlist where user_id = '%d'"
        temp = select_all(query % userList[index])
        orderList = list()
        for i in temp:
            orderList.append(i[0])

        for i in range(0, len(orderList)):
            sets[index].add(orderList[i])

    datas = []

    for i in range(0, len(userList)):
        temp = []
        for j in range(0, len(userList)):
            if (i != j):
                a = sets[i]
                b = sets[j]
                temp.append(len(a & b) / len(a | b))
            else:
                temp.append(0)

        datas.append(temp)
    #print(datas)
    df_x = pd.DataFrame(datas)
    nCluster = len(userList) ** 0.5

    kmeans = KMeans(n_clusters=round(nCluster), random_state=0).fit(df_x)
    print(kmeans.labels_)
    recommands = set()
    mine = sets[myindex]
    print(myindex)
    for index in range(0,len(kmeans.labels_)):
        if (kmeans.labels_[myindex] == kmeans.labels_[index]):
            recommands = recommands.union(sets[index] - mine)

    recommend_list = list(recommands)
    print(recommend_list)
    list_len = len(recommend_list)
    recommend_info = list()
    i = 100
    print(len(recommend_list))
    while i < 120:
        if(recommend_list[i] >= 10000):
            print(recommend_list[i])
            query = "select restaurant_id from pr_food where food_id = '%d'"
            get_table = select_one(query % recommend_list[i])
            query2 = "select restaurant_name from pr_restaurant where restaurant_id = '%d'"
            rname = select_one(query2 % get_table[0])
            restaurant_name = rname[0]
            query3 = "select food_name from pr_food where food_id = '%d'"
            fname = select_one(query3 % recommend_list[i])
            food_name = fname[0]
            query4 = "select food_price from pr_food where food_id = '%d'"
            fprice = select_one(query4 % recommend_list[i])
            food_price = fprice[0]
            rdic = {'restaurant_name': restaurant_name, 'food_name': food_name, 'food_price': food_price}
            recommend_info.append(rdic)
        i+=1

    return jsonify(results = recommend_info)
Ejemplo n.º 13
0
def getUserNumber(room_id):
    query = "select count(user_id) from room_list where user_present = 1 and room_id = '%d' and user_ready = 1"
    get_table = select_one(query % room_id)
    return get_table[0]