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
@@ -134,12 +134,6 @@ public class DescriptionGenerator {
// Elevation gain
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
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime())));
builder.append(lineBreak);
@@ -228,19 +222,4 @@ public class DescriptionGenerator {
builder.append(context.getString(resId, elevationInM, elevationInFt));
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 speedMovingValue;
private TextView speedMovingUnit;
private View gradeElevationSeparator;
private View gradeElevationContainer;
private View elevationSeparator;
private View elevationContainer;
private View speedContainer;
private TextView speedLabel;
private TextView speedValue;
@@ -190,8 +190,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
speedMovingValue = view.findViewById(R.id.stats_moving_speed_value);
speedMovingUnit = view.findViewById(R.id.stats_moving_speed_unit);
gradeElevationSeparator = view.findViewById(R.id.stats_elevation_separator);
gradeElevationContainer = view.findViewById(R.id.stats_elevation_container);
elevationSeparator = view.findViewById(R.id.stats_elevation_separator);
elevationContainer = view.findViewById(R.id.stats_elevation_container);
speedContainer = view.findViewById(R.id.stats_speed);
speedLabel = view.findViewById(R.id.stats_speed_label);
@@ -297,8 +297,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
speedMovingValue = null;
speedMovingUnit = null;
gradeElevationSeparator = null;
gradeElevationContainer = null;
elevationSeparator = null;
elevationContainer = null;
speedContainer = null;
speedLabel = null;
@@ -535,8 +535,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
// Make elevation visible?
{
boolean showElevation = PreferencesUtils.isShowStatsGradeElevation(getContext());
gradeElevationSeparator.setVisibility(showElevation ? View.VISIBLE : View.GONE);
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
elevationSeparator.setVisibility(showElevation ? View.VISIBLE : View.GONE);
}
}
@@ -580,10 +580,10 @@ public class StatsFragment extends Fragment implements TrackDataListener {
}
// Set elevation
boolean showGradeElevation = isRecording && PreferencesUtils.isShowStatsGradeElevation(getContext());
gradeElevationContainer.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE);
boolean showElevation = isRecording && PreferencesUtils.isShowStatsElevation(getContext());
elevationContainer.setVisibility(showElevation ? View.VISIBLE : View.GONE);
if (showGradeElevation) {
if (showElevation) {
double altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? lastTrackPoint.getAltitude() : Double.NaN;
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.
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);
@@ -241,9 +241,9 @@ public class PreferencesUtils {
return getBoolean(context, R.string.stats_keep_screen_on_while_recording_key, DEFAULT);
}
public static boolean isShowStatsGradeElevation(Context context) {
final boolean STATS_SHOW_GRADE_ELEVATION = context.getResources().getBoolean(R.bool.stats_show_grade_elevation_default);
return getBoolean(context, R.string.stats_show_grade_elevation_key, STATS_SHOW_GRADE_ELEVATION);
public static boolean isShowStatsElevation(Context context) {
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_ELEVATION);
}
public static boolean isStatsShowCoordinate(Context context) {