Help for a chart

I created this chart for visualize every single power data at each cadence value for entire activity.
Is possible to have a help fo visualize same value but for each interval…I tried without success…
This is the chart…

And this is a code

{
colors = ['rgb(0, 158, 128)', 'rgb(0, 158, 0)', 'rgb(255, 203, 14)', 'rgb(255, 127, 14)', 'rgb(221, 4, 71)', 'rgb(102, 51, 204)', 'rgb(0, 0, 0)','rgb(0, 0, 0)']
zonesP = []
let index=[]
let colori=[]

let act = icu.activity

let str = icu.streams
console.log(act.stream_types)

for (let i=0; i < act.icu_power_zones.length; i++){
   zonesP.push(act.icu_ftp * (act.icu_power_zones[i]/100))
}

console.log(zonesP)

let cad = str.get("cadence")
let pow = str.get("watts")

let x = cad.data
let y = pow.data

console.log(y)

for (let i=0; i < y.length; i++){
    index.push(zonesP.findIndex(x=>x>=y[i])+1);
    colori.push(colors[index[i]]);
}

   let data = [{
      x: x,
      y: y,
      type: 'scatter',
      mode: 'markers',
      marker: {
      size: 5, 
      color: colori},
    }
];



  let layout = {
    title: {
      text: "Power v Cadence"
    },
    margin: {
      l: 30,
      r: 20,
      t: 20,
      b: 30
    }
  }

  chart = { data, layout }
}

Thanks

You can do that. Here is some code that calculates average power for each work interval from the fixed_watts stream. It’s a bit contrived because average_watts is available as a field on the interval but does show how to work with interval data. The start_index (inclusive) and end_index (exclusive) are how you can get stream data for an interval.

Also you should use “fixed_watts” instead of “watts”. This has spikes clipped, dropouts fixed and so on.

{
  let activity = icu.activity
  let watts = icu.streams.fixed_watts

  let x = []
  let y = []
  let intervals = activity.icu_intervals || []
  for (let i = 0, c = 0; i < intervals.length; i++) {
    let iv = intervals[i]
    if (iv.type !== 'WORK') continue
    let tot = 0, num = 0
    for (let j = iv.start_index; j < iv.end_index; j++) {
      let v = watts[j]
      if (v !== null) {
        tot += v
        ++num
      }
    }
    let avgWatts = num > 0 ? tot/num : 0
    ++c
    x.push(iv.label || c)
    y.push(avgWatts /*iv.average_watts*/)
  }

  let data = [
    {
      x: x,
      y: y,
      type: 'bar',
      marker: {
        color: '#63c',
        opacity: 0.7
      }
    }
  ]

  let layout = {
    title: {
      text: "Average power for work intervals"
    },
    margin: {
      l: 30,
      r: 20,
      t: 20,
      b: 30
    }
  }

  chart = { data, layout }
}

Thanks @david for your support, but is not possible for each interval see the cadence and relative power ?

Similar to this chart, where 1,2,3,4,5,6 are the intervals.
For each interval I plot relative cadence and power

Thanks

Yes you can. Look for average_watts and average_cadence on each interval. All the fields are here:

Uusing avg_watts and average_cad , I always find only one value for each interval…or am I doing something wrong ?

I thought that is what you were looking for? If you want the underlying data for each interval you need to use the start_index and end_index fields and work with the streams.

@Manuel_Oberti
Just shared the chart. I have also added colored points depending on power zone following color code in intervals.
As mentioned by chat, in case of high amount of intervals in the activity, readability will be affected, but I think this chart covers what you were looking for.

Look for intervalsPWRCAD in the custom charts list

2 Likes

I try to create in another mode .
If you want to see look for Power / Cadence in custom charts.

Thanks

1 Like

I thought you wanted all intervals in sequence
Better to enable or disable intervals visibility in a single plot as you did to improve readability
Good work!

Your chart is perfect…I tried another test for another solution