Computed activity fields

Intervals.icu now supports custom activity fields either manually captured, computed using JavaScript code or read from FIT files. This is the first giant leap towards a programmable Intervals.icu!

You can click the play button to execute your script in the context of the selected activity to test.

The script has access to the following objects:

  • activity: the activity being analysed
  • athlete: for the activity
  • streams: the power, heart rate and so on traces for the activity
  • sportSettings: for the sport of the activity
  • field: the field being evaluated
  • icu: Provides access to other things loaded on demand

The icu object provides:

  • wellness: for the day of the activity
  • powerCurve (power duration curve)
  • powerCurveFatigued0 (power curve after some KJ of work done)
  • powerCurveFatigued1 (power curve after more KJ of work done)
  • hrCurve (heart rate duration curve)
  • paceCurve (distance vs time curve)
  • gapCurve (distance vs time using gradient adjusted pace)

The last expression in the script is the value stored for the field. The script can also update many fields on the activity which are also saved (e.g. icu_training_load for a custom load calc).

{
  let v = .. custom training load calc ..
  activity.icu_training_load = v
  v
}

Variables are implicitly declared. Don’t use ‘let’ or ‘var’ etc… The scrips for all fields for an activity share the same sandbox this fails if they declare variables.

If you do need to declare things wrap the script in a block:

{
   let factor = 2
   activity.average_stride * factor
}

The JavaScript code runs in a sandbox on the server when the activity is analysed. If anyone figures out how to escape that sandbox I want to know first!

The data model is here:

This post has more info on custom activity fields:

Similar functionality is available for interval fields:

You can plot custom activity fields on the fitness and compare pages. If there are multiple activities on the same day then values are combined according to the aggregate setting on the description tab:

You can map custom activity fields to session fields from the FIT file:

You can write scripts that directly process all the fit file messages:

Activity (and custom fields in general) can be converted before they are displayed. Fields with values in meters/second, meters and seconds are supported:

37 Likes

This feels huge. Super impressive. Thanks for pushing this platform so much @david

Can’t wait to see the use cases people develop. Man I need to learn to code!

1 Like

This is awesome. Are computed field then available in a downloaded FIT file?

1 Like

And once again a new Playground :rofl:
This is way more then expected and extends the possibilities by a giant leap.

Hi! Amazing work! I’ve added a few public fields for measuring core temperature. Although, they work fine in the activity field creator window but does not return any value in the view for the workout.
image


Definitively a game changing upgrade!!!
Many thanks.
@david I wonder if you plan to extend this to charts. It would be awesome to allow plotting processed data series (X, Y) in the current custom charts :pray:

3 Likes

I have documented the data model (sort of … needs more comments):

Yes I am going to do that.

You need to re-analyse the activity to compute values for newly added fields. Did you do that?

I just added that.

4 Likes

Yes, many times! No changes :slight_smile:

Curious… these computed values in the FIT file, what are they stored as? Developer Fields?

1 Like

Can you point me at one of your activities with core temp data so I can have a look. Tx.

Yes developer fields. The name matches code of the field and they are float32’s or string’s.

1 Like

Can you check this activity? It seems like it does only calculate one of the custom fields. If I change the script to so it looks exactly like another one, the field will calculate that already has a “0” in it.

https://intervals.icu/activities/i8771586

Tx. I know whats wrong and am working on a fix. The scripts for an activity all run in the same sandbox instance so if you declare a variable with “let” and another script does the same, the 2nd script fails. You can workaround this by removing let:

temp_threshold = 38.4

Instead of: let temp_threshold = 38.4

1 Like

Great!! It solved all the metrics :smiley:

This is brilliant, thanks so much. I’ve added in running cadence (just a 2x of average_cadence) and running efficiency index (metres per minute per watt) as public.

Excited to see these added to fitness charts as well, I’ve actually been hacking the running efficiency index via wellness metrics :grimacing:

Also wondering – and this may already be true – will it be possible to write data to the stream as well? This would allow charting within the activity, which would be amazing.

4 Likes

Tx. I am going to be extending this to all parts of Intervals.icu including custom streams as soon as I can. I will be sorting out plotting custom activity fields on the fitness and compare pages today.

If anyone does want to declare stuff in the script wrap the body in a block:

{
   let factor = 2
   activity.average_stride * factor
}
1 Like

This functionality has been extended to interval fields:

1 Like

You can now plot custom activity fields on the fitness and compare pages. If there are multiple activities on the same day then values are combined according to the aggregate setting on the description tab:

Choose sum, min, max or average.

1 Like

How can we add these custom fields in the fitness page? When I try to add a plot I can’t find any custom fields

They are showing up for me at the bottom of the list. Remember that if you are viewing another athlete you need to add your fields to them first by going to one of their activities, clicking “Custom” and using the search button.