Hi! I’m hoping to set up a custom stream for “inferred gear” that I could use for a chart of gear ratio without electric shifters. I think best for this would be:
Cadence / Speed
This would give, essentially, pedal strokes per distance traveled. I tried a few different scripts for a custom stream, but I don’t have a coding background and struggled with some errors. Has anyone set this up before that could share the code they used? Thanks!
Connor
For reference, the code I’ve tried is:
{
let speed = icu.streams.velocity_smooth
let cadence = icu.streams.cadence
for (let i = 0; i < data.length; i++) data[i] = (60 / 1000) * cadence[i] / speed[i]
}
If I let data[i] = cadence[i] or data[i] = speed[i], for example, I can see the charts. However, when I try to divide, it no longer shows anything. (Note: the 60/1000 is to get revs/ km as the metric from RPM and meters/ second.)
Nevermind, solved! Key was filtering out the divide-by-zero points. Fixed code below.
{
let speed = icu.streams.velocity_smooth;
let cadence = icu.streams.cadence;
for (let i = 0; i < data.length; i++) {
data[i] = (speed[i] > 0) ? (60 / 1000) * cadence[i] / speed[i] : null;
}