Comments (3)
Yes, I have removed nested structures in v2008 as they were half-baked. Currently monitors work on flat json/dict objects.
I would love to hear about your particular use case. Could you elaborate the case and the structure of json/python objects that you would like to monitor?
Thanks.
from reelay.
Dogan, first of all, thanks for making public this software. I stated using it only a short time ago.
I am monitoring MQTT messages which are composed of JSON objects. Convert MQTT topics into objects (e.g. "a/b/c" goes to {"a": {"b": {"c":{}}}) and put the payload object into the innermost sub-objects.
On a second thought, I could ditch this (admittedly complicated) logic and flatten all using name mangling (e.g. "a__b__c__etc"). In fact (correct me if I'm wrong), all of v2005's nested structured features can be emulated using flat, mangled names, since Rye-2005 only allowed operating on leaf values.
from reelay.
Yes, the workaround is flattennig the JSON objects. Two popular choices are using dots ("a.b.c") as in Javascript or using slashes ("/a/b/c") as in JSON pointer standard.
The other alternative is to use a python type that supports nested keys. Below is an example code that uses pyhocon
library.
from reelay import discrete_timed_monitor
from pyhocon import ConfigFactory
my_monitor = discrete_timed_monitor(
pattern=r"{'root.speed' > 13.0} since[:3] {'root.lights_on'}", #notice the quotes on nested keys
condense=False
)
input_sequence = [
dict(root=dict(speed=3.3, lights_on=False)),
dict(root=dict(speed=6.3, lights_on=False)),
dict(root=dict(speed=9.3, lights_on=True)),
dict(root=dict(speed=13.3, lights_on=False)),
dict(root=dict(speed=13.4, lights_on=False)),
dict(root=dict(speed=13.3, lights_on=False)),
dict(root=dict(speed=13.2, lights_on=False)),
dict(root=dict(speed=13.2, lights_on=False)),
]
result = []
for x in input_sequence:
y = my_monitor.update(ConfigFactory.from_dict(x)) #converting to hocon type
result.append(y)
expected = [
{'value': False},
{'value': False},
{'value': True},
{'value': True},
{'value': True},
{'value': True},
{'value': False},
{'value': False}]
print(result == expected)
This works because Reelay takes the string in the specification, and use it directly to access object fields.
from reelay.
Related Issues (13)
- Latest Docker image doesn't recognize the "rymtl" command HOT 1
- can't find "reelay/recipes.hpp" HOT 2
- Operator precedence for the PEG parser HOT 1
- Monitor formula to compare two data values HOT 2
- Segmentation fault while making monitor with References and Quantifiers HOT 3
- Links in the python getting started need updating
- Installing reelay on mac m1 HOT 1
- Automate Python releases using GitHub Actions HOT 1
- Python API design HOT 1
- Custom predicates from Python HOT 1
- Investigate compatibility with older standards HOT 1
- Pybind 2.4.3 and Clang and C++17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reelay.