Discrepancy in Custom Activity Fields Across Intervals of Identical Duration

Hi,

I’m working on computing the average pace for a specific run test session, using the same time intervals selected in the activity. The goal is to plot these averages on the fitness page and to reduce the manual effort required to identify intervals.

However, I’ve encountered a discrepancy where the average pace computed from my activity field does not match the selected interval average pace. Conversely, when calculating average power, the results align perfectly.

See below:

Here is the code I’m using for the custom activity field to compute pace:

{
  // Check if the activity name is "SRT-RPE"
  if (activity.name === "SRT-RPE") {
    // Access the relevant data streams
    velocitySmooth = streams.get("velocity_smooth").data;
    columnValues = streams.get("time").data; // Replace with your actual column name

    sumVelocity = 0;
    count = 0;

    // Loop through the data
    for (i = 0; i < velocitySmooth.length; i++) {
      if (activity.type === "Run" && columnValues[i] >= 90 && columnValues[i] <= 120) {
        if (typeof velocitySmooth[i] === "number" && velocitySmooth[i] > 0) {
          sumVelocity += velocitySmooth[i];
          count++;
        }
      }
    }

    // Calculate mean velocity (meters per second)
    meanVelocity = (count > 0) ? sumVelocity / count : 0;

    // Log the mean velocity in meters per second for debugging or display purposes
    console.log(`Mean velocity: ${meanVelocity.toFixed(2)} meters per second`);

    // Assign the mean velocity in meters per second to the field
    field.value = meanVelocity;
    meanVelocity
  } else {
    // Handle the case where the activity name is not "SRT-RPE"
    field.value = null; // or some other default value
    null
  }
}

What could explain the discrepancy in the mean pace?
Thanks!

Not sure if this is the only thing responsible, but the above is a 31sec time-span and not a 30sec one. You are dividing by 30, which makes your result bigger then what it should be. Guess that’s what causes the discrepancy.

Hi @MedTechCD,

Thank you for your response. You’re right about the 31sec time-span. Even when I adjust to columnValues[i] >= 90 && columnValues[i] < 120, the results are still quite similar. For my mean watts calculation, the values match those in the intervals selection.

Could it be that the average pace is calculated using a different stream than velocity_smooth in the intervals?

Could be End-distance minus Start-distance divided by elapsed time. Not sure though…

It’s getting closer!

If you take the 104m in 30s and convert to min/km you get the 4:48 min/km.
Are you taking the correct time references? 10 sec in is the 11th value because the first value is at 0.

Thanks for your help, @MedTechCD! I think I have a final working solution. I’m getting the exact same pace or a difference of just ±1 second, depending on the case!