KSPR
KSPR

Reputation: 2375

Show Timestamp of first Occurence

I have a db of hydrological data.

I wrote a cell in the influxdata panel to find the first occurrence where the measurement is above 17°.

enter image description here

But now I don't want to display the value but the timestamp in the cell when the first occurence was:

from(bucket: "hydroAPI")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "hydro")
  |> filter(fn: (r) => r["_field"] == "temperature")
  |> filter(fn: (r) => r["loc"] == "XXXX")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> filter(fn: (r) => r._value > 17 )
  |> first()
  |> yield(name: "mean")

This code is working, but it shows just the value. I want to see the time. Is this possible?

Upvotes: 0

Views: 399

Answers (1)

mhall119
mhall119

Reputation: 577

The Single Stat visualization will always display what's in the _value column, so you need to replace that with your time.

Try adding this just before your yield():

  |> drop(columns: ["_value"])
  |> rename(columns: {_time: "_value"})
  |> toString()

The first line drops the _value column so that you can rename the _time column in the second line. Since you probably don't want the timestamp in nanoseconds, the toString() on the third line will convert it into a human-readable form.

Upvotes: 2

Related Questions