Git Product home page Git Product logo

Comments (3)

doganulus avatar doganulus commented on July 29, 2024

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.

jcarrano avatar jcarrano commented on July 29, 2024

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.

doganulus avatar doganulus commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.