From ae3c6c7fb5674780350e3aa32eaba0bc4c12bfc9 Mon Sep 17 00:00:00 2001 From: 21geem1bif <21geem1bif@hft-stuttgart.de> Date: Tue, 3 Jun 2025 15:15:17 +0200 Subject: [PATCH] modified json format for room data --- backend/app/views.py | 22 ++++++++++++---------- stream_processing/mac_to_room.json | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/app/views.py b/backend/app/views.py index 626d5e4..2224cea 100644 --- a/backend/app/views.py +++ b/backend/app/views.py @@ -93,18 +93,20 @@ def room_data_range(request): ) tables = client.get_room_data_in_range(room, start, stop) - results = [] + + data_by_time = {} + for table in tables: for record in table.records: - results.append( - { - "time": str(record.get_time()), - "field": record.get_field(), - "value": record.get_value(), - } - ) - - return JsonResponse({"room": room, "data": results}, status=200) + timestamp = str(record.get_time()) + 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": data_by_time}, status=200) except json.JSONDecodeError: return JsonResponse( {"success": False, "message": "Invalid JSON"}, status=400 diff --git a/stream_processing/mac_to_room.json b/stream_processing/mac_to_room.json index 0f61203..c822d99 100644 --- a/stream_processing/mac_to_room.json +++ b/stream_processing/mac_to_room.json @@ -1,5 +1,5 @@ { - "AA:BB:CC:DD:EE:FF": "Wohnzimmer", + "AA:BB:CC:DD:EE:FF": "1/121", "11:22:33:44:55:66": "K\u00fcche", "77:88:99:AA:BB:CC": "Schlafzimmer", "DE:AD:BE:EF:12:34": "", -- GitLab