[SOLVED] Custom Stream weirdness (division by zero)

I’m trying to add a speed/watts stream. I found the fields I need, and independently I get a chart for the whole activity, but I only get a chart for the first few minutes when either is divided by the other.

code follows:

{
  let speed = icu.streams.velocity_smooth
  let watts = icu.streams.fixed_watts
  for (let i = 0; i < data.length; i++) {
    //data[i] = watts[i]  / speed[i]
    data[i] = speed[i] / watts[i]
    //data[i] = speed[i]
    //data[i] = watts[i]
  }
}




Division by zero perhaps?

2 Likes

Thanks, but that seems unlikely given the attached charts.

perhaps just try filtering out zeros? even if it seems unlikely from the charts.

I just copied your text on one of my activities

It is very likely division by zero. Try:

data[i] = watts[i] ? speed[i] / watts[i] : 0

That sorted it out for my own test.

1 Like

Thank you David for pointing this , just change my Run Effectiveness Activity Steams accordingly.

Thanks. Not sure how many hundreds of times I’ll need to learn the lesson to protect my formulae from the data I’m feeding them. :face_with_diagonal_mouth:

How true. Thank you Kristopher, for pointing weirdness (division by zero) in my scripts. Running Effectiveness (RE) formulas by Dr. A. Coggan.