mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Segments: use TrackPoint.type.
So, far specific latitude for segment start/end (i.e., PAUSE/RESUME) was used. #316.
This commit is contained in:
@@ -22,9 +22,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
||||
import de.dennisguse.opentracks.util.LocationUtils;
|
||||
import de.dennisguse.opentracks.util.TrackPointUtils;
|
||||
|
||||
/**
|
||||
@@ -58,6 +56,9 @@ public class TrackStatisticsUpdater {
|
||||
*/
|
||||
private static final double MAX_ACCELERATION = 0.02;
|
||||
|
||||
private boolean trackInitialized = false;
|
||||
private boolean segmentInitialized = false;
|
||||
|
||||
// The track's statistics
|
||||
private final TrackStatistics trackStatistics;
|
||||
|
||||
@@ -67,20 +68,14 @@ public class TrackStatisticsUpdater {
|
||||
private final DoubleRingBuffer speedBuffer_ms = new DoubleRingBuffer(SPEED_SMOOTHING_FACTOR);
|
||||
|
||||
// The current segment's statistics
|
||||
private TrackStatistics currentSegment;
|
||||
private final TrackStatistics currentSegment = new TrackStatistics();
|
||||
// Current segment's last trackPoint
|
||||
private TrackPoint lastTrackPoint;
|
||||
// Current segment's last moving trackPoint
|
||||
private TrackPoint lastMovingTrackPoint;
|
||||
|
||||
/**
|
||||
* Creates a new {@link TrackStatisticsUpdater}.
|
||||
*
|
||||
* @param startTime_ms the start time in milliseconds
|
||||
*/
|
||||
public TrackStatisticsUpdater(long startTime_ms) {
|
||||
trackStatistics = init(startTime_ms);
|
||||
currentSegment = init(startTime_ms);
|
||||
public TrackStatisticsUpdater() {
|
||||
trackStatistics = new TrackStatistics();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,17 +85,14 @@ public class TrackStatisticsUpdater {
|
||||
*/
|
||||
public TrackStatisticsUpdater(TrackStatistics trackStatistics) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
currentSegment = init(System.currentTimeMillis());
|
||||
trackInitialized = true;
|
||||
}
|
||||
|
||||
public void updateTime(long time) {
|
||||
currentSegment.setStopTime_ms(time);
|
||||
currentSegment.setTotalTime(time - currentSegment.getStartTime_ms());
|
||||
public void updateTime(long time_ms) {
|
||||
currentSegment.setStopTime_ms(time_ms);
|
||||
currentSegment.setTotalTime(time_ms - currentSegment.getStartTime_ms());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the track's statistics.
|
||||
*/
|
||||
public TrackStatistics getTrackStatistics() {
|
||||
// Take a snapshot - we don't want anyone messing with our trackStatistics
|
||||
TrackStatistics stats = new TrackStatistics(trackStatistics);
|
||||
@@ -110,23 +102,30 @@ public class TrackStatisticsUpdater {
|
||||
|
||||
/**
|
||||
* Adds a trackPoint.
|
||||
* TODO: This assume trackPoint has a valid time.
|
||||
*
|
||||
* @param trackPoint the trackPoint
|
||||
* @param minRecordingDistance the min recording distance
|
||||
*/
|
||||
public void addTrackPoint(TrackPoint trackPoint, int minRecordingDistance) {
|
||||
if (!trackInitialized) {
|
||||
trackStatistics.setStartTime_ms(trackPoint.getTime());
|
||||
trackInitialized = true;
|
||||
}
|
||||
if (!segmentInitialized) {
|
||||
currentSegment.setStartTime_ms(trackPoint.getTime());
|
||||
segmentInitialized = true;
|
||||
}
|
||||
|
||||
// Always update time
|
||||
updateTime(trackPoint.getTime());
|
||||
if (!LocationUtils.isValidLocation(trackPoint.getLocation())) {
|
||||
// Either pause or resume marker
|
||||
if (trackPoint.getLatitude() == TrackPointsColumns.PAUSE_LATITUDE) {
|
||||
if (trackPoint.isSegmentStart() || trackPoint.isSegmentEnd()) {
|
||||
if (trackPoint.isSegmentEnd()) {
|
||||
if (lastTrackPoint != null && lastMovingTrackPoint != null && lastTrackPoint != lastMovingTrackPoint) {
|
||||
currentSegment.addTotalDistance(lastMovingTrackPoint.distanceTo(lastTrackPoint));
|
||||
}
|
||||
trackStatistics.merge(currentSegment);
|
||||
}
|
||||
currentSegment = init(trackPoint.getTime());
|
||||
currentSegment.reset(trackPoint.getTime());
|
||||
lastTrackPoint = null;
|
||||
lastMovingTrackPoint = null;
|
||||
elevationBuffer_m.reset();
|
||||
@@ -238,13 +237,6 @@ public class TrackStatisticsUpdater {
|
||||
return newAverage - oldAverage;
|
||||
}
|
||||
|
||||
private TrackStatistics init(long time) {
|
||||
TrackStatistics stats = new TrackStatistics();
|
||||
stats.setStartTime_ms(time);
|
||||
stats.setStopTime_ms(time);
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the speed is valid.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user