def call_get_rents(R_id: int):
    select_Query = "select * from get_rent_data(%s);"
    res = Connect_TO_DB(select_Query, (R_id, ))
    if (((res[0])[D_DT]) != None):
        start_time = datetime.fromtimestamp(((res[0])[D_DT]) // 1000)
    else:
        start_time = 'Null'

    if (((res[0])[A_DT]) != None):
        end_time = datetime.fromtimestamp(((res[0])[A_DT]) // 1000)

    else:
        end_time = 'Null'

    return {
        R_ID: ((res[0])[R_ID]),
        D_ST_ID: ((res[0])[D_ST_ID]),
        D_ST_D: ((res[0])[D_ST_D]),
        A_ST_ID: ((res[0])[A_ST_ID]),
        A_ST_D: ((res[0])[A_ST_D]),
        R_D: ((res[0])[R_D]),
        D_DT: start_time,
        A_DT: end_time,
        RE_ID: ((res[0])[RE_ID]),
        R_M_R_ID: ((res[0])[R_M_R_ID]),
        R_R_D: ((res[0])[R_R_D]),
        C_ST_ID: ((res[0])[C_ST_ID]),
        C_ST_D: ((res[0])[C_ST_D]),
        U_ID: ((res[0])[U_ID])
    }
def get_recent_rents(resources_id: int):
    select_Query = "select * from get_recent_rents_data(%s);"
    res1 = Connect_TO_DB(select_Query, (resources_id, ))
    res3 = []
    for x in range(0, len(res1)):
        if (((res1[x])[D_DT]) != None):
            start_time = datetime.fromtimestamp(((res1[x])[D_DT]) // 1000)
        else:
            start_time = 'Null'
        if (((res1[x])[A_DT]) != None):
            end_time = datetime.fromtimestamp(((res1[x])[A_DT]) // 1000)
        else:
            end_time = 'null'

        res3.append({
            R_ID: ((res1[x])[R_ID]),
            D_DT: start_time,
            A_DT: end_time,
            U_ID: ((res1[x])[U_ID]),
            R_D: ((res1[x])[R_D]),
            D_ST_ID: ((res1[x])[D_ST_ID]),
            D_ST_D: ((res1[x])[D_ST_D]),
            A_ST_ID: ((res1[x])[A_ST_ID]),
            A_ST_D: ((res1[x])[A_ST_D])
        })
    return res3
def call_get_all_model_resources():
    select_Query = "select * from get_all_model_resources_ids();"
    res = Connect_TO_DB(select_Query)
    F_results = []  # final results
    for x in range(0, len(res)):
        results = call_get_model_resources((res[x])[MR_ID])
        F_results.append(results)
    return {"model_resources": F_results}
Beispiel #4
0
def insert_or_update_station(ST_id: int, station_data: station.Station):
    select_Query = "select from create_or_update_station(%s,%s);"
    station_data = str(json.dumps(station_data.dict()))
    data = (
        ST_id,
        station_data,
    )
    res = Connect_TO_DB(select_Query, data)
    return {}
def call_get_all_station():
    select_Query = "select * from get_all_station_ids();"
    res = Connect_TO_DB(select_Query)
    F_results = []  # final results
    for x in range(0, len(res)):
        results = call_get_station((res[x])[ST_ID])
        F_results.append(results)

    return {"stations": F_results}
Beispiel #6
0
def insert_or_update_model_resource(
        MR_id: int, model_resource_data: resource_model.ResourceModel):
    select_Query = "select from create_or_update_model_resources(%s,%s);"
    model_resource_data = str(json.dumps(model_resource_data.dict()))
    data = (
        MR_id,
        model_resource_data,
    )
    res = Connect_TO_DB(select_Query, data)
    return {}
Beispiel #7
0
def insert_or_update_resource(RE_id: int, ST_id: int, MR_id: int,
                              resource_data: resource.Resource):
    resource_data = str(json.dumps(resource_data.dict()))
    select_Query = "select from create_or_update_resources(%s,%s,%s,%s);"
    data = (
        RE_id,
        ST_id,
        MR_id,
        resource_data,
    )
    res = Connect_TO_DB(select_Query, data)
    return {}
def call_get_resources(RE_id: int):
    select_Query = "select * from get_resources_data(%s);"
    res = Connect_TO_DB(select_Query, (RE_id, ))
    # return the results of get_recent_rents
    results2 = get_recent_rents(RE_id)
    return {
        RE_ID: ((res[0])[RE_ID]),
        RE_D: ((res[0])[RE_D]),
        MR_ID: ((res[0])[MR_ID]),
        MR_D: ((res[0])[MR_D]),
        C_ST_ID: ((res[0])[ST_ID]),
        C_ST_D: ((res[0])[ST_D]),
        L_R: results2
    }
def call_get_station(st_id: int):
    select_Query = "select * from get_station_data_by_id(%s);"
    res = Connect_TO_DB(select_Query, (st_id, ))
    print((res[0])[RE_ID])
    resources_results = []
    for x in range(0, len(res)):
        resources_results.append({
            RE_ID: ((res[x])[RE_ID]),
            RE_D: ((res[x])[RE_D]),
            MR_ID: ((res[x])[MR_ID]),
            MR_D: ((res[x])[MR_D])
        })

    return {
        ST_ID: ((res[0])[ST_ID]),
        D: ((res[0])[D]),
        "Resources": resources_results
    }
Beispiel #10
0
def insert_or_update_rent(rent_data: rent.Rent):
    rent_data = rent_data.dict()
    rent_id = rent_data['rent_id']
    resource_id = rent_data['resource_id']
    User_id = rent_data['user_id']
    if (User_id == 0):
        User_id = None
    StartStation_id = rent_data['StartStation_id']
    EndStation_id = rent_data['EndStation_id']
    if (EndStation_id == 0):
        EndStation_id = None
    Departure_station_time = rent_data['StartTime']
    Departure_station_time = Departure_station_time.replace(tzinfo=None)
    Departure_station_time = int(
        (Departure_station_time - epoch).total_seconds() * 1000.0)
    Arrival_station_time = rent_data['EndTime']
    if (Arrival_station_time != "string"):
        Arrival_station_time = datetime.datetime.strptime(
            Arrival_station_time, '%Y-%m-%dT%H:%M:%S.%fZ')
        Arrival_station_time = Arrival_station_time.replace(tzinfo=None)
        Arrival_station_time = int(
            (Arrival_station_time - epoch).total_seconds() * 1000.0)
    else:
        Arrival_station_time = None
    rent_data = str(json.dumps({"Cost": rent_data['rentCost']}))
    select_Query = "select from create_or_update_rents(%s,%s,%s,%s,%s,%s,%s,%s);"
    data = (
        rent_id,
        StartStation_id,
        Departure_station_time,
        resource_id,
        rent_data,
        User_id,
        EndStation_id,
        Arrival_station_time,
    )

    res = Connect_TO_DB(select_Query, data)
    return {}
Beispiel #11
0
def call_delete_model_resources(MR_id: int):
    select_Query="select * from delete_model_resources(%s);"
    res=Connect_TO_DB(select_Query,(MR_id,))
    return res
Beispiel #12
0
def call_delete_station(ST_id :int):
    select_Query="select * from delete_station(%s);"
    res=Connect_TO_DB(select_Query,(ST_id,))
    return res
Beispiel #13
0
def call_delete_rent(R_id: int):
    select_Query="select * from delete_rent(%s);"
    res=Connect_TO_DB(select_Query,(R_id,))
    return res
def call_get_model_resources(MR_Id: int):
    select_Query = "select * from get_model_resources_data(%s);"
    res = Connect_TO_DB(select_Query, (MR_Id, ))
    return {MR_ID: ((res[0])[MR_ID]), D: ((res[0])[D])}