Averaging heights
This commit is contained in:
parent
99daeefa98
commit
790a692529
|
@ -1,5 +1,6 @@
|
||||||
export const getHeightStats = (wpts: Wpt[]) => {
|
export const getHeightStats = (wpts: Wpt[]) => {
|
||||||
let previous: number | null = null,
|
let previous: number | null = null,
|
||||||
|
previousAvg: number | null = null,
|
||||||
min: number | null = null,
|
min: number | null = null,
|
||||||
max: number | null = null,
|
max: number | null = null,
|
||||||
positive: number = 0,
|
positive: number = 0,
|
||||||
|
@ -7,7 +8,7 @@ export const getHeightStats = (wpts: Wpt[]) => {
|
||||||
|
|
||||||
wpts.forEach((wpt) => {
|
wpts.forEach((wpt) => {
|
||||||
if (wpt.ele) {
|
if (wpt.ele) {
|
||||||
const ele = Math.round(wpt.ele);
|
const ele = 10 * Math.round(wpt.ele / 10);
|
||||||
if (!max || ele > max) {
|
if (!max || ele > max) {
|
||||||
max = ele;
|
max = ele;
|
||||||
}
|
}
|
||||||
|
@ -15,12 +16,16 @@ export const getHeightStats = (wpts: Wpt[]) => {
|
||||||
min = ele;
|
min = ele;
|
||||||
}
|
}
|
||||||
if (previous) {
|
if (previous) {
|
||||||
if (ele > previous) {
|
const avg = (ele + previous) / 2;
|
||||||
positive += ele - previous;
|
if (previousAvg) {
|
||||||
|
if (avg > previousAvg) {
|
||||||
|
positive += avg - previousAvg;
|
||||||
} else {
|
} else {
|
||||||
negative += previous - ele;
|
negative += avg - previousAvg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
previousAvg = avg;
|
||||||
|
}
|
||||||
previous = ele;
|
previous = ele;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue