forked from upstream-mirrors/OpenTracks
Bugfix: formatting of pace was not formatted correctly (e.g., 4:60).
Fixes #370.
This commit is contained in:
@@ -253,7 +253,7 @@ public class ChartFragmentTest {
|
||||
trackPoint2.setTime(trackPoint1.getTime() + 222);
|
||||
trackPoint2.setSpeed(130);
|
||||
point = chartFragment.createPendingPoint(trackPoint2);
|
||||
Assert.assertEquals(130.0 * UnitConversions.MS_TO_KMH, point.getSpeed(), 0.01);
|
||||
Assert.assertEquals(130.0 * UnitConversions.MPS_TO_KMH, point.getSpeed(), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +278,7 @@ public class ChartFragmentTest {
|
||||
trackPoint2.setTime(trackPoint2.getTime() + 222);
|
||||
trackPoint2.setSpeed(102);
|
||||
point = chartFragment.createPendingPoint(trackPoint2);
|
||||
Assert.assertEquals(102.0 * UnitConversions.MS_TO_KMH * UnitConversions.KM_TO_MI, point.getSpeed(), 0.01);
|
||||
Assert.assertEquals(102.0 * UnitConversions.MPS_TO_KMH * UnitConversions.KM_TO_MI, point.getSpeed(), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +303,7 @@ public class ChartFragmentTest {
|
||||
trackPoint2.setTime(trackPoint2.getTime() + 222);
|
||||
trackPoint2.setSpeed(102);
|
||||
point = chartFragment.createPendingPoint(trackPoint2);
|
||||
Assert.assertEquals(HOURS_PER_UNIT / (102.0 * UnitConversions.MS_TO_KMH), point.getPace(), 0.01);
|
||||
Assert.assertEquals(HOURS_PER_UNIT / (102.0 * UnitConversions.MPS_TO_KMH), point.getPace(), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,4 +212,16 @@ public class StringUtilsTest {
|
||||
|
||||
Assert.assertEquals("1", StringUtils.formatDecimal(0.99, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSpeedParts() {
|
||||
Assert.assertEquals("4:59", StringUtils.getSpeedParts(context, 3.34, true, false).first);
|
||||
Assert.assertEquals("5:00", StringUtils.getSpeedParts(context, 3.33, true, false).first);
|
||||
|
||||
Assert.assertEquals("11.99", StringUtils.getSpeedParts(context, 3.33, true, true).first);
|
||||
Assert.assertEquals("7.45", StringUtils.getSpeedParts(context, 3.33, false, true).first);
|
||||
|
||||
Assert.assertEquals("min/km", StringUtils.getSpeedParts(context, 0, true, false).second);
|
||||
Assert.assertEquals("min/mi", StringUtils.getSpeedParts(context, 0, false, false).second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ChartPoint {
|
||||
elevation *= UnitConversions.M_TO_FT;
|
||||
}
|
||||
|
||||
speed = trackStatisticsUpdater.getSmoothedSpeed() * UnitConversions.MS_TO_KMH;
|
||||
speed = trackStatisticsUpdater.getSmoothedSpeed() * UnitConversions.MPS_TO_KMH;
|
||||
if (!metricUnits) {
|
||||
speed *= UnitConversions.KM_TO_MI;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class DescriptionGenerator {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void writeSpeed(double speed, StringBuilder builder, int resId, String lineBreak) {
|
||||
double speedInKmHr = speed * UnitConversions.MS_TO_KMH;
|
||||
double speedInKmHr = speed * UnitConversions.MPS_TO_KMH;
|
||||
double speedInMiHr = speedInKmHr * UnitConversions.KM_TO_MI;
|
||||
builder.append(context.getString(resId, speedInKmHr, speedInMiHr));
|
||||
builder.append(lineBreak);
|
||||
|
||||
@@ -13,7 +13,7 @@ public class AnnouncementUtils {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(context, category);
|
||||
double distance = trackStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||
double distancePerTime = trackStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH;
|
||||
double distancePerTime = trackStatistics.getAverageMovingSpeed() * UnitConversions.MPS_TO_KMH;
|
||||
|
||||
if (distance == 0) {
|
||||
return context.getString(R.string.voice_total_distance_zero);
|
||||
|
||||
@@ -227,19 +227,19 @@ public class StringUtils {
|
||||
speed_mps = 0;
|
||||
}
|
||||
|
||||
speed_mps *= UnitConversions.MS_TO_KMH;
|
||||
double speed = speed_mps * UnitConversions.M_TO_KM; //KM p sec
|
||||
if (!metricUnits) {
|
||||
speed_mps *= UnitConversions.KM_TO_MI;
|
||||
speed *= UnitConversions.KM_TO_MI;
|
||||
}
|
||||
|
||||
if (reportSpeed) {
|
||||
return new Pair<>(StringUtils.formatDecimal(speed_mps), unitString);
|
||||
return new Pair<>(StringUtils.formatDecimal(speed * UnitConversions.S_TO_HR), unitString);
|
||||
}
|
||||
|
||||
// convert from hours to minutes
|
||||
double pace = speed_mps == 0 ? 0.0 : 60.0 / speed_mps;
|
||||
int minutes = (int) pace;
|
||||
int seconds = (int) Math.round((pace - minutes) * 60.0);
|
||||
int pace = speed == 0 ? 0 : (int) Math.round(1 / speed); //sec / [KM | MI]
|
||||
|
||||
int minutes = pace / 60;
|
||||
int seconds = pace % 60;
|
||||
return new Pair<>(String.format(Locale.US, "%d:%02d", minutes, seconds), unitString);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ public class UnitConversions {
|
||||
public static final double HR_TO_MIN = 60.0;
|
||||
// multiplication factor to convert minutes to hours
|
||||
public static final double MIN_TO_HR = 1 / HR_TO_MIN;
|
||||
public static final double S_TO_HR = 1d / (S_TO_MIN * MIN_TO_HR);
|
||||
|
||||
// multiplication factor to convert kilometers to miles
|
||||
public static final double KM_TO_MI = 0.621371192;
|
||||
|
||||
@@ -62,7 +64,7 @@ public class UnitConversions {
|
||||
// multiplication factor to convert meters to feet
|
||||
public static final double M_TO_FT = M_TO_MI * MI_TO_FT;
|
||||
// multiplication factor to convert meters per second to kilometers per hour
|
||||
public static final double MS_TO_KMH = M_TO_KM / (S_TO_MIN * MIN_TO_HR);
|
||||
public static final double MPS_TO_KMH = M_TO_KM / (S_TO_MIN * MIN_TO_HR);
|
||||
|
||||
// Others
|
||||
// multiplication factor to convert degrees to radians
|
||||
|
||||
Reference in New Issue
Block a user