I have a big problem here:
I have an array of gps datas and it's necessary to calculate some informations, I did it all except for the total elevation gain in the route.
There's an array like this [825.23423, 827.39420, 828.19319, ...] that storage the elevation of each gps point passed and I need to calculate the full sum.
The problem is that gps is not so accurate and sometimes gives some incorrect elevations, and it's making the sum get wrong.
I tried many ways to smooth the data, here are some:
const getMediaFixed = (values: number[]) => {
values.sort((a, b) => {
return a - b;
});
values.pop();
values.shift();
const media = values.reduce((a, b) => a + b) / values.length;
return media;
};
let last: number = elevations[0];
let elevationSum = 0;
// let countLimit: number = 1;
for (let i = 0; i < elevations.length - 5; i += 5) {
let media: number;
if (i <= elevations.length - 4) {
media = getMediaFixed([
elevations[i],
elevations[i + 1],
elevations[i + 2],
elevations[i + 3],
elevations[i + 4],
]);
} else {
media = elevations[i];
}
const temp = 0.75 * last + 0.25 * media;
if (temp - last > 0) {
elevationSum += temp - last;
}
last = temp;
}
The point is that it's not working anyway.
Here's a site that works perfectly calculating from a GPX File (I couldn't find the contact to ask for help): https://www.trackreport.net
I appreciate any ideas to improve the code!
I made it using the exponential moving average to smooth the array with elevations and then I used 1 meter to ignore the bugs!
Thanks.