Commit b8475f4c authored by Alan Mitchell's avatar Alan Mitchell

Added signature of API method to return readings from multiple sensors.

parent 1334d910
......@@ -294,6 +294,58 @@ def sensor_readings(request, sensor_id):
return JsonResponse(result, status=500)
def sensor_readings_multiple(request):
"""API Method. Returns readings from multiple sensors, perhaps time-averaged
and filtered by a date/time range.
request: Django request object
The 'request' object can have the following query parameters:
sensor_id: The Sensor ID of a sensor to include. This parameter can occur
multiple times to request data from multiple sensors.
start_ts: (optional) A date/time indicating the earliest reading to return.
If not present, the earliest reading in the database is returned.
Format is a string date/time, interpretable by dateutil.parser.parse.
end_ts: (optional) A date/time indicating the latest reading to return.
If not present records through the latest record in the database are returned.
Format is a string date/time, interpretable by dateutil.parser.parse.
timezone: (optional) A timezone name, present in the pytz.timezone database
e.g. "US/Alaska". The timestamps for the sensor readings are returned
consistent with this timezone. Also, 'start_ts' and 'end_ts' are interpreted
as being in this timezone. If this parameter is not provided, the timezone of
the first building associated with the requested sensor is used. If no
building is associated with the sensor, UTC is the assumed timezone.
averaging: (optional) If provided, sensor readings are averaged into evenly spaced
time intervals as indicated by this parameter. The 'averaging' time interval
must be provided as a string such as '4H' (4 hours), '2D' (2 days), or any interval
describable by Pandas time offset notation:
label_offset: (optional) Only used if an 'averaging' parameter is provided. This
parameter controls what point in the time averaging interval is used to produce
the timestamp for the returned reading. 'label_offset' uses the same format as
'averaging', i.e. Pandas time offset notation, and the value is the time distance
from the start of averaging interval to the location of the timestamp. For example,
a value of '30min' means place the timestamp 30 minutes after the start of the
If no 'label_offset' is provided, the 'label_offset' is assumed to be 0, i.e.
the starting edge of the averaging interval is marked by the timestamp. Note
that the convention in all of the BMON timeseries plots is to place the timestamp
at the *center* of the averaging interval; that is *not* the default in this
function because of the difficulty in automatically calculating the proper
label_offset for the middle of the interval.
A JSON response containing an indicator of success or failure, the readings organized
how they would be exported from a Pandas DataFrame using the "to_json(orient='split')"
method, and the timezone of the timestamps returned.
def sensor_list(request):
"""API Method. Returns a list of all the sensors in the reading
database, including sensor properties, if available.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment