mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
In TripStatistics, return 0 for average speed and moving speed
when the denominator is zero. Use "1000.0" when getting a double by dividing by 1000.
This commit is contained in:
@@ -213,7 +213,7 @@ public class StatsUtilities {
|
||||
double minElevation, double maxElevation, double elevationGain,
|
||||
double minGrade, double maxGrade) {
|
||||
setTime(R.id.moving_time_register, movingTime);
|
||||
setDistance(R.id.total_distance_register, totalDistance / 1000);
|
||||
setDistance(R.id.total_distance_register, totalDistance / 1000.0);
|
||||
setSpeed(R.id.average_speed_register, averageSpeed * 3.6);
|
||||
setSpeed(R.id.average_moving_speed_register, averageMovingSpeed * 3.6);
|
||||
setSpeed(R.id.max_speed_register, maxSpeed * 3.6);
|
||||
@@ -226,7 +226,7 @@ public class StatsUtilities {
|
||||
|
||||
public void setAllStats(TripStatistics stats) {
|
||||
setTime(R.id.moving_time_register, stats.getMovingTime());
|
||||
setDistance(R.id.total_distance_register, stats.getTotalDistance() / 1000);
|
||||
setDistance(R.id.total_distance_register, stats.getTotalDistance() / 1000.0);
|
||||
setSpeed(R.id.average_speed_register, stats.getAverageSpeed() * 3.6);
|
||||
setSpeed(R.id.average_moving_speed_register,
|
||||
stats.getAverageMovingSpeed() * 3.6);
|
||||
|
||||
@@ -333,8 +333,8 @@ public class TrackList extends ListActivity
|
||||
double length = cursor.getDouble(totalDistanceIdx);
|
||||
String lengthUnit = null;
|
||||
if (metricUnits) {
|
||||
if (length > 1000) {
|
||||
length /= 1000;
|
||||
if (length > 1000.0) {
|
||||
length /= 1000.0;
|
||||
lengthUnit = getString(R.string.unit_kilometer);
|
||||
} else {
|
||||
lengthUnit = getString(R.string.unit_meter);
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class PeriodicTaskExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
double distance = service.getTripStatistics().getTotalDistance() / 1000;
|
||||
double distance = service.getTripStatistics().getTotalDistance() / 1000.0;
|
||||
if (!metricUnits) {
|
||||
distance *= UnitConversions.KM_TO_MI;
|
||||
}
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
||||
reportSpeed = preferences.getBoolean(context.getString(R.string.report_speed_key), true);
|
||||
}
|
||||
|
||||
double d = stats.getTotalDistance() / 1000; // d is in kilometers
|
||||
double d = stats.getTotalDistance() / 1000.0; // d is in kilometers
|
||||
double s = stats.getAverageMovingSpeed() * 3.6; // s is in kilometers per hour
|
||||
|
||||
if (d == 0) {
|
||||
|
||||
@@ -226,7 +226,7 @@ public class StringUtils implements DescriptionGenerator {
|
||||
}
|
||||
|
||||
TripStatistics trackStats = track.getStatistics();
|
||||
final double distanceInKm = trackStats.getTotalDistance() / 1000;
|
||||
final double distanceInKm = trackStats.getTotalDistance() / 1000.0;
|
||||
final double distanceInMiles = distanceInKm * UnitConversions.KM_TO_MI;
|
||||
final long minElevationInMeters = Math.round(trackStats.getMinElevation());
|
||||
final long minElevationInFeet =
|
||||
@@ -391,7 +391,7 @@ public class StringUtils implements DescriptionGenerator {
|
||||
public String generateWaypointDescription(Waypoint waypoint) {
|
||||
TripStatistics stats = waypoint.getStatistics();
|
||||
|
||||
final double distanceInKm = stats.getTotalDistance() / 1000;
|
||||
final double distanceInKm = stats.getTotalDistance() / 1000.0;
|
||||
final double distanceInMiles = distanceInKm * UnitConversions.KM_TO_MI;
|
||||
final double averageSpeedInKmh = stats.getAverageSpeed() * 3.6;
|
||||
final double averageSpeedInMph =
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class UnitConversions {
|
||||
public static final double M_TO_FT = 3.2808399;
|
||||
public static final double MI_TO_M = 1609.344;
|
||||
public static final double MI_TO_FEET = 5280.0;
|
||||
public static final double KMH_TO_MPH = 1000 * M_TO_FT / MI_TO_FEET;
|
||||
public static final double KMH_TO_MPH = 1000.0 * M_TO_FT / MI_TO_FEET;
|
||||
public static final double TO_RADIANS = Math.PI / 180.0;
|
||||
public static final double MPH_TO_KMH = 1.609344;
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ public class TrackWidgetProvider
|
||||
|
||||
// TODO replace this with format strings and miles.
|
||||
// convert meters to kilometers
|
||||
double displayDistance = stats.getTotalDistance() / 1000;
|
||||
double displayDistance = stats.getTotalDistance() / 1000.0;
|
||||
if (!isMetric) {
|
||||
displayDistance *= UnitConversions.KM_TO_MI;
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ public class TripStatistics implements Parcelable {
|
||||
* The start time for the trip. This is system time which might not match gps
|
||||
* time.
|
||||
*/
|
||||
private long startTime = -1;
|
||||
private long startTime = -1L;
|
||||
|
||||
/**
|
||||
* The stop time for the trip. This is the system time which might not match
|
||||
* gps time.
|
||||
*/
|
||||
private long stopTime = -1;
|
||||
private long stopTime = -1L;
|
||||
|
||||
/**
|
||||
* The total time that we believe the user was traveling in milliseconds.
|
||||
@@ -191,7 +191,10 @@ public class TripStatistics implements Parcelable {
|
||||
* @return The average speed in m/s
|
||||
*/
|
||||
public double getAverageSpeed() {
|
||||
return totalDistance / ((double) totalTime / 1000);
|
||||
if (totalTime == 0L) {
|
||||
return 0.0;
|
||||
}
|
||||
return totalDistance / ((double) totalTime / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +204,10 @@ public class TripStatistics implements Parcelable {
|
||||
* @return The average moving speed in m/s
|
||||
*/
|
||||
public double getAverageMovingSpeed() {
|
||||
return totalDistance / ((double) movingTime / 1000);
|
||||
if (movingTime == 0L) {
|
||||
return 0.0;
|
||||
}
|
||||
return totalDistance / ((double) movingTime / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user