Happy New Year to everyone.
I have a Flux query where I am monitoring the feedrate of a machine. If the feedrate is >= 1, then it’s true
, and if not, it’s false
. Here is the query and a snippet of the ~14,000 record output:
from(bucket: "AMPdata")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "SingleRotaryFurnaceElementData")
|> filter(fn: (r) => r["EquipNumber"] == "8")
|> filter(fn: (r) => r["MeasType"] == "actual")
|> filter(fn: (r) => r["_field"] == "Feedrate")
|> map(fn: (r) => ({ r with _value: if r._value >= 1 then
"true"
else
"false",
}),
)
|> yield(name: "Running or Not Running")
So far, so good. Next, I put these 3 lines just before the yield()
function and I get the total number of true
and false
records.
|> stateDuration(fn: (r) => r._value == "true")
|> group(columns: ["_value"])
|> count(column: "stateDuration")
Note that in the above stateDuration predicate function, it does not matter if I use r._value == “true” or r._value == “false”. The resulting output is the same.
And this is where I am getting stuck. What I would like to do is have a single table showing 3 values:
total number of true readings
total number of false readings
total number of true and false readings (i.e. total number or records)
I tried various techniques recommended in this thread, but no dice.
A second issue is that I want to do some basic math on the above output (multiply 1998 by 0.05). When I use a simple map
function like this:
|> map(fn: (r) => ({r with NewValue: r.stateDuration * 0.05}))
I get this error:
map: type conflict: float != int
Ultimately, I am trying to calculate the % of time the feedrate is >= 1. Maybe my above functions are not the right approach.
Any help is much appreciated.