Sorry I can’t explain this better right now but this might serve as a skeleton.
intervalLengthMin = 30 // change this number for different interval sizes
// define variables
//activity = icu.activity
streams = icu.streams
// filter time and watts for points with positive velocity
intervalLength = intervalLengthMin * 60
time = streams.get("time").data
watts = streams.get("watts").data
heartrate = streams.get("heartrate").data
velocity_smooth = streams.get("velocity_smooth").data
// body of work
Int_number = []
Int_power = []
Int_work = []
Int_hr = []
Int_length = []
Int_text = []
Int_colour= []
for (let i = 0, IntV = 0; i < time.length; IntV++) {
z1 = i
for (j=0, temp_power = 0, temp_hr = 0; j < intervalLength; j++, i++) {
if (i === watts.length) { break; }
temp_power += watts[i]
temp_hr += heartrate[i]
}
if (IntV % 2 == 0) {
Int_colour.push('rgb(242, 212, 146,1)')
} else {
Int_colour.push('rgb(242, 149, 89,1)')
}
z2 = i
temp_text = `Mins: ${z1/60} - ${Math.floor(z2/60)} `
Int_number.push(((z1+z2)/2)/60)
Int_power.push(Math.round(temp_power/j))
Int_work.push(Math.round(temp_power/1000))
Int_hr.push(Math.round(temp_hr/j))
Int_length.push((j-12)/60)
Int_text.push(temp_text)
}
data = [
{
x: Int_number,
y: Int_work,
text: Int_work.map(a => `Average: ${a}kj`),
width: Int_length,
marker:{color: Int_colour},
hoverinfo: 'text',
textposition: 'auto',
type: 'bar'
},
{
x: Int_number,
y: Int_hr,
text: Int_hr.map(a => `Average: ${a}bpm`),
width: Int_length,
marker:{color: 'rgb(171,35,40, 0)'},
hoverinfo: 'text',
yaxis: 'y2',
type: 'line'
},
{
type: 'bar',
y: [200],
orientation: 'h',
}
]
layout = {
title: {
text: `Work done for each ${intervalLengthMin}min Interval`
},
showlegend: false,
xaxis: {
ticktext: Int_text,
tickvals: Int_number
},
yaxis: {title: 'Power (w)'},
yaxis2: {
title: 'Heartrate (bpm)',
showgrid: false,
overlaying: 'y',
side: 'right'
},
paper_bgcolor: 'rgba(245,246,249,0.8)',
plot_bgcolor: 'rgba(245,246,249,1)',
margin: {
l: 35,
r: 40,
t: 40,
b: 20
}
}
chart = {data, layout}
chart
I think this is kind of what you were asking