# Custom interval fields

**URL:** <https://forum.intervals.icu/t/custom-interval-fields/25942>\
**Category:** Uncategorized\
**Created:** [27 December 2022 09:54 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942 "2022-12-27T09:54:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [27 December 2022 09:54 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/1 "2022-12-27T09:54:04Z")

</div>

Intervals.icu now supports custom fields for intervals. You can enter the values manually (e.g. from a test of some kind) or compute them using JavaScript code. Click “Fields” on the activity timeline page and then “Add Field” to create a new field or search for an existing field:

 ![Screen Shot 2022-12-26 at 15.44.04](https://forum.intervals.icu/uploads/default/original/3X/e/d/ed7ab957e684fe47290b7ad22577558bff740daf.png)

Note that the fields are specific to the athlete being edited. So if you are coaching people, create fields for yourself and then use the search button to add copies to your athletes.

 ![Screen Shot 2022-12-27 at 11.45.22](https://forum.intervals.icu/uploads/default/original/3X/7/7/77bab1141ef734e9ac612afb2be64a6f3cfdfefe.png)

You can click the values to edit:

 ![Screen Shot 2022-12-27 at 11.58.18](https://forum.intervals.icu/uploads/default/original/3X/2/3/2372ddbc18fce0476347c0998585799212eec952.png)

Sample script for distance per stroke:

```
interval.average_stride * 2

```

The script has access to the following objects:

- interval: the interval being updated
- field: the field being evaluated
- icu: object that provides access to the activity, athlete, wellness etc.

The last expression in the script is the value stored for the field.

Variables are implicitly declared. Don’t use ‘let’ or ‘var’ etc.. The script is invoked once for each interval using the same sandbox and this fails if it declares fields.

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

```auto
{
   activity.average_stride * 2
}

```

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:

> [@Code completion for Javascript in Intervals.icu](https://forum.intervals.icu/t/code-completion-for-javascript-in-intervals-icu/98300):
>
> You can now get code completion in your favourite editor when editing Javascript for Intervals.icu custom fields, streams, charts etc.. VS Code: IntelliJ IDEA: The instructions are here: [https://www.npmjs.com/package/@intervals-icu/js-data-model](https://www.npmjs.com/package/@intervals-icu/js-data-model) For info on the JS extension points:

The custom interval fields are also available as columns on the activity data page. You can edit the values on the grid:

 ![Screen Shot 2022-12-27 at 11.56.22](https://forum.intervals.icu/uploads/default/original/3X/3/3/338d94ef08579ea6d0432afb69cb82c3ecbce6e3.jpeg)

---

<div class="post-metadata">

**Author:** ![Tito](https://forum.intervals.icu/user_avatar/forum.intervals.icu/tito/32/38208_2.png) [@Tito](https://forum.intervals.icu/u/Tito)\
**Post date:** [27 December 2022 16:03 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/2 "2022-12-27T16:03:53Z")

</div>

This is awesome work!!! Thank you David!

---

<div class="post-metadata">

**Author:** ![theo](https://forum.intervals.icu/user_avatar/forum.intervals.icu/theo/32/29273_2.png) [@theo](https://forum.intervals.icu/u/theo)\
**Post date:** [27 December 2022 19:17 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/3 "2022-12-27T19:17:40Z")

</div>

This is amazing 😍

Having custom code is setting intervals.icu apart from the competition.

Potentially there could be a forum thread with a library of useful code.

---

<div class="post-metadata">

**Author:** ![thomas\_b](https://forum.intervals.icu/user_avatar/forum.intervals.icu/thomas_b/32/34745_2.png) [@thomas\_b](https://forum.intervals.icu/u/thomas_b)\
**Post date:** [28 December 2022 09:38 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/4 "2022-12-28T09:38:10Z")

</div>

Thank you, looks awesome !

Is “VAM” an available stream ?

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [28 December 2022 09:59 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/5 "2022-12-28T09:59:48Z")

</div>

No you would need to compute that from “fixed\_altitude” (altitude with elevation correction applied if needed and gaps interpolated).

---

<div class="post-metadata">

**Author:** ![Calum\_Young](https://forum.intervals.icu/user_avatar/forum.intervals.icu/calum_young/32/27333_2.png) [@Calum\_Young](https://forum.intervals.icu/u/Calum_Young)\
**Post date:** [25 January 2023 21:49 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/6 "2023-01-25T21:49:54Z")

</div>

Hi @david,

Is it possible to add core\_temperature as a field? If so, what script would I need to add to get this to work?

Thanks

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [26 January 2023 04:24 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/7 "2023-01-26T04:24:28Z")

</div>

Sure. I added a new public interval field “Average Core Temp” and added that to your interval fields. You should see it in the “Fields” list. The script looks like this:

```auto
temp = streams.get("core_temperature").data
tot = 0
c = 0
for (let i = interval.start_index; i < interval.end_index; i++) {
  let v = temp[i]
  if (v) {
    tot += v
    ++c
  }
}

c ? tot/c : null

```

I also added “Max Core Temp” if that is what you are after:

```auto
temp = streams.get("core_temperature").data
max = 0
for (let i = interval.start_index; i < interval.end_index; i++) {
  let v = temp[i]
  if (v > max) max = v
}

max > 0 ? max : null

```

---

<div class="post-metadata">

**Author:** ![Marco\_Derix](https://forum.intervals.icu/user_avatar/forum.intervals.icu/marco_derix/32/34228_2.png) [@Marco\_Derix](https://forum.intervals.icu/u/Marco_Derix)\
**Post date:** [26 January 2023 18:37 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/8 "2023-01-26T18:37:56Z")

</div>

Has anyone figured out if this can be used to get di2 gear info ?

---

<div class="post-metadata">

**Author:** ![raviabram](https://forum.intervals.icu/user_avatar/forum.intervals.icu/raviabram/32/27210_2.png) [@raviabram](https://forum.intervals.icu/u/raviabram)\
**Post date:** [9 February 2023 20:06 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/9 "2023-02-09T20:06:21Z")

</div>

Hi @david  
I have created Interval Field for swimming: “Interval Swim Stroke” with select list. Is it possible to map fit file for this specific stroke type ? I can find it in file at the end of each inerval:

 ![image](https://forum.intervals.icu/uploads/default/original/3X/f/3/f368c97e5035fb9d4751caf537a06bdab395c1f5.png)

If so, what script should I add to get this to work?

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [12 February 2023 08:33 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/10 "2023-02-12T08:33:04Z")

</div>

That is on the length messages and there isn’t a way to get data out of those onto the intervals yet.

---

<div class="post-metadata">

**Author:** ![broooo](https://forum.intervals.icu/user_avatar/forum.intervals.icu/broooo/32/93398_2.png) [@broooo](https://forum.intervals.icu/u/broooo)\
**Post date:** [6 March 2023 06:17 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/11 "2023-03-06T06:17:14Z")

</div>

I have made custom fields called “Running time” and “Running time %”, similar to the run/walk detection in Garmin. Thought some of you might like it 🙂

There are fields both for the activity as a whole, and for each interval.

Here’s what it looks like:

 ![Screenshot 2023-03-05 at 21-57-10 Intervals.icu](https://forum.intervals.icu/uploads/default/original/3X/6/3/632802c8ba05f005da9240d1a0b997a60e4b23c5.png)

It defines running as anything over a 60 cadence, and walking as anything over a 10 cadence. It will also ignore any data during the warmup and cooldown periods defined for your running activity.

The running time calculated is usually a little lower than the one shown by Garmin - not sure why but its usually \<1m of difference.

---

<div class="post-metadata">

**Author:** ![Andrew\_Bloom](https://forum.intervals.icu/user_avatar/forum.intervals.icu/andrew_bloom/32/32077_2.png) [@Andrew\_Bloom](https://forum.intervals.icu/u/Andrew_Bloom)\
**Post date:** [7 April 2023 14:09 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/12 "2023-04-07T14:09:55Z")

</div>

@david I’m trying to extract Stryd average Vertical Oscillation out of fit file data for my intervals and have been unsuccessful so far. Any advice?

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [8 April 2023 13:43 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/13 "2023-04-08T13:43:08Z")

</div>

You will be able to do that when I finally find time to complete support for mapping custom fields from records to activity traces. You will need to create a trace for it and then a custom activity/interval field to calculate the average.

---

<div class="post-metadata">

**Author:** ![Nimmerichter](https://forum.intervals.icu/user_avatar/forum.intervals.icu/nimmerichter/32/44090_2.png) [@Nimmerichter](https://forum.intervals.icu/u/Nimmerichter)\
**Post date:** [10 April 2023 14:56 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/14 "2023-04-10T14:56:40Z")

</div>

Dear all,  
I am trying to add an interval field which should be apparently pretty simple:  
(Work above FTP/Total Work\*100) \> its simply the percentage of W\>FTP to the Wtot for that interval.

I have found the “joules\_above\_ftp Integer” on the script page, but I must confess, my scripting-skills are pretty poor 😟  
Any help is much appreciated.

thanks  
alfred

---

<div class="post-metadata">

**Author:** ![Nimmerichter](https://forum.intervals.icu/user_avatar/forum.intervals.icu/nimmerichter/32/44090_2.png) [@Nimmerichter](https://forum.intervals.icu/u/Nimmerichter)\
**Post date:** [10 April 2023 15:16 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/15 "2023-04-10T15:16:02Z")

</div>

@david:  
brief question to your “All Work \>FTP” field:  
it is described as “…This measure includes the below the line portion when operating at or above FTP.”

Does this mean that power **AT** FTP is also accounted for (i.e. FTP 250W \> the script also calculates when working at 250W and not starts at 251W as the Work\>FTP would do?).  
And what means “…below the line portion…”? Does it also calculate 249 or 248, which is, by definition below FTP. Is there any trade-off in the script (e.g. if power is below FTP for xxx seconds \> then calculate \> else not).

Sorry for my simplified coding language, hope the question is clear enough.

best  
alfred

---

<div class="post-metadata">

**Author:** ![MedTechCD](https://forum.intervals.icu/user_avatar/forum.intervals.icu/medtechcd/32/40383_2.png) [@MedTechCD](https://forum.intervals.icu/u/MedTechCD)\
**Post date:** [10 April 2023 16:46 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/16 "2023-04-10T16:46:52Z")

</div>

There are 2 possibilities:

- You only take the Work that has been done at or above FTP and only that portion
- You take all Work done when intensity is equal or above FTP

> [@W' data for each ride](https://forum.intervals.icu/t/w-data-for-each-ride/3038/9):
>
> Just realized that I may not be explaining this clearly enough. You (probably) calculate the sum of the green and red boxes in underneath graph while it would be more intresting to calculate only the red box. [image]

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [10 April 2023 16:46 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/17 "2023-04-10T16:46:58Z")

</div>

The script does “if (w \>= ftp) {” so yes work done at FTP counts. I think this script will do:

```auto
{
interval.joules_above_ftp * 100 / interval.joules
}

```

---

<div class="post-metadata">

**Author:** ![Nimmerichter](https://forum.intervals.icu/user_avatar/forum.intervals.icu/nimmerichter/32/44090_2.png) [@Nimmerichter](https://forum.intervals.icu/u/Nimmerichter)\
**Post date:** [10 April 2023 18:03 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/18 "2023-04-10T18:03:32Z")

</div>

thank you David, script works as required, and also @MedTechCD for stepping in.

re to (w\>=ftp): this makes a significant difference compared to (w\>ftp), in the example below 35 vs 215kJ

![image](https://forum.intervals.icu/uploads/default/original/3X/8/1/8141984e7e5b314201331eae2c15a0f2535c06b9.png)

Have to reconsider on whether 1Watt up or down can make such a difference. But then again over 3h…

cheers  
alfred

---

<div class="post-metadata">

**Author:** ![Nimmerichter](https://forum.intervals.icu/user_avatar/forum.intervals.icu/nimmerichter/32/44090_2.png) [@Nimmerichter](https://forum.intervals.icu/u/Nimmerichter)\
**Post date:** [11 April 2023 07:28 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/19 "2023-04-11T07:28:32Z")

</div>

hi again, sorry a little too late yesterday evening to think clear 😴  
Soon became clear afterwards that “All Work\>FTP” calculate **ALL** power\*t, whereas “W\>FTP” use the typical Wbal calculation where W=(P-FTP)\*t.  
The former is obviously much higher.

cheers  
alfred

---

<div class="post-metadata">

**Author:** ![MedTechCD](https://forum.intervals.icu/user_avatar/forum.intervals.icu/medtechcd/32/40383_2.png) [@MedTechCD](https://forum.intervals.icu/u/MedTechCD)\
**Post date:** [11 April 2023 07:33 UTC](https://forum.intervals.icu/t/custom-interval-fields/25942/20 "2023-04-11T07:33:55Z")

</div>

That’s what I wanted to point out with this remark 😉

> [@MedTechCD](#):
>
> There are 2 possibilities:
> 
> - You only take the Work that has been done at or above FTP and only that portion
> - You take all Work done when intensity is equal or above FTP

[Next page](https://forum.intervals.icu/t/custom-interval-fields/25942.md?page=2)
