Raruto / leaflet-elevation

Leaflet plugin that allows to add elevation profiles using d3js
GNU General Public License v3.0
254 stars 82 forks source link

track.speed_min is always 0 #208

Closed hupe13 closed 1 year ago

hupe13 commented 2 years ago

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 commented 2 years ago

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.

Raruto commented 2 years ago

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

hupe13 commented 2 years ago

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.)

Raruto commented 2 years ago

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 commented 1 year ago

Patch released in version 2.2.8