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
@@ -63,8 +63,6 @@ public class DescriptionGeneratorTest {
stats.setMaxElevation(550); stats.setMaxElevation(550);
stats.setMinElevation(-500); stats.setMinElevation(-500);
stats.setTotalElevationGain(6000); stats.setTotalElevationGain(6000);
stats.setMaxGrade(0.42);
stats.setMinGrade(0.11);
stats.setStartTime(START_TIME); stats.setStartTime(START_TIME);
track.setTripStatistics(stats); track.setTripStatistics(stats);
track.setCategory("hiking"); track.setCategory("hiking");
@@ -85,8 +83,6 @@ public class DescriptionGeneratorTest {
+ "Max elevation: 550 m (1804 ft)<br>" + "Max elevation: 550 m (1804 ft)<br>"
+ "Min elevation: -500 m (-1640 ft)<br>" + "Min elevation: -500 m (-1640 ft)<br>"
+ "Elevation gain: 6000 m (19685 ft)<br>" + "Elevation gain: 6000 m (19685 ft)<br>"
+ "Max grade: 42 %<br>"
+ "Min grade: 11 %<br>"
+ "Recorded: " + StringUtils.formatDateTime(context, START_TIME) + "<br>"; + "Recorded: " + StringUtils.formatDateTime(context, START_TIME) + "<br>";
Assert.assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true)); Assert.assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true));
@@ -142,34 +138,4 @@ public class DescriptionGeneratorTest {
descriptionGenerator.writePace(1.1, builder, R.string.description_average_pace_in_minute, "\n"); descriptionGenerator.writePace(1.1, builder, R.string.description_average_pace_in_minute, "\n");
Assert.assertEquals("Average pace: 15:09 min/km (24:23 min/mi)\n", builder.toString()); Assert.assertEquals("Average pace: 15:09 min/km (24:23 min/mi)\n", builder.toString());
} }
/**
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)}.
*/
@Test
public void testWriteGrade() {
StringBuilder builder = new StringBuilder();
descriptionGenerator.writeGrade(.042, builder, R.string.description_max_grade, "<br>");
Assert.assertEquals("Max grade: 4 %<br>", builder.toString());
}
/**
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)} with a NaN.
*/
@Test
public void testWriteGrade_nan() {
StringBuilder builder = new StringBuilder();
descriptionGenerator.writeGrade(Double.NaN, builder, R.string.description_max_grade, "<br>");
Assert.assertEquals("Max grade: 0 %<br>", builder.toString());
}
/**
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)} with an infinite number.
*/
@Test
public void testWriteGrade_infinite() {
StringBuilder builder = new StringBuilder();
descriptionGenerator.writeGrade(Double.POSITIVE_INFINITY, builder, R.string.description_max_grade, "<br>");
Assert.assertEquals("Max grade: 0 %<br>", builder.toString());
}
} }
@@ -323,8 +323,6 @@ public class CustomContentProviderUtilsTest {
statistics.setMaxSpeed(60.0); statistics.setMaxSpeed(60.0);
statistics.setMaxElevation(1250.0); statistics.setMaxElevation(1250.0);
statistics.setMinElevation(1200.0); statistics.setMinElevation(1200.0);
statistics.setMaxGrade(15.0);
statistics.setMinGrade(minGrade);
track.setTripStatistics(statistics); track.setTripStatistics(statistics);
contentProviderUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
@@ -427,8 +425,6 @@ public class CustomContentProviderUtilsTest {
statistics.setMaxSpeed(60.0); statistics.setMaxSpeed(60.0);
statistics.setMaxElevation(1250.0); statistics.setMaxElevation(1250.0);
statistics.setMinElevation(1200.0); statistics.setMinElevation(1200.0);
statistics.setMaxGrade(15.0);
statistics.setMinGrade(-25.0);
track.setTripStatistics(statistics); track.setTripStatistics(statistics);
contentProviderUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
@@ -58,10 +58,6 @@ public class TripStatisticsTest {
statistics.setMinElevation(1200.0); // Resulting min elevation statistics.setMinElevation(1200.0); // Resulting min elevation
statistics2.setMaxElevation(3575.0); // Resulting max elevation statistics2.setMaxElevation(3575.0); // Resulting max elevation
statistics2.setMinElevation(2800.0); statistics2.setMinElevation(2800.0);
statistics.setMaxGrade(15.0);
statistics.setMinGrade(-25.0); // Resulting min grade
statistics2.setMaxGrade(35.0); // Resulting max grade
statistics2.setMinGrade(0.0);
statistics.merge(statistics2); statistics.merge(statistics2);
@@ -74,8 +70,6 @@ public class TripStatisticsTest {
Assert.assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed(), 0.001); Assert.assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed(), 0.001);
Assert.assertEquals(1200.0, statistics.getMinElevation(), 0.001); Assert.assertEquals(1200.0, statistics.getMinElevation(), 0.001);
Assert.assertEquals(3575.0, statistics.getMaxElevation(), 0.001); Assert.assertEquals(3575.0, statistics.getMaxElevation(), 0.001);
Assert.assertEquals(-25.0, statistics.getMinGrade(), 0.001);
Assert.assertEquals(35.0, statistics.getMaxGrade(), 0.001);
} }
@Test @Test
@@ -134,12 +134,6 @@ public class DescriptionGenerator {
// Elevation gain // Elevation gain
writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak); writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak);
// Max grade
writeGrade(stats.getMaxGrade(), builder, R.string.description_max_grade, lineBreak);
// Min grade
writeGrade(stats.getMinGrade(), builder, R.string.description_min_grade, lineBreak);
// Recorded time // Recorded time
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime()))); builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime())));
builder.append(lineBreak); builder.append(lineBreak);
@@ -228,19 +222,4 @@ public class DescriptionGenerator {
builder.append(context.getString(resId, elevationInM, elevationInFt)); builder.append(context.getString(resId, elevationInM, elevationInFt));
builder.append(lineBreak); builder.append(lineBreak);
} }
/**
* Writes grade.
*
* @param grade grade in fraction
* @param builder StringBuilder to append grade
* @param resId resource id grade string
* @param lineBreak line break string
*/
@VisibleForTesting
void writeGrade(double grade, StringBuilder builder, int resId, String lineBreak) {
long gradeInPercent = Double.isNaN(grade) || Double.isInfinite(grade) ? 0L : Math.round(grade * 100);
builder.append(context.getString(resId, gradeInPercent));
builder.append(lineBreak);
}
} }
@@ -147,8 +147,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
private TextView speedMovingLabel; private TextView speedMovingLabel;
private TextView speedMovingValue; private TextView speedMovingValue;
private TextView speedMovingUnit; private TextView speedMovingUnit;
private View gradeElevationSeparator; private View elevationSeparator;
private View gradeElevationContainer; private View elevationContainer;
private View speedContainer; private View speedContainer;
private TextView speedLabel; private TextView speedLabel;
private TextView speedValue; private TextView speedValue;
@@ -190,8 +190,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
speedMovingValue = view.findViewById(R.id.stats_moving_speed_value); speedMovingValue = view.findViewById(R.id.stats_moving_speed_value);
speedMovingUnit = view.findViewById(R.id.stats_moving_speed_unit); speedMovingUnit = view.findViewById(R.id.stats_moving_speed_unit);
gradeElevationSeparator = view.findViewById(R.id.stats_elevation_separator); elevationSeparator = view.findViewById(R.id.stats_elevation_separator);
gradeElevationContainer = view.findViewById(R.id.stats_elevation_container); elevationContainer = view.findViewById(R.id.stats_elevation_container);
speedContainer = view.findViewById(R.id.stats_speed); speedContainer = view.findViewById(R.id.stats_speed);
speedLabel = view.findViewById(R.id.stats_speed_label); speedLabel = view.findViewById(R.id.stats_speed_label);
@@ -297,8 +297,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
speedMovingValue = null; speedMovingValue = null;
speedMovingUnit = null; speedMovingUnit = null;
gradeElevationSeparator = null; elevationSeparator = null;
gradeElevationContainer = null; elevationContainer = null;
speedContainer = null; speedContainer = null;
speedLabel = null; speedLabel = null;
@@ -535,8 +535,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
// Make elevation visible? // Make elevation visible?
{ {
boolean showElevation = PreferencesUtils.isShowStatsGradeElevation(getContext()); boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
gradeElevationSeparator.setVisibility(showElevation ? View.VISIBLE : View.GONE); elevationSeparator.setVisibility(showElevation ? View.VISIBLE : View.GONE);
} }
} }
@@ -580,10 +580,10 @@ public class StatsFragment extends Fragment implements TrackDataListener {
} }
// Set elevation // Set elevation
boolean showGradeElevation = isRecording && PreferencesUtils.isShowStatsGradeElevation(getContext()); boolean showElevation = isRecording && PreferencesUtils.isShowStatsElevation(getContext());
gradeElevationContainer.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE); elevationContainer.setVisibility(showElevation ? View.VISIBLE : View.GONE);
if (showGradeElevation) { if (showElevation) {
double altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? lastTrackPoint.getAltitude() : Double.NaN; double altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? lastTrackPoint.getAltitude() : Double.NaN;
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits); Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
@@ -28,9 +28,6 @@ public class TripStatistics {
// The min and max elevation (meters) seen on this trip. // The min and max elevation (meters) seen on this trip.
private final ExtremityMonitor elevationExtremities = new ExtremityMonitor(); 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. // The trip start time. This is the system time, might not match the GPs time.
private long startTime = -1L; private long startTime = -1L;
@@ -64,7 +61,6 @@ public class TripStatistics {
maxSpeed_mps = other.maxSpeed_mps; maxSpeed_mps = other.maxSpeed_mps;
elevationExtremities.set(other.elevationExtremities.getMin(), other.elevationExtremities.getMax()); elevationExtremities.set(other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
totalElevationGain_m = other.totalElevationGain_m; 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()); elevationExtremities.update(other.elevationExtremities.getMax());
} }
totalElevationGain_m += other.totalElevationGain_m; 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; 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 @NonNull
@Override @Override
public String toString() { public String toString() {
@@ -274,7 +241,6 @@ public class TripStatistics {
+ "; Total Distance: " + getTotalDistance() + "; Total Time: " + getTotalTime() + "; Total Distance: " + getTotalDistance() + "; Total Time: " + getTotalTime()
+ "; Moving Time: " + getMovingTime() + "; Max Speed: " + getMaxSpeed() + "; Moving Time: " + getMovingTime() + "; Max Speed: " + getMaxSpeed()
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation() + "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade() + "; Elevation Gain: " + getTotalElevationGain() + "}";
+ "; Max Grade: " + getMaxGrade() + "}";
} }
} }
@@ -38,21 +38,11 @@ import static de.dennisguse.opentracks.services.TrackRecordingService.MAX_NO_MOV
public class TripStatisticsUpdater { public class TripStatisticsUpdater {
/** /**
* The number of grade readings to smooth to get a somewhat accurate signal. * The number of elevation 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.
*/ */
@VisibleForTesting @VisibleForTesting
private static final int ELEVATION_SMOOTHING_FACTOR = 25; 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. * 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) // A buffer of the recent elevation readings (m)
private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR); 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 // A buffer of the recent speed readings (m/s) for calculating max speed
private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR); private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR);
@@ -143,8 +129,6 @@ public class TripStatisticsUpdater {
lastTrackPoint = null; lastTrackPoint = null;
lastMovingTrackPoint = null; lastMovingTrackPoint = null;
elevationBuffer.reset(); elevationBuffer.reset();
runBuffer.reset();
gradeBuffer.reset();
speedBuffer.reset(); speedBuffer.reset();
return; return;
} }
@@ -176,10 +160,6 @@ public class TripStatisticsUpdater {
// Update moving time // Update moving time
currentSegment.addMovingTime(movingTime); currentSegment.addMovingTime(movingTime);
// Update grade
double run = lastTrackPoint.distanceTo(trackPoint);
updateGrade(run, elevationDifference);
// Update max speed // Update max speed
if (trackPoint.hasSpeed() && lastTrackPoint.hasSpeed()) { if (trackPoint.hasSpeed() && lastTrackPoint.hasSpeed()) {
updateSpeed(trackPoint.getTime(), trackPoint.getSpeed(), lastTrackPoint.getTime(), lastTrackPoint.getSpeed()); updateSpeed(trackPoint.getTime(), trackPoint.getSpeed(), lastTrackPoint.getTime(), lastTrackPoint.getSpeed());
@@ -250,26 +230,6 @@ public class TripStatisticsUpdater {
return difference; 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) { private TripStatistics init(long time) {
TripStatistics stats = new TripStatistics(); TripStatistics stats = new TripStatistics();
stats.setStartTime(time); stats.setStartTime(time);
@@ -241,9 +241,9 @@ public class PreferencesUtils {
return getBoolean(context, R.string.stats_keep_screen_on_while_recording_key, DEFAULT); return getBoolean(context, R.string.stats_keep_screen_on_while_recording_key, DEFAULT);
} }
public static boolean isShowStatsGradeElevation(Context context) { public static boolean isShowStatsElevation(Context context) {
final boolean STATS_SHOW_GRADE_ELEVATION = context.getResources().getBoolean(R.bool.stats_show_grade_elevation_default); final boolean STATS_SHOW_ELEVATION = context.getResources().getBoolean(R.bool.stats_show_elevation_default);
return getBoolean(context, R.string.stats_show_grade_elevation_key, STATS_SHOW_GRADE_ELEVATION); return getBoolean(context, R.string.stats_show_grade_elevation_key, STATS_SHOW_ELEVATION);
} }
public static boolean isStatsShowCoordinate(Context context) { public static boolean isStatsShowCoordinate(Context context) {
+1 -1
View File
@@ -5,7 +5,7 @@
<bool name="stats_show_coordinate_default" translatable="false">false</bool> <bool name="stats_show_coordinate_default" translatable="false">false</bool>
<string name="stats_show_grade_elevation_key" translatable="false">statsShowGradeElevation</string> <string name="stats_show_grade_elevation_key" translatable="false">statsShowGradeElevation</string>
<bool name="stats_show_grade_elevation_default" translatable="false">false</bool> <bool name="stats_show_elevation_default" translatable="false">false</bool>
<string name="stats_show_on_lockscreen_while_recording_key" translatable="false">trackdetail_show_on_lockscreen_while_recording</string> <string name="stats_show_on_lockscreen_while_recording_key" translatable="false">trackdetail_show_on_lockscreen_while_recording</string>
<bool name="stats_show_on_lockscreen_while_recording_default" translatable="false">false</bool> <bool name="stats_show_on_lockscreen_while_recording_default" translatable="false">false</bool>
+1 -1
View File
@@ -44,7 +44,7 @@ limitations under the License.
<PreferenceCategory android:title="@string/settings_show"> <PreferenceCategory android:title="@string/settings_show">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="@bool/stats_show_grade_elevation_default" android:defaultValue="@bool/stats_show_elevation_default"
android:key="@string/stats_show_grade_elevation_key" android:key="@string/stats_show_grade_elevation_key"
android:title="@string/stats_elevation" /> android:title="@string/stats_elevation" />
<SwitchPreferenceCompat <SwitchPreferenceCompat