Average Lap Power

How would I calculate average power over the course of a lap? Does populating an array with values in one second intervals create memory issues?
  • If you want overall average power or lap power, where you don't know how many samples you need. Maintaining a long array of samples isn't going to for this. You need to use the second technique I showed in our other thread on this topic, but slightly modified to keep track of the number of seconds that have elapsed.

    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();
    }
    }


    As with the other thread, you may have to implement the timer callback functions (onTimerStop(), onTimerPause(), onTimerReset()) to finish this, but the above should be a good start.

    Travis
  • Wow, you're super fast. Thank you! Really appreciate the code- It was enough to get me on track.
  • 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.