Add Trajectory
Description: Add a new trajectory to dataset
URI: /datasets/trajectory/<name>
http method: POST
Code
app.route('/datasets/trajectory/<string:name>', methods=['POST'])
def addTrajectory(name):
if not request.json:
abort(400)
json_args = request.json
traj_points = json_args.get('trajectory')
query = "SELECT MAX(tid) FROM " + name + ";"
rows = conn.query(query).getresult()
next_tid = int(rows[0][0]) +1
tid = str(next_tid)
for point in traj_points:
lon = point.get('lon')
lat = point.get('lat')
timestamp = point.get('timestamp')
query= "INSERT INTO " + name +" (tid,lon, lat, timestamp) VALUES ("+ tid +","+ str(lon)+","+ str(lat)+", "+str(timestamp)+");"
print query
conn.query(query)
return "Add trajectory :" + tid