class XDataField extends Ui.SimpleDataField
{
hidden var _M_seconds;
hidden var _M_average;
function initialize() {
SimpleDataField.initialize();
_M_seconds = 0;
}
function compute(info) {
if (info.currentPower == null) {
return null;
}
++_M_seconds;
if (_M_average == null) {
_M_average = info.currentPower;
}
else {
_M_average = (_M_average * (_M_seconds - 1)) + info.currentPower) / (_M_seconds * 1.0);
}
return _M_average.toNumber();
}
}
Unfortunately, averagePower is an integer. If this were a floating point then it would be super easy... you just capture the averagePower at the start of the "interval". At the end of the lap or time period or condition, you'd simply need to do some simple math on the change in averagePower during that time duration. And you could quickly figure out the averagePower during that time interval. But because "averagePower" is an integer, that won't work... the value is too granular to do it that way.