How to get back _time on mean()?

I am storing lighthouse-data. Each lighthouse-run is a measuring_point and belongs to a measurement. Each measurement has its own unique uuid.

So the structure does look like this:

  • site
    • measurement
      • measurement_point
      • measurement_point
      • measurement_point
    • measurement
      • measurement_point
      • measurement_point
      • measurement_point
  • site
    • measurement
      • measurement_point
      • measurement_point
      • measurement_point
    • measurement
      • measurement_point
      • measurement_point
      • measurement_point

For each measurement_point I am getting the mean()-value like this:

from(bucket: "test")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "lighthouse")
  |> filter(fn: (r) => r["_field"] == "speedindex")
  |> filter(fn: (r) => r["site"] == "1d1a13a3-bb07-3447-a3b7-d8ffcae74045")
  |> group(columns: ["measurement"])
  |> mean()
  |> yield(name: "mean")

Now I saw that if I do that, the records ore “losing” their _time, which leads to this graph:

As you can see: Although the measurements have not been performed at the same time, the values are “stacked” at the same time.

If I render a simple table, I am getting this result: Edit: Need to save this in a new post, as I am a new user so I am not allowed to embed multiple images.

This is fine, but I guess it shows the problem: The mean() value is calculated but there is no thing as a “mean time”. And even if I choose median, which should pick the median value (which would have a time, I guess) the _time-value is missing.

What can I do to get the time back?

Hello @ahoiroman,
You described it perfectly.

This is fine, but I guess it shows the problem: The mean() value is calculated but there is no thing as a “mean time”.
So you can elect to insert a time for when the mean value was calculated. I’d do:

 |> map(fn: (r) => ({ r with _time: now()}))

Selector functions will return the timestamp while aggregators wont. There’s a selector version of the median function:

 |> median(method: "exact_selector")
1 Like