passenger_id = row[0]
        time_stamp = row[1]
        long = float(row[2])
        lat = float(row[3])

        # Use google s2Sphere library to calculate Cell
        p1 = s2sphere.LatLng.from_degrees(lat, long)
        cell = s2sphere.CellId.from_lat_lng(p1).parent(15)
        cell_id = str(cell.id())
        #print (cell_id)

        # update passenger current and previous location
        res = igz_nosql_web.ngx_update_expression_request(
            s, WEBAPI_URL, PASSENGERS_TABLE_PATH + "passenger_" + passenger_id,
            None, None, None,
            "SET previous_cell_id=if_not_exists(current_cell_id,0);current_cell_id="
            + cell_id +
            ";change_cell_id_indicator=(previous_cell_id != current_cell_id);",
            None)

        if res.status_code not in (200, 204):
            print("Error during update of passengers table. Error code is " +
                  str(res.status_code))

# Get current and previous cell for passenger
        response_json = igz_nosql_web.ngx_get_item_request(
            s,
            WEBAPI_URL,
            PASSENGERS_TABLE_PATH + "passenger_" + passenger_id,
            None,
            None,
示例#2
0
    for row in readCSV:
        #print(row)
        driver_id = row[0]
        time_stamp = row[1]
	long = float(row[2])
        lat  = float(row[3])

	# Use google s2Sphere library to calculate Cell 
        p1 = s2sphere.LatLng.from_degrees(lat,long)
        cell = s2sphere.CellId.from_lat_lng(p1).parent(15)
        cell_id = str(cell.id())
        #print (cell_id)

        # update driver current and previous location 
        res = igz_nosql_web.ngx_update_expression_request(s,BASE_URL, DRIVERS_PATH_IN_URL + "driver_" + driver_id, None, None,
                                            "CreateOrReplaceAttributes",
                                            "previous_cell_id=current_cell_id;current_cell_id=" + cell_id + ";change_cell_id_indicator=(previous_cell_id != current_cell_id);",
                                            "exists(current_cell_id)")
	
        # if driver does not exist, add driver
	if res.status_code == requests.codes.bad_request:
            igz_nosql_web.ngx_update_expression_request(s,BASE_URL, DRIVERS_PATH_IN_URL + "driver_" + driver_id, None, None,
                                          "CreateOrReplaceAttributes",
                                          "current_cell_id=" + cell_id + ";previous_cell_id=0;change_cell_id_indicator=(1==1);",
                                          "(1==1)")

        # Get current and previous cell for driver 
        response_json = igz_nosql_web.ngx_get_item_request(s,BASE_URL, DRIVERS_PATH_IN_URL+"driver_"+driver_id,None,None,exp_attrs=["change_cell_id_indicator","current_cell_id","previous_cell_id"])

        # Check if a cell update is needed
        attrs = response_json["Item"]
        change_cell_id_indicator_val = attrs["change_cell_id_indicator"]["BOOL"]