Hi folks,
very new to all this and have a basic, I presume, question…
I am using code in Node-Red to dynamically build Flux queries and have gone with a simplistic approach using an individual query and thus table output for each dataset I am passing to the graph node.
My code generates this … ( This is two datasets but could be 1-6 )
from(bucket: "HydroDB")
|> range(start: 1747690665, stop: 1750282665)
|> filter(fn: (r) => r["_field"] == "Grid_Watts")
|> aggregateWindow(every: 1800s, fn: mean, createEmpty: false)
|> map(fn: (r) => ({r with _value: r._value * 1.0}))
|> yield(name: "Grid_Watts-mean X 1 [ 30M ]")
from(bucket: "HydroDB")
|> range(start: 1747690665, stop: 1750282665)
|> filter(fn: (r) => r["_field"] == "Inv_Watts")
|> aggregateWindow(every: 1800s, fn: mean, createEmpty: false)
|> map(fn: (r) => ({r with _value: r._value * 1.0}))
|> yield(name: "Inv_Watts-mean X 1 [ 30M ]")
Since I wrote this I have realised that the ‘from’ and ‘range’ which are always common, could be called first and dropped into a variable that is subsequently used to drop a table/reference into both ‘filters’ (Sorry not sure what the proper terminology is)
Aside from the comment above, that is there anything wrong with this approach, query per graph line effectively, or my code in general for that matter.
This is literally my first attempt ant anything useful and I am, at best, muddling through.
My Node-Red code is, and has to be, recursive, because the number of fields and aggregate functions change, based on user input from a form. If structuring Flux this way is a poor plan for some reason, I would need to know how to generate better Flux that is still practical to build dynamically, and for that I would need to understand Flux
Feel free to be direct, I am here to learn, and well aware that there is much of that to be done!
Any and all help will be much apriciated.
If anyone is interested in code that generates this, one query block per object in an array, I will happily post it but it is likely off topic…