return engine
-@app.route('/api/<version>/sensors/')
-def sensors(version):
- """List all sensors found in the database"""
+def select_sensordata(initial_where, initial_sql_args):
engine = open_engine(config)
with engine.connect() as conn:
- cursor = conn.execute('select distinct sensor_id, sensor_name, value_type from sensors')
- result = [dict(row) for row in cursor]
- return jsonify(result)
-
-
-@app.route('/api/<version>/sensor/<sensor_id>')
-def sensor(version, sensor_id):
- """Return all sensor data
-
- URL parameters:
- begin=<datetime>, optional, format like "2018-05-19T21:07:53"
- end=<datetime>, optional, format like "2018-05-19T21:07:53"
- mode=<full|consolidated>, optional. return all rows (default) or with lower resolution (for charts)
- """
- engine = open_engine(config)
- with engine.connect() as conn:
- where = ['sensor_id=%s']
- sql_args = [sensor_id]
+ where = [initial_where]
+ sql_args = [initial_sql_args]
begin = None
end = None
if 'begin' in request.args:
# TODO: filter out samples from 'result'
# like loop over results and skip if timestamp(n+1)-timestamp(n)<resolution
+ return result
+
+
+@app.route('/api/<version>/sensors/')
+def sensors(version):
+ """List all sensors found in the database"""
+ engine = open_engine(config)
+ with engine.connect() as conn:
+ cursor = conn.execute('select distinct sensor_id, sensor_name, value_type from sensors')
+ result = [dict(row) for row in cursor]
return jsonify(result)
+@app.route('/api/<version>/sensor/id/<sensor_id>')
+def sensorid(version, sensor_id):
+ """Return all data for a specific sensor
+
+ URL parameters:
+ begin=<datetime>, optional, format like "2018-05-19T21:07:53"
+ end=<datetime>, optional, format like "2018-05-19T21:07:53"
+ mode=<full|consolidated>, optional. return all rows (default) or with lower resolution (for charts)
+ """
+ result = select_sensordata('sensor_id=%s', sensor_id)
+ return jsonify(result)
+
+
+@app.route('/api/<version>/sensor/type/<sensor_type>')
+def sensortype(version, sensor_type):
+ """Return all data for a specific sensor type
+
+ URL parameters:
+ begin=<datetime>, optional, format like "2018-05-19T21:07:53"
+ end=<datetime>, optional, format like "2018-05-19T21:07:53"
+ mode=<full|consolidated>, optional. return all rows (default) or with lower resolution (for charts)
+ """
+ result = select_sensordata('value_type=%s', sensor_type)
+ return jsonify(result)
+
+
@app.route('/data/', defaults={'timespan': 1})
@app.route("/data/<int:timespan>", methods=['GET'])
def data(timespan):