From ef18f28bc1bbf916151f0ae9d4c9c57cc0dad016 Mon Sep 17 00:00:00 2001 From: sonora Date: Fri, 4 Nov 2016 09:48:56 +0100 Subject: [PATCH] Basic solution concept for #3222, keep old results in display to find proper heuristic parameter --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 17 +++++++++++++++-- .../net/osmand/plus/helpers/GpxUiHelper.java | 6 ++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index c7c500ac7f..4933278de5 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -251,6 +251,9 @@ public class GPXUtilities { public long startTime = Long.MAX_VALUE; public long endTime = Long.MIN_VALUE; public long timeSpan = 0; + //*****Issue 3222, for testing only + public long timeMoving0 = 0; + public float totalDistanceMoving0 = 0; public long timeMoving = 0; public float totalDistanceMoving = 0; @@ -418,8 +421,17 @@ public class GPXUtilities { net.osmand.Location.distanceBetween(prev.lat, prev.lon, point.lat, point.lon, calculations); totalDistance += calculations[0]; - // Averaging speed values is less exact than totalDistance/timeMoving - if (speed > 0 && point.time != 0 && prev.time != 0) { + // Motion detection: + // speed > 0 uses GPS chipset's motion detection + // calculations[0] > minDisplacment * time is heuristic needed because tracks may be filtered at recording time, so points at rest may not be present in file at all + + //*****Issue 3222, for testing only + if (speed > 0 && point.time != 0 && prev.time != 0) { + timeMoving0 = timeMoving0 + (point.time - prev.time); + totalDistanceMoving0 += calculations[0]; + } + + if ((speed > 0) && (calculations[0] > 0.5 / 1000f * (point.time - prev.time)) && point.time != 0 && prev.time != 0) { timeMoving = timeMoving + (point.time - prev.time); totalDistanceMoving += calculations[0]; } @@ -444,6 +456,7 @@ public class GPXUtilities { // 5. Max speed and Average speed, if any. Average speed is NOT overall (effective) speed, but only calculated for "moving" periods. + // Averaging speed values is less precise than totalDistanceMoving/timeMoving if (speedCount > 0) { if (timeMoving > 0) { avgSpeed = (float) totalDistanceMoving / (float) timeMoving * 1000f; diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index f99379d3d3..2a024abe91 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -133,6 +133,12 @@ public class GpxUiHelper { // 3. Time moving, if any if (analysis.isTimeMoving()) { + //*****Issue 3222, for testing only + final String formatDuration0 = Algorithms.formatDuration((int) (analysis.timeMoving0 / 1000), app.accessibilityEnabled()); + description.append(nl).append(app.getString(R.string.gpx_timemoving, + getColorValue(timeSpanClr, formatDuration0, html))); + description.append(" (" + getColorValue(distanceClr, OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving0, app), html) + ")"); + final String formatDuration = Algorithms.formatDuration((int) (analysis.timeMoving / 1000), app.accessibilityEnabled()); description.append(nl).append(app.getString(R.string.gpx_timemoving, getColorValue(timeSpanClr, formatDuration, html)));