-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to acquire bulk readings in compact JSON format
The "compact JSON" format is currently defined with timestamps as keys. Example: { "1611082554": { "temperature": 21.42, "humidity": 41.55 }, "1611082568": { "temperature": 42.84, "humidity": 83.1 } }
- Loading branch information
Showing
5 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2021 Andreas Motl <andreas@getkotori.org> | ||
import json | ||
|
||
|
||
class CompactTimestampedJsonDecoder: | ||
""" | ||
Decode JSON payloads in compact format, with timestamps as keys. | ||
Documentation | ||
============= | ||
- https://getkotori.org/docs/handbook/decoders/json.html (not yet) | ||
- https://github.com/daq-tools/kotori/issues/39 | ||
Example | ||
======= | ||
:: | ||
{ | ||
"1611082554": { | ||
"temperature": 21.42, | ||
"humidity": 41.55 | ||
}, | ||
"1611082568": { | ||
"temperature": 42.84, | ||
"humidity": 83.1 | ||
} | ||
} | ||
""" | ||
|
||
@staticmethod | ||
def decode(payload): | ||
|
||
# Decode from JSON. | ||
message = json.loads(payload) | ||
|
||
# Create list of data dictionaries. | ||
data = [] | ||
for timestamp, item in message.items(): | ||
item["time"] = timestamp | ||
data.append(item) | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters