Get a dataset
Description: retrieve a dataset
uri: /datasets/trajectory/<name>
http method: GET
Sequence Diagram
Code
#retrieve a dataset/trajectory/~in given range
@app.route('/datasets/trajectory/<name>', methods=['GET'])
def retrieve_a_dataset(name):
#conn_string = "host='192.168.100.200' dbname='hdwu' user='hdwu' password='4321'"
#conn = pg.connect(conn_string)
#if name == "taxi"
args = request.args
trajectory = []
if 'tid' in args:
query = "select * from trajectory." + name + " where tid=" + args['tid']+ ";"
rows = conn.query(query).getresult()
for row in rows:
if len(trajectory) == 0:
trajectory.append({'tid': row[0], 'points': [{'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]}]})
else: trajectory[0]['points'].append({'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]})
elif 'lon_s'and 'lon_e' and 'lat_s' and 'lat_e' in args:
query = "select * from trajectory." + name + " where lon>=" + args['lon_s'] + " and lon<=" + args['lon_e'] + " and lat>=" + args['lat_s'] + " and lat<=" + args['lat_e'] + ";"
rows = conn.query(query).getresult()
for row in rows:
print row
if row[0] == len(trajectory)-1:
trajectory[row[0]]['points'].append({'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]})
else: trajectory.append({'tid': row[0], 'points': [{'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]}]})
else:
query = "select * from trajectory." + name + ";"
rows = conn.query(query).getresult()
for row in rows:
if row[0] == len(trajectory)-1:
trajectory[row[0]]['points'].append({'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]})
else: trajectory.append({'tid': row[0], 'points': [{'index': row[1], 'lon': row[2], 'lat': row[3], 'timestamp': row[4]}]})
return jsonify({'trajectory': trajectory})