fix: compute GPX stats per-file to avoid spurious inter-track segments
Both stats.html.twig and trip.html.twig previously flattened all GPX trackpoints into a single masterPts array before computing haversine distance, elevation, and moving time. This caused the junction between file N's last point and file N+1's first point to be treated as a real segment — e.g. Florence→coast (~79 km, ~42 h) for Italy's 3-file demo data, overstating distance and moving time significantly. Fix: compute all metrics within each file independently and sum the results. fileResults collection and callback consumption are unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WPJztrVGbwic2xTG7G9fjM
This commit is contained in:
@@ -162,27 +162,24 @@ if (GPX_URLS.length > 0) {
|
||||
});
|
||||
fileResults[idx] = pts;
|
||||
pending--;
|
||||
if (pending === 0) { computeDistance(); }
|
||||
if (pending === 0) { computeTotalDistance(); }
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.warn('GPX load failed:', url, err);
|
||||
fileResults[idx] = [];
|
||||
pending--;
|
||||
if (pending === 0) { computeDistance(); }
|
||||
if (pending === 0) { computeTotalDistance(); }
|
||||
});
|
||||
});
|
||||
|
||||
function computeDistance() {
|
||||
var masterPts = [];
|
||||
fileResults.forEach(function(pts) {
|
||||
if (pts) { pts.forEach(function(p) { masterPts.push(p); }); }
|
||||
});
|
||||
function computeTotalDistance() {
|
||||
var total = 0;
|
||||
for (var i = 1; i < masterPts.length; i++) {
|
||||
total += haversine(masterPts[i-1].lat, masterPts[i-1].lon,
|
||||
masterPts[i].lat, masterPts[i].lon);
|
||||
}
|
||||
distEl.textContent = masterPts.length < 2 ? '—' : Math.round(total).toLocaleString();
|
||||
fileResults.forEach(function(pts) {
|
||||
for (var i = 1; i < pts.length; i++) {
|
||||
total += haversine(pts[i-1].lat, pts[i-1].lon, pts[i].lat, pts[i].lon);
|
||||
}
|
||||
});
|
||||
distEl.textContent = total > 0 ? Math.round(total).toLocaleString() : '—';
|
||||
}
|
||||
} else {
|
||||
// Mode B: sum haversine between consecutive entry lat/lng points
|
||||
|
||||
Reference in New Issue
Block a user