mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-12-02 18:12:11 +00:00
improve speed computation
This commit is contained in:
@@ -977,11 +977,17 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
? statistics.global.distance.moving / (statistics.global.time.moving / 3600)
|
? statistics.global.distance.moving / (statistics.global.time.moving / 3600)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
statistics.local.speed = distanceWindowSmoothingWithDistanceAccumulator(
|
statistics.local.speed = timeWindowSmoothing(
|
||||||
points,
|
points,
|
||||||
200,
|
10000,
|
||||||
|
(index) =>
|
||||||
|
index > 0
|
||||||
|
? distance(points[index - 1].getCoordinates(), points[index].getCoordinates())
|
||||||
|
: 0,
|
||||||
(accumulated, start, end) =>
|
(accumulated, start, end) =>
|
||||||
points[start].time && points[end].time
|
points[start].time &&
|
||||||
|
points[end].time &&
|
||||||
|
points[end].time.getTime() - points[start].time.getTime() > 0
|
||||||
? (3600 * accumulated) /
|
? (3600 * accumulated) /
|
||||||
(points[end].time.getTime() - points[start].time.getTime())
|
(points[end].time.getTime() - points[start].time.getTime())
|
||||||
: undefined
|
: undefined
|
||||||
@@ -1942,9 +1948,10 @@ export function getElevationDistanceFunction(statistics: GPXStatistics) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function distanceWindowSmoothing(
|
function windowSmoothing(
|
||||||
points: TrackPoint[],
|
points: TrackPoint[],
|
||||||
distanceWindow: number,
|
distance: (index1: number, index2: number) => number,
|
||||||
|
window: number,
|
||||||
accumulate: (index: number) => number,
|
accumulate: (index: number) => number,
|
||||||
compute: (accumulated: number, start: number, end: number) => number,
|
compute: (accumulated: number, start: number, end: number) => number,
|
||||||
remove?: (index: number) => number
|
remove?: (index: number) => number
|
||||||
@@ -1955,10 +1962,7 @@ function distanceWindowSmoothing(
|
|||||||
end = 0,
|
end = 0,
|
||||||
accumulated = 0;
|
accumulated = 0;
|
||||||
for (var i = 0; i < points.length; i++) {
|
for (var i = 0; i < points.length; i++) {
|
||||||
while (
|
while (start + 1 < i && distance(start, i) > window) {
|
||||||
start + 1 < i &&
|
|
||||||
distance(points[start].getCoordinates(), points[i].getCoordinates()) > distanceWindow
|
|
||||||
) {
|
|
||||||
if (remove) {
|
if (remove) {
|
||||||
accumulated -= remove(start);
|
accumulated -= remove(start);
|
||||||
} else {
|
} else {
|
||||||
@@ -1966,10 +1970,7 @@ function distanceWindowSmoothing(
|
|||||||
}
|
}
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
while (
|
while (end < points.length && distance(i, end) <= window) {
|
||||||
end < points.length &&
|
|
||||||
distance(points[i].getCoordinates(), points[end].getCoordinates()) <= distanceWindow
|
|
||||||
) {
|
|
||||||
accumulated += accumulate(end);
|
accumulated += accumulate(end);
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
@@ -1979,13 +1980,31 @@ function distanceWindowSmoothing(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function distanceWindowSmoothing(
|
||||||
|
points: TrackPoint[],
|
||||||
|
window: number,
|
||||||
|
accumulate: (index: number) => number,
|
||||||
|
compute: (accumulated: number, start: number, end: number) => number
|
||||||
|
): number[] {
|
||||||
|
return windowSmoothing(
|
||||||
|
points,
|
||||||
|
(index1, index2) =>
|
||||||
|
distance(points[index1].getCoordinates(), points[index2].getCoordinates()),
|
||||||
|
window,
|
||||||
|
accumulate,
|
||||||
|
compute
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function distanceWindowSmoothingWithDistanceAccumulator(
|
function distanceWindowSmoothingWithDistanceAccumulator(
|
||||||
points: TrackPoint[],
|
points: TrackPoint[],
|
||||||
distanceWindow: number,
|
distanceWindow: number,
|
||||||
compute: (accumulated: number, start: number, end: number) => number
|
compute: (accumulated: number, start: number, end: number) => number
|
||||||
): number[] {
|
): number[] {
|
||||||
return distanceWindowSmoothing(
|
return windowSmoothing(
|
||||||
points,
|
points,
|
||||||
|
(index1, index2) =>
|
||||||
|
distance(points[index1].getCoordinates(), points[index2].getCoordinates()),
|
||||||
distanceWindow,
|
distanceWindow,
|
||||||
(index) =>
|
(index) =>
|
||||||
index > 0
|
index > 0
|
||||||
@@ -1996,6 +2015,21 @@ function distanceWindowSmoothingWithDistanceAccumulator(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function timeWindowSmoothing(
|
||||||
|
points: TrackPoint[],
|
||||||
|
window: number,
|
||||||
|
accumulate: (index: number) => number,
|
||||||
|
compute: (accumulated: number, start: number, end: number) => number
|
||||||
|
): number[] {
|
||||||
|
return windowSmoothing(
|
||||||
|
points,
|
||||||
|
(index1, index2) => points[index2].time?.getTime() - points[index1].time?.getTime() || 0,
|
||||||
|
window,
|
||||||
|
accumulate,
|
||||||
|
compute
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function withTimestamps(
|
function withTimestamps(
|
||||||
points: TrackPoint[],
|
points: TrackPoint[],
|
||||||
speed: number,
|
speed: number,
|
||||||
|
|||||||
Reference in New Issue
Block a user