I added a custom field called “Max Performance condition”. This returns the maximal value of the performance condition. It is public and suggestions (like the same value the Garmin Device will show after 10 to 20 minutes after the start of a training?) are welcome.
Here is the script:
{
let maxValue = -Infinity;
if (icu && icu.fit && icu.fit.record) {
for (let record of icu.fit.record) {
let relevantFields = record.filter(field => field.num === 90 && typeof field.value === 'number');
if (relevantFields.length > 0) {
let maxFieldValue = Math.max(...relevantFields.map(field => field.value));
if (maxFieldValue > maxValue) {
maxValue = maxFieldValue;
}
}
}
let v = maxValue;
if (!Number.isNaN(v)) {
console.log('Max value:', v);
} else {
console.error('Failed to calculate max value');
}
v;
} else {
console.error('icu or icu.fit or icu.fit.record is null or undefined');
}
}
