Skip to content

Commit

Permalink
Bugfix: Elevation in charts smoothing removed as it was broken.
Browse files Browse the repository at this point in the history
Fixes #1241.
  • Loading branch information
dennisguse committed Jun 11, 2022
1 parent d680089 commit 0b326a7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void create_by_time() {
statistics.setTotalTime(Duration.ofSeconds(1000));

// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), Altitude.EGM2008.of(0), false, UnitSystem.IMPERIAL);
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL);

// then
assertEquals(1000000, (long) point.getTimeOrDistance());
Expand All @@ -40,7 +40,7 @@ public void create_by_distance() {
statistics.setTotalDistance(Distance.of(1000));

// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), Altitude.EGM2008.of(0), true, UnitSystem.METRIC);
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);

// then
assertEquals(1, (long) point.getTimeOrDistance());
Expand All @@ -50,9 +50,11 @@ public void create_by_distance() {
public void create_get_altitude_speed_and_pace() {
// given
TrackStatistics statistics = new TrackStatistics();
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));

// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(10), Altitude.EGM2008.of(50), false, UnitSystem.METRIC);
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertEquals(50, point.getAltitude(), 0.01);
Expand All @@ -64,9 +66,10 @@ public void create_get_altitude_speed_and_pace() {
public void create_sensorNotAvailable() {
// given
TrackStatistics statistics = new TrackStatistics();

TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(10), Altitude.EGM2008.of(50), false, UnitSystem.METRIC);
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertNull(point.getHeartRate());
Expand All @@ -77,15 +80,16 @@ public void create_sensorNotAvailable() {
@Test
public void create_sensorAvailable() {
// given
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint();
trackPoint.setHeartRate(100f);
trackPoint.setCadence(101f);
trackPoint.setPower(102f);
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50))
.setHeartRate(100f)
.setCadence(101f)
.setPower(102f);

TrackStatistics statistics = new TrackStatistics();

// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), Altitude.EGM2008.of(50), false, UnitSystem.METRIC);
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertEquals(100.0, point.getHeartRate(), 0.01);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public void clearTrackPoints() {
}
}

public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed, Altitude smoothedAltitude) {
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed) {
if (isResumed()) {
ChartPoint point = new ChartPoint(trackStatistics, trackPoint, smoothedSpeed, smoothedAltitude, chartByDistance, viewBinding.chartView.getUnitSystem());
ChartPoint point = new ChartPoint(trackStatistics, trackPoint, smoothedSpeed, chartByDistance, viewBinding.chartView.getUnitSystem());
pendingPoints.add(point);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/dennisguse/opentracks/chart/ChartPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class ChartPoint {
this.altitude = altitude;
}

public ChartPoint(@NonNull TrackStatistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, Altitude smoothedAltitude, boolean chartByDistance, UnitSystem unitSystem) {
public ChartPoint(@NonNull TrackStatistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
if (chartByDistance) {
timeOrDistance = trackStatistics.getTotalDistance().toKM_Miles(unitSystem);
} else {
timeOrDistance = trackStatistics.getTotalTime().toMillis();
}

if (smoothedAltitude != null) {
altitude = Distance.of(smoothedAltitude.toM()).toM_FT(unitSystem);
if (trackPoint.hasAltitude()) {
altitude = Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem);
}

if (smoothedSpeed != null) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dennisguse/opentracks/data/TrackDataHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private void notifyTrackPointsTableUpdate(boolean updateSamplingState, Set<Liste
// Also include the last point if the selected track is not recording.
if ((localNumLoadedTrackPoints % samplingFrequency == 0) || (trackPointId == lastTrackPointId && !isSelectedTrackRecording())) {
for (Listener trackDataListener : listeners) {
trackDataListener.onSampledInTrackPoint(trackPoint, currentUpdater.getTrackStatistics(), currentUpdater.getSmoothedSpeed(), currentUpdater.getSmoothedAltitude());
trackDataListener.onSampledInTrackPoint(trackPoint, currentUpdater.getTrackStatistics(), currentUpdater.getSmoothedSpeed());
}
} else {
for (Listener trackDataListener : listeners) {
Expand Down Expand Up @@ -432,7 +432,7 @@ public interface Listener {
*
* @param trackPoint the trackPoint
*/
default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed, @Nullable Altitude smoothedAltitude_m) {
default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TrackPoint {
private Double longitude;
private Distance horizontalAccuracy;
private Distance verticalAccuracy;
private Altitude altitude;
private Altitude altitude; //TODO use Altitude.WGS84
private Speed speed;
private Float bearing;
private Distance sensorDistance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,6 @@ private void resetAverageHeartRate() {
totalHeartRateDuration = Duration.ZERO;
}

/**
* Gets the smoothed altitude over several readings.
* The altitude readings is noisy so the smoothed altitude is better than the raw altitude for many tasks.
*/
public Altitude getSmoothedAltitude() {
return altitudeBuffer.getAverage();
}

public Speed getSmoothedSpeed() {
return speedBuffer.getAverage();
}
Expand Down

0 comments on commit 0b326a7

Please sign in to comment.