Hi, I’m monitoring the temperatur of a compressor. I know when it is ON or OFF and, of course, his temperature. What I would like to get is each max when it’s ON and each min when it is OFF.
I could achieve a lot with that script below, but the given temperatures are when the system switches ON or OFF, not the min/max somewhere in between. Any advices would be helpfull. Thanks
span = -8h
raw = from(bucket: “compres”)
|> range(start: span)
|> filter(fn: (r) =>
(r[“_field”] == “ComprON”))
|> aggregateWindow(every: 1s, fn: first)
|> fill(column: “_value”, usePrevious: true)
|> map(fn: (r) =>
({r with _level: if r._value > 0.0 then “swON” else “swOFF”}))
|> keep(columns: [“_measurement”, “_time”, “_level”])
tempe = from(bucket: “compres”)
|> range(start: span)
|> filter(fn: (r) =>
(r[“_field”] == “TempKomp”))
|> aggregateWindow(every: 1s, fn: mean)
|> fill(column: “_value”, usePrevious: true)
|> map(fn: (r) =>
({r with Tkomp: r._value}))
|> keep(columns: [“_measurement”, “_time”, “Tkomp”])
ON = raw
|> monitor.stateChanges(fromLevel: “swOFF”, toLevel: “swON”)
OFF = raw
|> monitor.stateChanges(fromLevel: “swON”, toLevel: “swOFF”)
over = union(tables: [ON, OFF, tempe])
|> group(columns: [“_time”], mode: “by”)
|> sort(columns: [“_time”])
|> fill(column: “Tkomp”, usePrevious: true)
|> tail(n: 1)
|> group()
|> filter(fn: (r) =>
(exists r._level))
temp = over
|> elapsed(unit: 1s, timeColumn: “_time”, columnName: “tcycle”)