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