Server side data model for scripts

I have added a new stats object and will deploy Monday AM (GMT+2). So now you can do this sort of thing to compute a 30 second power stream:

{
  let watts = icu.streams.fixed_watts
  let w30 = icu.stats.calcMovingAvg(watts, 30)
  for (let i = 0; i < data.length; i++) data[i] = Math.floor(w30[i] + 0.5)
}

Note that the second argument is the number of points to use for the window, not seconds. If you want to cater for activities with data points more than 1 second apart:

let w30 = icu.stats.calcMovingAvg(watts, 30 / (activity.icu_median_time_delta || 1))
// activity.icu_median_time_delta is the median time between data ticks

There is also calcCenteredMovingAvg which is what is usually used in the Intervals.icu web app.

Nulls and undefined values are treated as zero for both average calcs.

1 Like