leaflet-elevation icon indicating copy to clipboard operation
leaflet-elevation copied to clipboard

track.speed_min is always 0

Open hupe13 opened this issue 3 years ago • 4 comments

Hi Raruto,

I have found that the minimum speed is always 0. The cause seems to be here: https://github.com/Raruto/leaflet-elevation/blob/3ee745d71ed172979b7bfe0ff52f7c63214d3c04/src/handlers/speed.js#L18-L22

See your example.

I tried different things, but I can't solve the problem. Can you help me please?

Thank you very much.

hupe13 avatar Jul 25 '22 19:07 hupe13

Maybe I found a solution. Change https://github.com/Raruto/leaflet-elevation/blob/3ee745d71ed172979b7bfe0ff52f7c63214d3c04/src/utils.js#L135-L136 to

export const iMin = (iVal, min = +Infinity, idx = 1) => (idx > 1) ? (iVal < min ? iVal : min) : min;
export const iAvg = (iVal, avg = 0, idx = 1) => (iVal && idx > 1) ? (( iVal + avg * (idx - 1))) / idx : avg * (idx - 1) / idx;

I will made a pull request, when I'm ready.

hupe13 avatar Jul 26 '22 13:07 hupe13

Hi hupe, could you explain in detail the reason for this bug? (I don't have much time to understand this code..)

Even better, if you can write some tests that show the correctness of what you say:

https://github.com/Raruto/leaflet-elevation/blob/3ee745d71ed172979b7bfe0ff52f7c63214d3c04/package.json#L10

https://github.com/Raruto/leaflet-elevation/blob/3ee745d71ed172979b7bfe0ff52f7c63214d3c04/spec/utils.test.js#L9-L23

Raruto avatar Sep 20 '22 19:09 Raruto

You can see this in your example for the 2016 Santa Rosa Marathon. When you run you don't pause, you always move. But the minimum speed is 0. I have to recap my tests, please be patient. (It may be that the runner took a break during the marathon, but I have another gpx file for a run, there was definitely no break.)

hupe13 avatar Sep 21 '22 13:09 hupe13

When you run you don't pause, you always move. But the minimum speed is 0. I have to recap my tests, please be patient.

You should check the instant t = 0 -> speed = dx / dt = 0

Raruto avatar Sep 21 '22 17:09 Raruto

Patch released in version 2.2.8

Raruto avatar Dec 18 '22 10:12 Raruto