Commit ae3c6c7f authored by Gezer's avatar Gezer
Browse files

modified json format for room data

parent 434b1c37
No related merge requests found
Showing with 13 additions and 11 deletions
+13 -11
...@@ -93,18 +93,20 @@ def room_data_range(request): ...@@ -93,18 +93,20 @@ def room_data_range(request):
) )
tables = client.get_room_data_in_range(room, start, stop) tables = client.get_room_data_in_range(room, start, stop)
results = []
data_by_time = {}
for table in tables: for table in tables:
for record in table.records: for record in table.records:
results.append( timestamp = str(record.get_time())
{ field = record.get_field()
"time": str(record.get_time()), value = record.get_value()
"field": record.get_field(),
"value": record.get_value(), if timestamp not in data_by_time:
} data_by_time[timestamp] = {}
) data_by_time[timestamp][field] = value
return JsonResponse({"room": room, "data": results}, status=200) return JsonResponse({"room": room, "data": data_by_time}, status=200)
except json.JSONDecodeError: except json.JSONDecodeError:
return JsonResponse( return JsonResponse(
{"success": False, "message": "Invalid JSON"}, status=400 {"success": False, "message": "Invalid JSON"}, status=400
......
{ {
"AA:BB:CC:DD:EE:FF": "Wohnzimmer", "AA:BB:CC:DD:EE:FF": "1/121",
"11:22:33:44:55:66": "K\u00fcche", "11:22:33:44:55:66": "K\u00fcche",
"77:88:99:AA:BB:CC": "Schlafzimmer", "77:88:99:AA:BB:CC": "Schlafzimmer",
"DE:AD:BE:EF:12:34": "", "DE:AD:BE:EF:12:34": "",
......
Supports Markdown
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