3s Average Power

Hello everyone,

I am pretty noob in programming but I managed to create a (even rather complex) cycling Datafield.

The only thing I am missing is that I would like to display a 3s average power instead of currentPower, but due to my poor programming knowledge I don't know how can I do it.

Is there anyone willing to help and share a piece of code?

I found a couple of similar questions in the forum but they are from several years ago and I am not able to integrate that code in my datafield (VSC throws several errors).

Thank you!

  • Wow they run a real tight ship

    (I was actually originally gonna use a disconnected sensor as an example of a case where Garmin displays "--")

  • So I ended up splitting into two variables, mValuePower3s for computations and mValuePower3sView for the display, so the latter can be given to output "--" when getAverage() returns null.

    In general I am quite happy with the datafield(s) I was able to put together, just one thing: do you know why, compared to the "stock" 3s Power available in the Edge 1050, the values are identical but there is 1 second delay?

  • I wonder how there is only 1 second delay. I would not be surprised if there was 3 second delay

  • compared to the "stock" 3s Power available in the Edge 1050, the values are identical but there is 1 second delay?
    I wonder how there is only 1 second delay. I would not be surprised if there was 3 second delay

    How do you figure? Both the built in field and the example code I posted are supposed to provide a rolling 3 second average, based on real-time power data.

    You understand that right? You are not mistakenly thinking that 4688023 is comparing 3s power in their app to the built-in instant power field? Even if that were the case, it wouldn't really translate to a "3-second delay" per se.

    [1/x]

  • The example code samples power based on Activity.Info.currentPower [updated once per second], calculates the average as soon as there's enough data [3 seconds worth] and updates every second. In fact it can be modified so that it calculates the average immediately [with even 1 second or 2 seconds worth], but that's besides the point.

    Unless the native field has the ability to look 3 seconds in the future, or currentPower is delayed by 3 seconds, I don't see why there would necessarily be a 3 second delay between the native field and CIQ code that presumably calculates rolling average in the same (or similar) way.

    In other words, if the native 3s power field and the CIQ 3s power field both have access to the same instant power data (at the same time), then I don't see any reason for a 3-second delay between the 2.

    [2/x]

  • To be clear, this is how the suggested CIQ code works

    Time (s)

    Activity.Info.currentPower

    CIQ app: 3s rolling data

    CIQ app: 3s rolling average

    0

    110

    {110}

    --

    1

    120

    {110,120}

    --

    2

    125

    {110,120,125}

    (110+120+125) / 3 = 118.33

    3

    140

    {120,125,140}

    128.33

    4

    150

    {125,140,150}

    138.33

    The only way I can think of for the native 3s rolling average to be 3 seconds ahead of the CIQ 3s average would be for Activity.Info.currentPower to be needlessly [and implausibly] delayed by 3s.

    And the only ways I can think of for native 3s average to be 3 seconds behind the CIQ 3s average would be:

    - if the native average had a really strange algorithm for calculating "rolling average".

    or

    - Activity.Info.currentPower was actually 3 seconds ahead of the native field [which is probably not the case]

    In general I am quite happy with the datafield(s) I was able to put together, just one thing: do you know why, compared to the "stock" 3s Power available in the Edge 1050, the values are identical but there is 1 second delay?

    If you also display Activity.Info.currentPower in your data field, is it synchronized with the native instant power field?

    Or is there a 1-second delay? If there's a 1 second delay between native current power and built-in current power, then any values calculated from current power would have the same delay.

    If there's no delay between native and CIQ current power, but still a delay between native 3s power and your app's 3s power, that's harder to explain:

    - If native 3s power is 1s *behind* your app (which seems unlikely), then that might be explained by Garmin's rolling average algorithm perhaps being a bit strange in that it shows the average for the previous 3 seconds *not including the current second*.

    - If native 3s power is 1s *ahead* of your app (which is what I thought you meant in the first place), then I don't really have a way to explain that

  • If you also display Activity.Info.currentPower in your data field, is it synchronized with the native instant power field?

    Or is there a 1-second delay? If there's a 1 second delay between native current power and built-in current power, then any values calculated from current power would have the same delay.

    I must check this out, but yeah my first guess would also be that native has a 1s faster access to the data than compute()

  • I must check this out, but yeah my first guess would also be that native has a 1s faster access to the data than compute()

    Yeah I *think* I've seen a native field being 1 second ahead of the (supposedly) same Activity.Info field, but kind of depends.

    For example, I think Activity.Info.timerTime is *usually* sync'd with the built-in Timer field, but at least on older, slower watches, there could be some cases when there was a 1 second lag.