Esempio n. 1
0
def get_constraints(day):
    if day == 5 or day == 11:
        sql = route_records.get_constraints(2)
        print(sql)
        r = pgsqlib.fetch(sql)

        data = {
            "cons_dur": r[0][0],
            "cons_dis": r[0][2],
            "cons_rest": r[0][3],
            "cons_stop": r[0][4]
        }
    else:
        sql = route_records.get_constraints(1)
        print(sql)
        r = pgsqlib.fetch(sql)

        data = {
            "cons_dur": r[0][0],
            "cons_dis": r[0][2],
            "cons_rest": r[0][3],
            "cons_stop": r[0][4]
        }

    return data
Esempio n. 2
0
def get_sales():
    ori = route_records.check_sales('P')
    print(ori)
    r = pgsqlib.fetch(ori)

    data = {"sales_id": r[0][0], "sales_name": r[0][1], "ori_id": r[0][2]}

    return data
Esempio n. 3
0
def check_sales(status):
    ori = route_records.check_sales(status)
    print(ori)
    res = pgsqlib.fetch(ori)
    if len(res) == 0:
        print("sales sudah ganti")
        sql = route_records.proc_sales_id()
        pgsqlib.execScalar(sql)
    else:
        pass
Esempio n. 4
0
def get_diss(sales_id, day):
    sql = route_records.get_diss(sales_id, day)
    print(sql)
    data = pgsqlib.fetch(sql)
    diss = data[0][0]
    if diss == None:
        diss = 0
    else:
        pass
    print(diss)
    return diss
Esempio n. 5
0
def check_point_sales():
    sql = route_records.checkPointSales()
    data = pgsqlib.fetch(sql)
    print(data)
    data = data[0][1]
    if data == None:
        data = 0
    else:
        data = 1
    print(data)
    return data
Esempio n. 6
0
def get_durs(sales_id, day):
    sql = route_records.get_durs(sales_id, day)
    print(sql)
    data = pgsqlib.fetch(sql)
    durs = data[0][0]
    stop = data[0][1] * 600
    if durs == None:
        durs = 0
    else:
        durs += stop
    print("durs %s" % durs)
    return durs
Esempio n. 7
0
def get_ori_id():
    sql = route_records.get_ori_id()
    print(sql)
    r = pgsqlib.fetch(sql)

    data = {
        "sales_id": r[0][0],
        "sales_name": r[0][1],
        "day": r[0][2],
        "ori_id": r[0][3]
    }

    return data
Esempio n. 8
0
def update_sales_queue(dest_id, sales_id, day):
    ori = route_records.check_sales('Q')
    print(ori)
    res = pgsqlib.fetch(ori)
    print("len update sales %s" % len(res))
    if len(res) == 0:
        #update tb_route_fc
        sql = route_records.updatePointSales('dest_id', dest_id, 'D', sales_id,
                                             day)
        print(sql)
        pgsqlib.execScalar(sql)

        print("all sales has been used")
    else:
        pass
Esempio n. 9
0
def clustering():
	data_constraint = [357,305]

	n = 0
	while n <= 11:
		sql = prep_records.select_first_cluster_id()
		res = pgsqlib.fetch(sql)
		ori_id = res[0][0]

		if n == 5 or n == 11:
			limit_constraint = data_constraint[1]
		else:
			limit_constraint = data_constraint[0]

		sql = prep_records.update_cluster_table(n, ori_id, limit_constraint)
		print(sql)
		pgsqlib.execScalar(sql)

		sql = prep_records.insert_depo(n)
		print(sql)
		pgsqlib.execScalar(sql)

		n += 1
Esempio n. 10
0
def get_ori(ori_id, day):
    ori = route_records.get_ori_dest(ori_id, day)
    print(ori)
    r = pgsqlib.fetch(ori)

    print(r)

    if len(r) == 0:
        data = {}
    else:
        data = {
            "id": r[0][0],
            "ori_id": r[0][1],
            "ori_lat": r[0][2],
            "ori_lon": r[0][3],
            "dest_id": r[0][4],
            "dest_lat": r[0][5],
            "dest_lon": r[0][6],
            "distance": r[0][7],
            "duration": r[0][8],
            "polyline": r[0][9]
        }

    return data