Replies: 1 comment 1 reply
-
Good one @gdiana. Here is an another version of JSONata if anyone interested with the consideration of dynamic keys $map($, function($v, $index, $vv){
$merge([
$map($keys($vv),function($key){
{
$key :
$key = "Timestamp" ?
$number($lookup($vv[$index],$key)) :
$index = 0 ? null : $number($lookup($vv[$index],$key)) - $number($lookup($vv[$index -1],$key))
}
})
])
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Quite often many electrical meters of energy systems provide accumulative data which just shows a straight incremental line, when one desires to see the actual load profile or differential / incremental energy usage per sample time.
Many low cost meters do not provide incremental data but only accumulative data and then one has to try and use fancy queries to try and get the actual load profile etc using say Modbus or MQTT.
One may do this in ones database query but if JSON data is available then one may use the JSONATA parser provided in the INFINITY DATA SOURCE. This is far more powerful, easier and flexible to do rather than trying to do this within UQL.
So this is what we get using accumulative data
and by using JSONATA we get
This may be achieved by using the following JSONATA script on the following json data structure
The JSONATA map function allows one to parse the json data ($v) with index ($i) and a static copy of the json data ($a).
Using the copy one can access the differential data, but which requires one to retrieve energy data one sample earlier and one sample later for any desired time period. ie required time period ie t(n-1) ----- t(N+1) opposed to t(n)--- T(N). If the sample period is say 30min then it must start one sample before the start time and end one sample after.
The $ is the Json path to the energy usage data. In this case it is just $ as it is at the top
If one tries to do the above using $v instead of $a one gets an error as the $v data is changed or dynamic whereas its copy $a remains static, thereby allowing one to subtract the next sample from the previous sample and store the difference in $v.
Note I have used
Phase
' as this must be used when any variable has a space in its name such asPhase A
The result is that one now gets graphs which are far more meaningful.
Hope this helps a little.
Beta Was this translation helpful? Give feedback.
All reactions