Renamed TripStatistics to TrackStatistics.

This commit is contained in:
Dennis Guse
2020-04-02 08:01:00 +02:00
parent dfc785f2fd
commit 16c654141f
28 changed files with 237 additions and 237 deletions
@@ -19,20 +19,20 @@ package de.dennisguse.opentracks.stats;
import androidx.annotation.NonNull;
/**
* Statistical data about a trip.
* The data in this class should be filled out by TripStatisticsBuilder.
* Statistical data about a {@link de.dennisguse.opentracks.content.data.Track}.
* The data in this class should be filled out by {@link TrackStatisticsUpdater}.
*
* @author Rodrigo Damazio
*/
public class TripStatistics {
public class TrackStatistics {
// The min and max elevation (meters) seen on this trip.
// The min and max elevation (meters) seen on this track.
private final ExtremityMonitor elevationExtremities = new ExtremityMonitor();
// The trip start time. This is the system time, might not match the GPs time.
private long startTime = -1L;
// The trip stop time. This is the system time, might not match the GPS time.
private long stopTime = -1L;
// The track start time. This is the system time, might not match the GPs time.
private long startTime_ms = -1L;
// The track stop time. This is the system time, might not match the GPS time.
private long stopTime_ms = -1L;
private double totalDistance_m;
// Updated when new points are received, may be stale.
@@ -44,7 +44,7 @@ public class TripStatistics {
// The total elevation gained (meters).
private double totalElevationGain_m;
public TripStatistics() {
public TrackStatistics() {
}
/**
@@ -52,9 +52,9 @@ public class TripStatistics {
*
* @param other another statistics data object to copy from
*/
public TripStatistics(TripStatistics other) {
startTime = other.startTime;
stopTime = other.stopTime;
public TrackStatistics(TrackStatistics other) {
startTime_ms = other.startTime_ms;
stopTime_ms = other.stopTime_ms;
totalDistance_m = other.totalDistance_m;
totalTime_ms = other.totalTime_ms;
movingTime_ms = other.movingTime_ms;
@@ -69,9 +69,9 @@ public class TripStatistics {
*
* @param other another statistics data object
*/
public void merge(TripStatistics other) {
startTime = Math.min(startTime, other.startTime);
stopTime = Math.max(stopTime, other.stopTime);
public void merge(TrackStatistics other) {
startTime_ms = Math.min(startTime_ms, other.startTime_ms);
stopTime_ms = Math.max(stopTime_ms, other.stopTime_ms);
totalDistance_m += other.totalDistance_m;
totalTime_ms += other.totalTime_ms;
movingTime_ms += other.movingTime_ms;
@@ -84,22 +84,22 @@ public class TripStatistics {
}
/**
* Gets the trip start time. The number of milliseconds since epoch.
* Gets the track start time. The number of milliseconds since epoch.
*/
public long getStartTime() {
return startTime;
public long getStartTime_ms() {
return startTime_ms;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
public void setStartTime_ms(long startTime_ms) {
this.startTime_ms = startTime_ms;
}
public long getStopTime() {
return stopTime;
public long getStopTime_ms() {
return stopTime_ms;
}
public void setStopTime(long stopTime) {
this.stopTime = stopTime;
public void setStopTime_ms(long stopTime_ms) {
this.stopTime_ms = stopTime_ms;
}
public double getTotalDistance() {
@@ -117,7 +117,7 @@ public class TripStatistics {
/**
* Gets the total time in milliseconds that this track has been active.
* This statistic is only updated when a new point is added to the statistics, so it may be off.
* If you need to calculate the proper total time, use {@link #getStartTime} with the current time.
* If you need to calculate the proper total time, use {@link #getStartTime_ms} with the current time.
*/
public long getTotalTime() {
return totalTime_ms;
@@ -237,7 +237,7 @@ public class TripStatistics {
@NonNull
@Override
public String toString() {
return "TripStatistics { Start Time: " + getStartTime() + "; Stop Time: " + getStopTime()
return "TrackStatistics { Start Time: " + getStartTime_ms() + "; Stop Time: " + getStopTime_ms()
+ "; Total Distance: " + getTotalDistance() + "; Total Time: " + getTotalTime()
+ "; Moving Time: " + getMovingTime() + "; Max Speed: " + getMaxSpeed()
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
@@ -28,14 +28,14 @@ import de.dennisguse.opentracks.util.LocationUtils;
import static de.dennisguse.opentracks.services.TrackRecordingService.MAX_NO_MOVEMENT_SPEED;
/**
* Updater for {@link TripStatistics}.
* For updating track trip statistics as new locations are added.
* NOTE:Some of the locations represent pause/resume separator.
* Updater for {@link TrackStatistics}.
* For updating track {@link TrackStatistics} as new {@link TrackPoint}s are added.
* NOTE: Some of the locations represent pause/resume separator.
*
* @author Sandor Dornbush
* @author Rodrigo Damazio
*/
public class TripStatisticsUpdater {
public class TrackStatisticsUpdater {
/**
* The number of elevation readings to smooth to get a somewhat accurate signal.
@@ -49,7 +49,7 @@ public class TripStatisticsUpdater {
@VisibleForTesting
private static final int SPEED_SMOOTHING_FACTOR = 25;
private static final String TAG = TripStatisticsUpdater.class.getSimpleName();
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
/**
* Ignore any acceleration faster than this.
* Will ignore any speeds that imply acceleration greater than 2g's
@@ -57,52 +57,52 @@ public class TripStatisticsUpdater {
*/
private static final double MAX_ACCELERATION = 0.02;
// The track's trip statistics
private final TripStatistics tripStatistics;
// The track's statistics
private final TrackStatistics trackStatistics;
// A buffer of the recent elevation readings (m)
private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR);
// A buffer of the recent speed readings (m/s) for calculating max speed
private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR);
// The current segment's trip statistics
private TripStatistics currentSegment;
// The current segment's statistics
private TrackStatistics currentSegment;
// Current segment's last trackPoint
private TrackPoint lastTrackPoint;
// Current segment's last moving trackPoint
private TrackPoint lastMovingTrackPoint;
/**
* Creates a new trip statistics updater.
* Creates a new {@link TrackStatisticsUpdater}.
*
* @param startTime the start time
* @param startTime_ms the start time in milliseconds
*/
public TripStatisticsUpdater(long startTime) {
tripStatistics = init(startTime);
currentSegment = init(startTime);
public TrackStatisticsUpdater(long startTime_ms) {
trackStatistics = init(startTime_ms);
currentSegment = init(startTime_ms);
}
/**
* Creates a new trip statistics updater with a trip statistics already existed.
* Creates a new{@link TrackStatisticsUpdater} with a {@link TrackStatisticsUpdater} already existed.
*
* @param tripStatistics a trip statistics.
* @param trackStatistics a {@link TrackStatisticsUpdater}
*/
public TripStatisticsUpdater(TripStatistics tripStatistics) {
this.tripStatistics = tripStatistics;
public TrackStatisticsUpdater(TrackStatistics trackStatistics) {
this.trackStatistics = trackStatistics;
currentSegment = init(System.currentTimeMillis());
}
public void updateTime(long time) {
currentSegment.setStopTime(time);
currentSegment.setTotalTime(time - currentSegment.getStartTime());
currentSegment.setStopTime_ms(time);
currentSegment.setTotalTime(time - currentSegment.getStartTime_ms());
}
/**
* Gets the track's trip statistics.
* Gets the track's statistics.
*/
public TripStatistics getTripStatistics() {
// Take a snapshot - we don't want anyone messing with our tripStatistics
TripStatistics stats = new TripStatistics(tripStatistics);
public TrackStatistics getTrackStatistics() {
// Take a snapshot - we don't want anyone messing with our trackStatistics
TrackStatistics stats = new TrackStatistics(trackStatistics);
stats.merge(currentSegment);
return stats;
}
@@ -123,7 +123,7 @@ public class TripStatisticsUpdater {
if (lastTrackPoint != null && lastMovingTrackPoint != null && lastTrackPoint != lastMovingTrackPoint) {
currentSegment.addTotalDistance(lastMovingTrackPoint.distanceTo(lastTrackPoint));
}
tripStatistics.merge(currentSegment);
trackStatistics.merge(currentSegment);
}
currentSegment = init(trackPoint.getLocation().getTime());
lastTrackPoint = null;
@@ -230,10 +230,10 @@ public class TripStatisticsUpdater {
return difference;
}
private TripStatistics init(long time) {
TripStatistics stats = new TripStatistics();
stats.setStartTime(time);
stats.setStopTime(time);
private TrackStatistics init(long time) {
TrackStatistics stats = new TrackStatistics();
stats.setStartTime_ms(time);
stats.setStopTime_ms(time);
return stats;
}