Use a calculated mean and stddev in map

I’m trying to calculated a z-score to some dates in influxql. I have my dayStats, which consist of {_time, _value}, and I’m trying to do something like this:

// some code above that generates dayStats

groupMean = dayStats |> mean()
groupStddev = dayStats |> stddev()

dayStats
  |> map( fn : (r)=>({r with
    "z": ((r._value - groupMean[0][0]._value) / groupStddev[0][0]._value)
  }))

The problem is I cannot persuade InfluxQL to convert my groupMean and groupStddev tables into a single float that I can subtract from my r._value for each record: my groupMean[0][0]._value attempt fails.
Any help much appreciated, best,
Craig

I worked it out:


groupMean = dayStats |> mean() |> findColumn(fn: (key)=> true, column: "_value")
groupStddev = dayStats |> stddev() |> findColumn(fn: (key)=> true, column: "_value")

dayStats
  |> map( fn : (r)=>({r with
    "z": (r._value - groupMean[0]) / groupStddev[0]
  }))

alternatively

groupMean = dayStats |> mean() |> findRecord(fn: (key)=> true, idx: 0)
groupStddev = dayStats |> stddev() |> findRecord(fn: (key)=> true, idx: 0)

dayStats
  |> map( fn : (r)=>({r with
    "z": (r._value - groupMean._value) / groupStddev._value
  }))

Hello @craigmj,
Thank you for sharing your solution with the community! We really appreciate it.