From 8ba598000937751443d13c150af546f344bbf147 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Thu, 11 Jul 2013 17:06:14 -0700 Subject: [PATCH] Code cleanup: reorg methods in TripStatistics --- .../mytracks/stats/TripStatisticsUpdater.java | 2 +- .../apps/mytracks/stats/TripStatistics.java | 314 +++++++++--------- 2 files changed, 157 insertions(+), 159 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java index c6c0065d4..e34fec1a8 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java +++ b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java @@ -73,7 +73,7 @@ public class TripStatisticsUpdater { /** * Ignore any acceleration faster than this. Will ignore any speeds that imply - * accelaration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02 + * acceleration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02 * m/(m*ms) */ private static final double MAX_ACCELERATION = 0.02; diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java b/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java index cee446305..c10385fcb 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java @@ -73,20 +73,19 @@ public class TripStatistics implements Parcelable { * @param other another statistics data object to copy from */ public TripStatistics(TripStatistics other) { - this.startTime = other.startTime; - this.stopTime = other.stopTime; - this.totalDistance = other.totalDistance; - this.totalTime = other.totalTime; - this.movingTime = other.movingTime; - this.latitudeExtremities.set( - other.latitudeExtremities.getMin(), other.latitudeExtremities.getMax()); - this.longitudeExtremities.set( + startTime = other.startTime; + stopTime = other.stopTime; + totalDistance = other.totalDistance; + totalTime = other.totalTime; + movingTime = other.movingTime; + latitudeExtremities.set(other.latitudeExtremities.getMin(), other.latitudeExtremities.getMax()); + longitudeExtremities.set( other.longitudeExtremities.getMin(), other.longitudeExtremities.getMax()); - this.maxSpeed = other.maxSpeed; - this.elevationExtremities.set( + maxSpeed = other.maxSpeed; + elevationExtremities.set( other.elevationExtremities.getMin(), other.elevationExtremities.getMax()); - this.totalElevationGain = other.totalElevationGain; - this.gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax()); + totalElevationGain = other.totalElevationGain; + gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax()); } /** @@ -128,6 +127,15 @@ public class TripStatistics implements Parcelable { return startTime; } + /** + * Sets the trip start time. + * + * @param startTime the trip start time in milliseconds since the epoch + */ + public void setStartTime(long startTime) { + this.startTime = startTime; + } + /** * Gets the trip stop time. The number of milliseconds since epoch. */ @@ -135,6 +143,15 @@ public class TripStatistics implements Parcelable { return stopTime; } + /** + * Sets the trip stop time. + * + * @param stopTime the stop time in milliseconds since the epoch + */ + public void setStopTime(long stopTime) { + this.stopTime = stopTime; + } + /** * Gets the total distance the user traveled in meters. */ @@ -142,6 +159,24 @@ public class TripStatistics implements Parcelable { return totalDistance; } + /** + * Sets the total trip distance. + * + * @param totalDistance the trip distance in meters + */ + public void setTotalDistance(double totalDistance) { + this.totalDistance = totalDistance; + } + + /** + * Adds to the current total distance. + * + * @param distance the distance to add in meters + */ + public void addTotalDistance(double distance) { + totalDistance += distance; + } + /** * Gets the total time in milliseconds that this track has been active. This * statistic is only updated when a new point is added to the statistics, so @@ -152,6 +187,15 @@ public class TripStatistics implements Parcelable { return totalTime; } + /** + * Sets the trip total time. + * + * @param totalTime the trip total time in milliseconds + */ + public void setTotalTime(long totalTime) { + this.totalTime = totalTime; + } + /** * Gets the moving time in milliseconds. */ @@ -159,6 +203,24 @@ public class TripStatistics implements Parcelable { return movingTime; } + /** + * Sets the trip total moving time. + * + * @param movingTime the trip total moving time in milliseconds + */ + public void setMovingTime(long movingTime) { + this.movingTime = movingTime; + } + + /** + * Adds to the trip total moving time. + * + * @param time the time in milliseconds + */ + public void addMovingTime(long time) { + movingTime += time; + } + /** * Gets the topmost position (highest latitude) of the track, in signed * degrees. @@ -237,6 +299,38 @@ public class TripStatistics implements Parcelable { return (getLeftDegrees() + getRightDegrees()) / 2.0; } + /** + * Sets the bounding box for this trip. The unit for all parameters is signed + * millions of degree (degrees * 1E6). + * + * @param leftE6 the leftmost longitude reached + * @param topE6 the topmost latitude reached + * @param rightE6 the rightmost longitude reached + * @param bottomE6 the bottommost latitude reached + */ + public void setBounds(int leftE6, int topE6, int rightE6, int bottomE6) { + latitudeExtremities.set(bottomE6 / 1E6, topE6 / 1E6); + longitudeExtremities.set(leftE6 / 1E6, rightE6 / 1E6); + } + + /** + * Updates a new latitude value. + * + * @param latitude the latitude value in signed decimal degrees + */ + public void updateLatitudeExtremities(double latitude) { + latitudeExtremities.update(latitude); + } + + /** + * Updates a new longitude value. + * + * @param longitude the longitude value in signed decimal degrees + */ + public void updateLongitudeExtremities(double longitude) { + longitudeExtremities.update(longitude); + } + /** * Gets the average speed in meters/second. This calculation only takes into * account the displacement until the last point that was accounted for in @@ -266,139 +360,6 @@ public class TripStatistics implements Parcelable { return maxSpeed; } - /** - * Gets the minimum elevation. This is calculated from the smoothed elevation - * so this can actually be more than the current elevation. - */ - public double getMinElevation() { - return elevationExtremities.getMin(); - } - - /** - * Gets the maximum elevation. This is calculated from the smoothed elevation - * so this can actually be less than the current elevation. - */ - public double getMaxElevation() { - return elevationExtremities.getMax(); - } - - /** - * Gets the total elevation gain in meters. This is calculated as the sum of - * all positive differences in the smoothed elevation. - */ - public double getTotalElevationGain() { - return totalElevationGain; - } - - /** - * Gets the minimum grade for this trip. - */ - public double getMinGrade() { - return gradeExtremities.getMin(); - } - - /** - * Gets the maximum grade for this trip. - */ - public double getMaxGrade() { - return gradeExtremities.getMax(); - } - - /** - * Sets the trip start time. - * - * @param startTime the trip start time in milliseconds since the epoch - */ - public void setStartTime(long startTime) { - this.startTime = startTime; - } - - /** - * Sets the trip stop time. - * - * @param stopTime the stop time in milliseconds since the epoch - */ - public void setStopTime(long stopTime) { - this.stopTime = stopTime; - } - - /** - * Sets the total trip distance. - * - * @param totalDistance the trip distance in meters - */ - public void setTotalDistance(double totalDistance) { - this.totalDistance = totalDistance; - } - - /** - * Adds to the current total distance. - * - * @param distance the distance to add in meters - */ - void addTotalDistance(double distance) { - totalDistance += distance; - } - - /** - * Sets the trip total time. - * - * @param totalTime the trip total time in milliseconds - */ - public void setTotalTime(long totalTime) { - this.totalTime = totalTime; - } - - /** - * Sets the trip total moving time. - * - * @param movingTime the trip total moving time in milliseconds - */ - public void setMovingTime(long movingTime) { - this.movingTime = movingTime; - } - - /** - * Adds to the trip total moving time. - * - * @param time the time in milliseconds - */ - void addMovingTime(long time) { - movingTime += time; - } - - /** - * Sets the bounding box for this trip. The unit for all parameters is signed - * millions of degree (degrees * 1E6). - * - * @param leftE6 the leftmost longitude reached - * @param topE6 the topmost latitude reached - * @param rightE6 the rightmost longitude reached - * @param bottomE6 the bottommost latitude reached - */ - public void setBounds(int leftE6, int topE6, int rightE6, int bottomE6) { - latitudeExtremities.set(bottomE6 / 1E6, topE6 / 1E6); - longitudeExtremities.set(leftE6 / 1E6, rightE6 / 1E6); - } - - /** - * Updates a new latitude value. - * - * @param latitude the latitude value in signed decimal degrees - */ - void updateLatitudeExtremities(double latitude) { - latitudeExtremities.update(latitude); - } - - /** - * Updates a new longitude value. - * - * @param longitude the longitude value in signed decimal degrees - */ - void updateLongitudeExtremities(double longitude) { - longitudeExtremities.update(longitude); - } - /** * Sets the maximum speed. * @@ -408,6 +369,14 @@ public class TripStatistics implements Parcelable { this.maxSpeed = maxSpeed; } + /** + * Gets the minimum elevation. This is calculated from the smoothed elevation + * so this can actually be more than the current elevation. + */ + public double getMinElevation() { + return elevationExtremities.getMin(); + } + /** * Sets the minimum elevation. * @@ -417,6 +386,14 @@ public class TripStatistics implements Parcelable { elevationExtremities.setMin(elevation); } + /** + * Gets the maximum elevation. This is calculated from the smoothed elevation + * so this can actually be less than the current elevation. + */ + public double getMaxElevation() { + return elevationExtremities.getMax(); + } + /** * Sets the maximum elevation. * @@ -431,10 +408,18 @@ public class TripStatistics implements Parcelable { * * @param elevation the elevation value in meters */ - void updateElevationExtremities(double elevation) { + public void updateElevationExtremities(double elevation) { elevationExtremities.update(elevation); } + /** + * Gets the total elevation gain in meters. This is calculated as the sum of + * all positive differences in the smoothed elevation. + */ + public double getTotalElevationGain() { + return totalElevationGain; + } + /** * Sets the total elevation gain. * @@ -449,17 +434,15 @@ public class TripStatistics implements Parcelable { * * @param gain the elevation gain in meters */ - void addTotalElevationGain(double gain) { + public void addTotalElevationGain(double gain) { totalElevationGain += gain; } /** - * Sets the minimum grade. - * - * @param grade the grade as a fraction (-1.0 would mean vertical downwards) + * Gets the minimum grade for this trip. */ - public void setMinGrade(double grade) { - gradeExtremities.setMin(grade); + public double getMinGrade() { + return gradeExtremities.getMin(); } /** @@ -471,23 +454,38 @@ public class TripStatistics implements Parcelable { gradeExtremities.setMax(grade); } + /** + * Gets the maximum grade for this trip. + */ + public double getMaxGrade() { + return gradeExtremities.getMax(); + } + + /** + * Sets the minimum grade. + * + * @param grade the grade as a fraction (-1.0 would mean vertical downwards) + */ + public void setMinGrade(double grade) { + gradeExtremities.setMin(grade); + } + /** * Updates a new grade value. * * @param grade the grade value as a fraction */ - void updateGradeExtremities(double grade) { + public void updateGradeExtremities(double grade) { gradeExtremities.update(grade); } @Override public String toString() { return "TripStatistics { Start Time: " + getStartTime() + "; Stop Time: " + getStopTime() - + "; Total Time: " + getTotalTime() + "; Total Distance: " + getTotalDistance() - + "; Total Time: " + getTotalTime() + "; Moving Time: " + getMovingTime() - + "; Min Latitude: " + getBottomDegrees() + "; Max Latitude: " + getTopDegrees() - + "; Min Longitude: " + getLeftDegrees() + "; Max Longitude: " + getRightDegrees() - + "; Max Elevation: " + getMaxElevation() + "; Max Speed: " + getMaxSpeed() + + "; Total Distance: " + getTotalDistance() + "; Total Time: " + getTotalTime() + + "; Moving Time: " + getMovingTime() + "; Min Latitude: " + getBottomDegrees() + + "; Max Latitude: " + getTopDegrees() + "; Min Longitude: " + getLeftDegrees() + + "; Max Longitude: " + getRightDegrees() + "; Max Speed: " + getMaxSpeed() + "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation() + "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade() + "; Max Grade: " + getMaxGrade() + "}";