Removed grade internals completely.

This commit is contained in:
Dennis Guse
2020-04-01 20:22:02 +02:00
parent 8b04d9c4a6
commit f621cdf032
10 changed files with 18 additions and 157 deletions
@@ -28,9 +28,6 @@ public class TripStatistics {
// The min and max elevation (meters) seen on this trip.
private final ExtremityMonitor elevationExtremities = new ExtremityMonitor();
// The min and max grade seen on this trip.
@Deprecated //Remove grade min/max completely
private final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
// The trip start time. This is the system time, might not match the GPs time.
private long startTime = -1L;
@@ -64,7 +61,6 @@ public class TripStatistics {
maxSpeed_mps = other.maxSpeed_mps;
elevationExtremities.set(other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
totalElevationGain_m = other.totalElevationGain_m;
gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
}
/**
@@ -85,10 +81,6 @@ public class TripStatistics {
elevationExtremities.update(other.elevationExtremities.getMax());
}
totalElevationGain_m += other.totalElevationGain_m;
if (other.gradeExtremities.hasData()) {
gradeExtremities.update(other.gradeExtremities.getMin());
gradeExtremities.update(other.gradeExtremities.getMax());
}
}
/**
@@ -242,31 +234,6 @@ public class TripStatistics {
totalElevationGain_m += gain_m;
}
public double getMinGrade() {
return gradeExtremities.getMin();
}
public void setMinGrade(double grade) {
gradeExtremities.setMin(grade);
}
public double getMaxGrade() {
return gradeExtremities.getMax();
}
/**
* Sets the maximum grade.
*
* @param grade the grade as a fraction (1.0 would mean vertical upwards)
*/
public void setMaxGrade(double grade) {
gradeExtremities.setMax(grade);
}
public void updateGradeExtremities(double grade) {
gradeExtremities.update(grade);
}
@NonNull
@Override
public String toString() {
@@ -274,7 +241,6 @@ public class TripStatistics {
+ "; Total Distance: " + getTotalDistance() + "; Total Time: " + getTotalTime()
+ "; Moving Time: " + getMovingTime() + "; Max Speed: " + getMaxSpeed()
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade()
+ "; Max Grade: " + getMaxGrade() + "}";
+ "; Elevation Gain: " + getTotalElevationGain() + "}";
}
}
@@ -38,21 +38,11 @@ import static de.dennisguse.opentracks.services.TrackRecordingService.MAX_NO_MOV
public class TripStatisticsUpdater {
/**
* The number of grade readings to smooth to get a somewhat accurate signal.
*/
public static final int GRADE_SMOOTHING_FACTOR = 5;
/**
* The number of elevation readings to smooth to get a somewhat accurate
* signal.
* The number of elevation readings to smooth to get a somewhat accurate signal.
*/
@VisibleForTesting
private static final int ELEVATION_SMOOTHING_FACTOR = 25;
/**
* The number of run readings to smooth for calculating grade.
*/
@VisibleForTesting
private static final int RUN_SMOOTHING_FACTOR = 25;
/**
* The number of speed reading to smooth to get a somewhat accurate signal.
*/
@@ -72,10 +62,6 @@ public class TripStatisticsUpdater {
// A buffer of the recent elevation readings (m)
private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR);
// A buffer of the recent run readings (m) for calculating grade
private final DoubleBuffer runBuffer = new DoubleBuffer(RUN_SMOOTHING_FACTOR);
// A buffer of the recent grade calculations (%)
private final DoubleBuffer gradeBuffer = new DoubleBuffer(GRADE_SMOOTHING_FACTOR);
// A buffer of the recent speed readings (m/s) for calculating max speed
private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR);
@@ -143,8 +129,6 @@ public class TripStatisticsUpdater {
lastTrackPoint = null;
lastMovingTrackPoint = null;
elevationBuffer.reset();
runBuffer.reset();
gradeBuffer.reset();
speedBuffer.reset();
return;
}
@@ -176,10 +160,6 @@ public class TripStatisticsUpdater {
// Update moving time
currentSegment.addMovingTime(movingTime);
// Update grade
double run = lastTrackPoint.distanceTo(trackPoint);
updateGrade(run, elevationDifference);
// Update max speed
if (trackPoint.hasSpeed() && lastTrackPoint.hasSpeed()) {
updateSpeed(trackPoint.getTime(), trackPoint.getSpeed(), lastTrackPoint.getTime(), lastTrackPoint.getSpeed());
@@ -250,26 +230,6 @@ public class TripStatisticsUpdater {
return difference;
}
/**
* Updates a grade reading.
*
* @param run the run
* @param rise the rise
*/
@VisibleForTesting
private void updateGrade(double run, double rise) {
runBuffer.setNext(run);
double smoothedRun = runBuffer.getAverage();
// With the error in the altitude measurement, it is dangerous to divide by * anything less than 5.
if (smoothedRun < 5.0) {
return;
}
gradeBuffer.setNext(rise / smoothedRun);
currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
}
private TripStatistics init(long time) {
TripStatistics stats = new TripStatistics();
stats.setStartTime(time);