Duration above X watts for a ride

Is it possible to get the time which was spent above a certain power target for a single ride?
Let’s say I want to see the time above 300W.

Usually my zones don’t show want I want to see e.g. when one zone is from 280-310W and I’m interested to see the time above 300W.
I also don’t want to change my zone every time as I’m interested on one day for time above 300W, on another above 400W…
It would be great to have a flexible option for such an anlysis.

Shouldn’t be to difficult with a Custom Activity Field.
Get the power stream, increase a counter for every value above the set value.

You can do this with a single custom activity field with a value specified within the script.

Or you can do two custom fields, where one is the calculation and the other sets the target value. The following code snippet for the calculation, and then also add a custom field with name TargetWatts to set the target.

You need to re-analyze after changing the target value.

watts = streams.get("fixed_watts").data
target = activity.customFields?.TargetWatts ?? activity.icu_ftp
console.log("target", target)
time_above = 0
for (let i = 0; i < watts.length; i++) {
   w = watts[i]
  if (w >= target) time_above += 1
}

time_above/60
4 Likes

That’s cool. But

  1. There is a way to count only when the target is exceeded for at least X consecutive seconds?
  2. If that’s possible, can we also count how many times I hit X watts for at least 5 seconds? For example, I held 1000 watts for 5 seconds, three times during a ride…

You could do anything … :smiley:

{
watts = streams.get("fixed_watts").data;
target = activity.customFields?.TargetWatts ?? activity.icu_ftp;
console.log("target", target);

let time_above = 0;
let consecutive_time = 0;
let threshold = 5; // Minimum duration (seconds) above target
let occurrences = 0; 
let specific_watt = 1000; // Wattage to track

for (let i = 0; i < watts.length; i++) {
    let w = watts[i];

    if (w >= target) {
        consecutive_time += 1;
    } else {
        // If streak ends, check if it was long enough
        if (consecutive_time >= threshold) {
            time_above += consecutive_time;
        }
        consecutive_time = 0; // Reset counter
    }

    // Tracking occurrences of a specific wattage being held for at least 5 sec
    if (w >= specific_watt) {
        consecutive_time += 1;
    } else {
        if (consecutive_time >= threshold) {
            occurrences += 1;
        }
        consecutive_time = 0; // Reset counter
    }
}

// Final check in case the ride ends with an active streak
if (consecutive_time >= threshold) {
    time_above += consecutive_time;
    occurrences += 1;
}

console.log("Total time above target:", time_above / 60, "minutes");
console.log("Occurrences of holding", specific_watt, "watts for at least", threshold, "seconds:", occurrences);
}
2 Likes

Whoa, that’s awesome. I always used to look at time above xxx watts in Golden Cheetah, but after they changed the UI in 3.5 or 3.6 I couldn’t figure out how to do it anymore.

Now I just need to learn how to use your code :upside_down_face:

Does it help? You can find it in “power” tab, then “activity charts”:


2 Likes

Thank you very much for all your help. That’s awesome!

@Gabriel_Vargas this chart is very handy!
@David_R I managed to include the two custom fields (first time I did it :slight_smile: ). However the minutes are x10. In my example the time above is 71 minutes where it was 7 minutes. Do you know what I did wrong?



1 Like

@Gabriel_Vargas
22-05-2025_16-44-31
I fixed it. I had to convert it to “x/10”.

This is so useful, thank you :pray: