Data aggregation and propagation across multi-level system device hierarchy

Hi all,

Our team is working on an application that needs to support the following structure:

The leaf nodes of the tree are regular devices that report one attribute “color” that can change over time.
While the none-leaf nodes represent the physical organization of those devices.
Keep in mind that the depth of the tree can vary as well as the number of nodes per level.

One of the requirements of the application is to be able to aggregate the data of the devices at any level of the tree structure. For instance, a user may like to know how many devices were reported as “green” two days ago for State 2. Another user could ask how many devices were in “red” last week in City 4.

Our first approach was to implement a System Device for each none-leaf node in the tree hierarchy. Each System Device would automatically calculate the aggregations mentioned above based on the selected query interval.
We realized that there is no aggregation that allows you to count the number of devices that were in a given color. So we replaced the color attribute of the devices with three booleans (red, blue, green). Depending on the color of the device is, one boolean will be true, the rest will set to false. So in the System Device we declared three attributes (red, blue, green) that would automatically calculate the sum of devices for each color accordingly.

Next thing we started to simulate data in order to test how aggregations work with several Devices and
System Devices. But, when we tried to simulate data sent in the past we realize that System Devices do not track when the original state (from the Devices) was sent. So, if a Device (let’s say Device 1 in the picture) reports that yesterday it was “blue” the next System Device in the hierarchy (City 1) will assume that Device 1 is “blue” today.
Sending data in the past is not only a simulation requirement. In a real scenario, we could also get Device state updates from previous days. What alternative do we have here? Should we use regular devices for the none-leaf nodes in the hierarchy too? If so, how should we trigger the aggregations now that is something that we should manage internally? Would the aggregation calculations scale if the number of devices and none-leaf nodes increase? Which is the best way of associating devices in a tree structure now that the child-parent functionality provided by the System Devices is not an option? Maybe using tags?

Thanks in advance

Systems would have been perfect for this use case if not for the requirement to recalculate the system aggregation for devices reported with a past timestamp.

My next suggestion was going to be device tags, where “Device 1” would get tagged with “city=City 1”, "state=“State 1”, etc., as you could then perform your data queries by passing in "state=“State 1” to get all devices under it. But this falls apart with your requirement of “Keep in mind that the depth of the tree can vary”, especially if the names of the depth nodes varies in different parts of the tree.

So, how about experience groups? They have a hierarchical structure and the depth can vary from group to group. Furthermore, devices can also be assigned to multiple groups at multiple levels, which is not something you have asked for but would be possible to expand to in the future.

The downside of using experience groups is not all parts of the Losant system support querying by advanced device query (and thus experience group) yet; so you could …

Please let us know if that would work for your use case.

Thanks Dylan for your quick reply.
We thought about Experience Groups, but there is a limitation about the number of child groups that a given parent group can have. For instance. in the example above if the number of cities down State 1 is greater than 100 and I try to get all the aggregated data for State 1 using either the Gauge Query or the Time Series nodes, this error occurs:

That’s why we were looking to use System Devices, which we think there is no limitation about the number of nodes within the tree structure.