Computed activity fields

It’s JavaScript but running in a sandbox on the server.
I found the Fundamentals part of this tutorial very useful to start ‘reading’ existing scripts:

2 Likes

You can comment or remove this line at the end to always return a value, not only when time between percentages is the most time spent in the workout:

I think the HR curve goes the other way, I mean, in your screenshot, you have spent 26min above your 85.1% of HRmax.

Edit: After reading you again, you understand perfectly the HR curve, just need to remove the condition I’ve told you above.

1 Like

Perfect thank you! It’s working as intended. I need to learn JS :wink::grinning:

1 Like

Quick follow up. Do I need to “re analyse” all my activities for the value to show up in each activity?

I’m afraid so. For me is so bad because I have several workouts planned that not match with the actual activity, so I have to go back to drag n’ drop again. I also have to block the intervals on each activity once again…

Perhaps we can ask for a feature request to @david to have a new action for all the activities to recalculate only custom fields.

2 Likes

Hey, I am studying my running “Flight Time” for a good build, however my watch and strap combo don’t show me this information. I think I can get it removing the ground contact time (GCT) from the time I spend between steps (getting this from the steps per minute). This is the formula I have come out:

(60 / (activity.average_cadence * 2) * 1000) - activity.GCT

I have created a public custom activity field to test it (it uses the GCT custom field that I get from Garmin fit field). The values I get make sense to me, do you people think it is correct?

It can be calculated by running the script per activity too. But that is only good news if you need just to do a couple of them. Then it saves you the work of reworking all intervals.

The re-analyse option on the activity list view has a checkbox to keep existing intervals.

You can also get this for a range of activities from the API: Swagger UI

Example: https://intervals.icu/api/v1/athlete/2049151/activity-power-curves?oldest=2022-06-27T00:00:00&newest=2023-02-15T23:59:59&secs=120,240,480

1 Like

Wow thanks I missed that one. Will have to give it a go.

Works perfectly. A quick test in R gives this :slight_smile: (running/stryd Power, I wish I could ride like that!)

1 Like

Hi All,

I imagine this is a really basic question but i just don’t understand why this isnt working. Any help for a complete java beginner much appreciated!!

I am recording a field called “Bloodglucose” to my FIT file using the xdrip+ add in on my garmin watch.

The field is called “Bloodglucose” and i can see this when i open the file in fitfileviewer. I am trying to follow the above guidance in order to create fields for a) time spent below 4, b)time spent above 10, c) time spent in range. But im struggling to access the data at all using the below:

//limits
Low_limit=4
High_limit=10
//get streams
Blood_glucose= streams.get(“Bloodglucose”).data

//calculate time spent
let time_low=0
for(let i=0; i<Blood_glucose.length; i++) {
let t=Blood_glucose[i]
if (t<=Low_limit) time_low +=1
}

But i keep getting the error “Invalid stream type [Bloodglucose]” - but this steam definitely exists when i view the FIT file in fitfileviewer. Any ideas what i’m doing wrong?

Thanks for the help,
Rhys

“Custom Streams”, i.e. those not currently in the list (can inspect network activity to see ones available - see screenshot) are not yet supported.

Thats a shame - thanks for the info though!

What are the units for that field?

Units i use (and commonly used in Europe) are mmol/L.

(The US typically use mg/dL)

I have added support for “Bloodglucose”. You need to do Actions → Reprocess File to get the new trace. Then click “Charts” to add it.

3 Likes

Hi David - this is fantastic! Really appreciate this!

1 Like

Hi David,

Just coming back to this. Your example works great, but when I try to pass a fatigue value in the URL I get a 422 error Invalid fatigue. Any ideas? As an example I’m just passing the value 3000.

I can’t get this to work in R or using swagger.

Cheers

John

You need to do fatigue=kj0 or fatigue=kj1 to get fatigued power curves for the athlete. These correspond to whatever has been configured on the /power page for the athlete:

The payload does include the actual kJ values.

1 Like

Ah. thanks I get it now. Works perfectly (and agrees with my own calcs :slight_smile: )

1 Like