I’m currently working on a query, which will output the losses of some machinery. I’m using the difference of the input power and the output power to calculate the loss. I want to get the losses of multiple machines and add them all together. Here is what I have:
from(bucket: "someBucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
...
|> filter(fn: (r) => r["name"] == "machine1input" or r["name"] == "machine1output")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
// get positive values
|> map(fn: (r) => ({ r with _value: math.abs(x: r._value) }))
// group them by each timestamp
|> group(columns: ["_time"], mode:"by")
// get the difference
|> difference(nonNegative: false, columns: ["_value"])
// use only positive values
|> map(fn: (r) => ({ r with _value: math.abs(x: r._value) }))
// group them by "name" which does nothing in this step, but is needed
// to know which difference corresponds to which machine later on
|> group(columns: ["name"], mode: "by")
|> yield(name: "diff_machine1")
from(bucket: "someBucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
...
|> filter(fn: (r) => r["name"] == "machine2input" or r["name"] == "machine2output")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> map(fn: (r) => ({ r with _value: math.abs(x: r._value) }))
|> group(columns: ["_time"], mode:"by")
|> difference(nonNegative: false, columns: ["_value"])
|> map(fn: (r) => ({ r with _value: math.abs(x: r._value) }))
|> group(columns: ["name"], mode: "by")
|> yield(name: "diff_machine2")
...
In total, I am calculating the losses of twelve machines. In the UI using the table visualization, I can see all the tables and entries of all the different losses. Now the tricky part:
I want to pick up all the Data I yielded and execute some functions on it. something like
currentStreamedData
|> group(columns: ["_time"], mode: "by")
// and so on
but I haven’t found any information on how to do something like this. My only other idea would be saving all the tables in variables and joining them together one by one, but I think there must be a more elegant way to do this.
Appreciate any help!