Im saving the data from my gas meter to a database. Every 30mins im getting the current meter reading.
When there is no change i only want to keep the first entry
for example:
#1 1:00 8738m²
#2 1:30 8740m²
#3 2:00 8740m²
#4 2:30 8740m²
#5 3:00 8744m²
in this case i want to use a task job but i dont want to keep #3 and #4.
how can i do this?
I found this as a suggestion from another user
from(bucket: "sensors")
# Usual range and filter.
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._field == "temp")
# Copy "_value" column so that the original won't get lost.
|> duplicate(column: "_value", as: "diff")
# Convert "diff"-column to the difference from pervious row.
|> difference(
columns: ["diff"],
keepFirst: true # Stores null in first "diff"-column.
)
# Keep the first null-valued row; it is the initial value,
# and all other rows with a change (diff != 0).
|> filter(fn: (r) => not exists r.diff or r.diff != 0)
1 Like