No longer waiting for buffer to be fill before setting grade, elevation, and max speed values

This commit is contained in:
Jimmy Shih
2013-11-27 14:06:15 -08:00
parent 6b8ccc8a83
commit 48ecf26a42
@@ -155,10 +155,8 @@ public class TripStatisticsUpdater {
currentSegment.updateLatitudeExtremities(location.getLatitude()); currentSegment.updateLatitudeExtremities(location.getLatitude());
currentSegment.updateLongitudeExtremities(location.getLongitude()); currentSegment.updateLongitudeExtremities(location.getLongitude());
Double elevationDifference = null; double elevationDifference = location.hasAltitude() ? updateElevation(location.getAltitude())
if (location.hasAltitude()) { : 0.0;
elevationDifference = updateElevation(location.getAltitude());
}
if (lastLocation == null || lastMovingLocation == null) { if (lastLocation == null || lastMovingLocation == null) {
lastLocation = location; lastLocation = location;
@@ -232,7 +230,7 @@ public class TripStatisticsUpdater {
speedBuffer.reset(); speedBuffer.reset();
} else if (isValidSpeed(time, speed, lastLocationTime, lastLocationSpeed)) { } else if (isValidSpeed(time, speed, lastLocationTime, lastLocationSpeed)) {
speedBuffer.setNext(speed); speedBuffer.setNext(speed);
if (speedBuffer.isFull() && speedBuffer.getAverage() > currentSegment.getMaxSpeed()) { if (speedBuffer.getAverage() > currentSegment.getMaxSpeed()) {
currentSegment.setMaxSpeed(speedBuffer.getAverage()); currentSegment.setMaxSpeed(speedBuffer.getAverage());
} }
} else { } else {
@@ -246,20 +244,18 @@ public class TripStatisticsUpdater {
* @param elevation the elevation * @param elevation the elevation
*/ */
@VisibleForTesting @VisibleForTesting
Double updateElevation(double elevation) { double updateElevation(double elevation) {
// Update elevation using the smoothed average after the buffer is full // Update elevation using the smoothed average
double oldAverage = elevationBuffer.getAverage(); double oldAverage = elevationBuffer.getAverage();
elevationBuffer.setNext(elevation); elevationBuffer.setNext(elevation);
double newAverage = elevationBuffer.getAverage(); double newAverage = elevationBuffer.getAverage();
if (elevationBuffer.isFull()) {
currentSegment.updateElevationExtremities(newAverage); currentSegment.updateElevationExtremities(newAverage);
Double difference = newAverage - oldAverage; double difference = newAverage - oldAverage;
if (difference > 0) { if (difference > 0) {
currentSegment.addTotalElevationGain(difference); currentSegment.addTotalElevationGain(difference);
}
return difference;
} }
return null; return difference;
} }
/** /**
@@ -269,13 +265,9 @@ public class TripStatisticsUpdater {
* @param rise the rise * @param rise the rise
*/ */
@VisibleForTesting @VisibleForTesting
void updateGrade(double run, Double rise) { void updateGrade(double run, double rise) {
runBuffer.setNext(run); runBuffer.setNext(run);
if (!runBuffer.isFull() || rise == null) {
return;
}
double smoothedRun = runBuffer.getAverage(); double smoothedRun = runBuffer.getAverage();
/* /*
@@ -286,9 +278,7 @@ public class TripStatisticsUpdater {
return; return;
} }
gradeBuffer.setNext(rise / smoothedRun); gradeBuffer.setNext(rise / smoothedRun);
if (gradeBuffer.isFull()) { currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
}
} }
private TripStatistics init(long time) { private TripStatistics init(long time) {