Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

track.speed_min is always 0 #208

Closed
hupe13 opened this issue Jul 25, 2022 · 5 comments · Fixed by #219
Closed

track.speed_min is always 0 #208

hupe13 opened this issue Jul 25, 2022 · 5 comments · Fixed by #219

Comments

@hupe13
Copy link
Contributor

hupe13 commented Jul 25, 2022

Hi Raruto,

I have found that the minimum speed is always 0. The cause seems to be here:

pointToAttr: (_, i) => {
let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : 0;
},

See your example.

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

Thank you very much.

@hupe13
Copy link
Contributor Author

hupe13 commented Jul 26, 2022

Maybe I found a solution. Change

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

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
Copy link
Owner

Raruto commented Sep 20, 2022

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:

"test": "node spec/index.js",

test('iAvg()', () => {
let avg;
avg = iAvg(100, undefined, 1); assert.is(toFixed(avg), 100); // average for [100] is 100
avg = iAvg(100, avg, 2); assert.is(toFixed(avg), 100); // average for [100, 100] is 100
avg = iAvg(200, avg, 3); assert.is(toFixed(avg), 133.33); // average for [100, 100, 200] is 133.33
avg = iAvg(200, avg, 4); assert.is(toFixed(avg), 150); // average for [100, 100, 200, 200] is 150
});
test('iMin()', () => {
let min;
min = iMin(100, undefined); assert.is(toFixed(min), 100); // min for [100] is 100
min = iMin(0, min); assert.is(toFixed(min), 0); // min for [100, 0] is 100
min = iMin(-200, min); assert.is(toFixed(min), -200); // min for [100, 0, -200] is -200
min = iMin(200, min); assert.is(toFixed(min), -200); // min for [100, -100, -200, 200] is -200
});

@hupe13
Copy link
Contributor Author

hupe13 commented Sep 21, 2022

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
Copy link
Owner

Raruto commented Sep 21, 2022

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 added a commit that referenced this issue Oct 30, 2022
Raruto added a commit that referenced this issue Dec 18, 2022
* attempt to fix #208

* Add some `NaN` unit tests

* remove `skipNull` option and refactor `_registerDataAttribute` function

* Move stats calc after `deltaMax`, `clampRange` and `decimals` limiters
@Raruto
Copy link
Owner

Raruto commented Dec 18, 2022

Patch released in version 2.2.8

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants