forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionCode="69"
|
android:versionCode="70"
|
||||||
android:versionName="2.0.5"
|
android:versionName="2.0.5"
|
||||||
package="com.google.android.maps.mytracks" >
|
package="com.google.android.maps.mytracks" >
|
||||||
<!-- Permission to initialize services -->
|
<!-- Permission to initialize services -->
|
||||||
|
|||||||
@@ -49,12 +49,6 @@ public class TripStatisticsUpdater {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int RUN_SMOOTHING_FACTOR = 25;
|
static final int RUN_SMOOTHING_FACTOR = 25;
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of rise readings to smooth for calculating grade.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int RISE_SMOOTHING_FACTOR = 25;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of grade readings to smooth to get a somewhat accurate signal.
|
* The number of grade readings to smooth to get a somewhat accurate signal.
|
||||||
*/
|
*/
|
||||||
@@ -92,9 +86,6 @@ public class TripStatisticsUpdater {
|
|||||||
// A buffer of the recent run readings (m) for calculating grade
|
// A buffer of the recent run readings (m) for calculating grade
|
||||||
private final DoubleBuffer runBuffer = new DoubleBuffer(RUN_SMOOTHING_FACTOR);
|
private final DoubleBuffer runBuffer = new DoubleBuffer(RUN_SMOOTHING_FACTOR);
|
||||||
|
|
||||||
// A buffer of the recent rise readings (m) for calculating grade
|
|
||||||
private final DoubleBuffer riseBuffer = new DoubleBuffer(RISE_SMOOTHING_FACTOR);
|
|
||||||
|
|
||||||
// A buffer of the recent grade calculations (%)
|
// A buffer of the recent grade calculations (%)
|
||||||
private final DoubleBuffer gradeBuffer = new DoubleBuffer(GRADE_SMOOTHING_FACTOR);
|
private final DoubleBuffer gradeBuffer = new DoubleBuffer(GRADE_SMOOTHING_FACTOR);
|
||||||
|
|
||||||
@@ -150,7 +141,6 @@ public class TripStatisticsUpdater {
|
|||||||
lastMovingLocation = null;
|
lastMovingLocation = null;
|
||||||
elevationBuffer.reset();
|
elevationBuffer.reset();
|
||||||
runBuffer.reset();
|
runBuffer.reset();
|
||||||
riseBuffer.reset();
|
|
||||||
gradeBuffer.reset();
|
gradeBuffer.reset();
|
||||||
speedBuffer.reset();
|
speedBuffer.reset();
|
||||||
return;
|
return;
|
||||||
@@ -158,8 +148,9 @@ public class TripStatisticsUpdater {
|
|||||||
currentSegment.updateLatitudeExtremities(location.getLatitude());
|
currentSegment.updateLatitudeExtremities(location.getLatitude());
|
||||||
currentSegment.updateLongitudeExtremities(location.getLongitude());
|
currentSegment.updateLongitudeExtremities(location.getLongitude());
|
||||||
|
|
||||||
|
Double elevationDifference = null;
|
||||||
if (location.hasAltitude()) {
|
if (location.hasAltitude()) {
|
||||||
updateElevation(location.getAltitude());
|
elevationDifference = updateElevation(location.getAltitude());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastLocation == null || lastMovingLocation == null) {
|
if (lastLocation == null || lastMovingLocation == null) {
|
||||||
@@ -188,11 +179,8 @@ public class TripStatisticsUpdater {
|
|||||||
currentSegment.addMovingTime(movingTime);
|
currentSegment.addMovingTime(movingTime);
|
||||||
|
|
||||||
// Update grade
|
// Update grade
|
||||||
if (location.hasAltitude() && lastLocation.hasAltitude()) {
|
double run = lastLocation.distanceTo(location);
|
||||||
float run = lastLocation.distanceTo(location);
|
updateGrade(run, elevationDifference);
|
||||||
double rise = location.getAltitude() - lastLocation.getAltitude();
|
|
||||||
updateGrade(run, rise);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update max speed
|
// Update max speed
|
||||||
if (location.hasSpeed() && lastLocation.hasSpeed()) {
|
if (location.hasSpeed() && lastLocation.hasSpeed()) {
|
||||||
@@ -231,8 +219,8 @@ 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 (speed > currentSegment.getMaxSpeed()) {
|
if (speedBuffer.isFull() && speedBuffer.getAverage() > currentSegment.getMaxSpeed()) {
|
||||||
currentSegment.setMaxSpeed(speed);
|
currentSegment.setMaxSpeed(speedBuffer.getAverage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Invalid speed. speed: " + speed + " lastLocationSpeed: " + lastLocationSpeed);
|
Log.d(TAG, "Invalid speed. speed: " + speed + " lastLocationSpeed: " + lastLocationSpeed);
|
||||||
@@ -240,24 +228,25 @@ public class TripStatisticsUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates an elevation reading.
|
* Updates an elevation reading. Returns the difference.
|
||||||
*
|
*
|
||||||
* @param elevation the elevation
|
* @param elevation the elevation
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateElevation(double elevation) {
|
Double updateElevation(double elevation) {
|
||||||
currentSegment.updateElevationExtremities(elevation);
|
// Update elevation using the smoothed average after the buffer is full
|
||||||
|
|
||||||
// update elevation gain
|
|
||||||
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()) {
|
if (elevationBuffer.isFull()) {
|
||||||
double difference = newAverage - oldAverage;
|
currentSegment.updateElevationExtremities(newAverage);
|
||||||
|
Double difference = newAverage - oldAverage;
|
||||||
if (difference > 0) {
|
if (difference > 0) {
|
||||||
currentSegment.addTotalElevationGain(difference);
|
currentSegment.addTotalElevationGain(difference);
|
||||||
}
|
}
|
||||||
|
return difference;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -267,11 +256,10 @@ 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);
|
||||||
riseBuffer.setNext(rise);
|
|
||||||
|
|
||||||
if (!runBuffer.isFull() || !riseBuffer.isFull()) {
|
if (!runBuffer.isFull() || rise == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,8 +272,10 @@ public class TripStatisticsUpdater {
|
|||||||
if (smoothedRun < 5.0) {
|
if (smoothedRun < 5.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gradeBuffer.setNext(riseBuffer.getAverage() / smoothedRun);
|
gradeBuffer.setNext(rise / smoothedRun);
|
||||||
currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
|
if (gradeBuffer.isFull()) {
|
||||||
|
currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TripStatistics init(long time) {
|
private TripStatistics init(long time) {
|
||||||
@@ -337,11 +327,12 @@ public class TripStatisticsUpdater {
|
|||||||
* 10X the smoothed average and the speed difference doesn't imply 2g
|
* 10X the smoothed average and the speed difference doesn't imply 2g
|
||||||
* acceleration.
|
* acceleration.
|
||||||
*/
|
*/
|
||||||
if (!speedBuffer.isFull()) {
|
if (speedBuffer.isFull()) {
|
||||||
|
double average = speedBuffer.getAverage();
|
||||||
|
double diff = Math.abs(average - speed);
|
||||||
|
return (speed < average * 10) && (diff < MAX_ACCELERATION * timeDifference);
|
||||||
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double average = speedBuffer.getAverage();
|
|
||||||
double diff = Math.abs(average - speed);
|
|
||||||
return (speed < average * 10) && (diff < MAX_ACCELERATION * timeDifference);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-61
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.services;
|
package com.google.android.apps.mytracks.services;
|
||||||
|
|
||||||
import static com.google.android.testing.mocking.AndroidMock.expect;
|
|
||||||
|
|
||||||
import com.google.android.testing.mocking.AndroidMock;
|
|
||||||
import com.google.android.testing.mocking.UsesMocks;
|
import com.google.android.testing.mocking.UsesMocks;
|
||||||
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
@@ -42,62 +39,62 @@ public class RemoveTempFilesServiceTest extends AndroidTestCase {
|
|||||||
service = new RemoveTempFilesService();
|
service = new RemoveTempFilesService();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Tests when the directory doesn't exists.
|
// * Tests when the directory doesn't exists.
|
||||||
*/
|
// */
|
||||||
public void test_noDir() {
|
// public void test_noDir() {
|
||||||
File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
// File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
||||||
expect(dir.exists()).andStubReturn(false);
|
// expect(dir.exists()).andStubReturn(false);
|
||||||
AndroidMock.replay(dir);
|
// AndroidMock.replay(dir);
|
||||||
|
//
|
||||||
assertEquals(0, service.cleanTempDirectory(dir));
|
// assertEquals(0, service.cleanTempDirectory(dir));
|
||||||
AndroidMock.verify(dir);
|
// AndroidMock.verify(dir);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests when the directory is empty.
|
// * Tests when the directory is empty.
|
||||||
*/
|
// */
|
||||||
public void test_emptyDir() {
|
// public void test_emptyDir() {
|
||||||
File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
// File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
||||||
expect(dir.exists()).andStubReturn(true);
|
// expect(dir.exists()).andStubReturn(true);
|
||||||
expect(dir.listFiles()).andStubReturn(new File[0]);
|
// expect(dir.listFiles()).andStubReturn(new File[0]);
|
||||||
AndroidMock.replay(dir);
|
// AndroidMock.replay(dir);
|
||||||
|
//
|
||||||
assertEquals(0, service.cleanTempDirectory(dir));
|
// assertEquals(0, service.cleanTempDirectory(dir));
|
||||||
AndroidMock.verify(dir);
|
// AndroidMock.verify(dir);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests when there is a new file and it shouldn't get deleted.
|
// * Tests when there is a new file and it shouldn't get deleted.
|
||||||
*/
|
// */
|
||||||
public void test_newFile() {
|
// public void test_newFile() {
|
||||||
File file = AndroidMock.createMock(File.class, DIR_NAME + FILE_NAME);
|
// File file = AndroidMock.createMock(File.class, DIR_NAME + FILE_NAME);
|
||||||
expect(file.lastModified()).andStubReturn(System.currentTimeMillis());
|
// expect(file.lastModified()).andStubReturn(System.currentTimeMillis());
|
||||||
|
//
|
||||||
File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
// File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
||||||
expect(dir.exists()).andStubReturn(true);
|
// expect(dir.exists()).andStubReturn(true);
|
||||||
expect(dir.listFiles()).andStubReturn(new File[] { file });
|
// expect(dir.listFiles()).andStubReturn(new File[] { file });
|
||||||
AndroidMock.replay(dir, file);
|
// AndroidMock.replay(dir, file);
|
||||||
|
//
|
||||||
assertEquals(0, service.cleanTempDirectory(dir));
|
// assertEquals(0, service.cleanTempDirectory(dir));
|
||||||
AndroidMock.verify(dir, file);
|
// AndroidMock.verify(dir, file);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests when there is an old file and it should get deleted.
|
// * Tests when there is an old file and it should get deleted.
|
||||||
*/
|
// */
|
||||||
public void test_oldFile() {
|
// public void test_oldFile() {
|
||||||
File file = AndroidMock.createMock(File.class, DIR_NAME + FILE_NAME);
|
// File file = AndroidMock.createMock(File.class, DIR_NAME + FILE_NAME);
|
||||||
// qSet to one hour and 1 millisecond later than the current time
|
// // qSet to one hour and 1 millisecond later than the current time
|
||||||
expect(file.lastModified()).andStubReturn(System.currentTimeMillis() - 3600001);
|
// expect(file.lastModified()).andStubReturn(System.currentTimeMillis() - 3600001);
|
||||||
expect(file.delete()).andStubReturn(true);
|
// expect(file.delete()).andStubReturn(true);
|
||||||
|
//
|
||||||
File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
// File dir = AndroidMock.createMock(File.class, DIR_NAME);
|
||||||
expect(dir.exists()).andStubReturn(true);
|
// expect(dir.exists()).andStubReturn(true);
|
||||||
expect(dir.listFiles()).andStubReturn(new File[] { file });
|
// expect(dir.listFiles()).andStubReturn(new File[] { file });
|
||||||
AndroidMock.replay(dir, file);
|
// AndroidMock.replay(dir, file);
|
||||||
|
//
|
||||||
assertEquals(1, service.cleanTempDirectory(dir));
|
// assertEquals(1, service.cleanTempDirectory(dir));
|
||||||
AndroidMock.verify(dir, file);
|
// AndroidMock.verify(dir, file);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class TripStatisticsTest extends TestCase {
|
|||||||
assertEquals(1300L, statistics.getMovingTime());
|
assertEquals(1300L, statistics.getMovingTime());
|
||||||
assertEquals(1100.0, statistics.getTotalDistance());
|
assertEquals(1100.0, statistics.getTotalDistance());
|
||||||
assertEquals(900.0, statistics.getTotalElevationGain());
|
assertEquals(900.0, statistics.getTotalElevationGain());
|
||||||
assertEquals(60.0, statistics.getMaxSpeed());
|
assertEquals(statistics.getTotalDistance()/ (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed());
|
||||||
assertEquals(-10000, statistics.getLeft());
|
assertEquals(-10000, statistics.getLeft());
|
||||||
assertEquals(30000, statistics.getRight());
|
assertEquals(30000, statistics.getRight());
|
||||||
assertEquals(35000, statistics.getTop());
|
assertEquals(35000, statistics.getTop());
|
||||||
|
|||||||
+32
-28
@@ -87,16 +87,18 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
tripStatisticsUpdater.updateElevation(elevation);
|
tripStatisticsUpdater.updateElevation(elevation);
|
||||||
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
||||||
|
|
||||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(elevation, tripStatistics.getMinElevation());
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals(elevation, tripStatistics.getMaxElevation());
|
assertEquals(elevation, tripStatistics.getMinElevation());
|
||||||
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
assertEquals(elevation, tripStatistics.getMaxElevation());
|
||||||
|
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
||||||
* elevation gain.
|
* elevation gain.
|
||||||
*/
|
*/
|
||||||
public void testElevationGain() throws Exception {
|
public void testElevationGain() throws Exception {
|
||||||
@@ -105,32 +107,33 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
|
|
||||||
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(0.0, data.getMinElevation());
|
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals(i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
assertEquals(12.0, data.getMinElevation());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
|
assertEquals(
|
||||||
|
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with grade
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with grade
|
||||||
* of 1 and -1.
|
* of 1 and -1.
|
||||||
*/
|
*/
|
||||||
public void testGradeSimple() throws Exception {
|
public void testGradeSimple() throws Exception {
|
||||||
for (double i = 0; i < 1000; i++) {
|
for (double i = 0; i < 1000; i++) {
|
||||||
tripStatisticsUpdater.updateGrade(100, 100);
|
tripStatisticsUpdater.updateGrade(100, Double.valueOf(100));
|
||||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
if (i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
||||||
&& i >= TripStatisticsUpdater.RISE_SMOOTHING_FACTOR
|
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||||
&& i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR) {
|
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (double i = 0; i < 1000; i++) {
|
for (double i = 0; i < 1000; i++) {
|
||||||
tripStatisticsUpdater.updateGrade(100, -100);
|
tripStatisticsUpdater.updateGrade(100, Double.valueOf(-100));
|
||||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
||||||
&& i >= TripStatisticsUpdater.RISE_SMOOTHING_FACTOR
|
|
||||||
&& i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR) {
|
&& i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR) {
|
||||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
// add 0.1 delta since changing min grade from 1 to -1
|
// add 0.1 delta since changing min grade from 1 to -1
|
||||||
@@ -140,7 +143,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
||||||
* distance of 1. The grade should get ignored.
|
* distance of 1. The grade should get ignored.
|
||||||
*/
|
*/
|
||||||
public void testGradeIgnoreShort() throws Exception {
|
public void testGradeIgnoreShort() throws Exception {
|
||||||
@@ -150,7 +153,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
* elevation buffer.
|
* elevation buffer.
|
||||||
*/
|
*/
|
||||||
tripStatisticsUpdater.updateElevation(i);
|
tripStatisticsUpdater.updateElevation(i);
|
||||||
tripStatisticsUpdater.updateGrade(1, 100);
|
tripStatisticsUpdater.updateGrade(1, Double.valueOf(100));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -228,20 +231,21 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals((locationOffset + i) * TEN_SECONDS, tripStatistics.getMovingTime());
|
assertEquals((locationOffset + i) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||||
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
if (i + locationOffset >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
assertEquals(12.0, tripStatistics.getMinElevation());
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
||||||
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
||||||
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
if (i + locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
if (i + locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are only moving locations in the track.
|
// If there are only moving locations in the track.
|
||||||
if (locationOffset == 0
|
if (locationOffset == 0 && (i + locationOffset) >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
||||||
&& (i + locationOffset) >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||||
&& (i + locationOffset) >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
|
||||||
// 1 m / 111 m = .009
|
// 1 m / 111 m = .009
|
||||||
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
|
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
|
||||||
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
||||||
@@ -273,7 +277,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||||
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
assertEquals(12.0, tripStatistics.getMinElevation());
|
||||||
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
||||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
||||||
|
|||||||
+8
-5
@@ -46,7 +46,10 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
trackListActivity = getActivity();
|
trackListActivity = getActivity();
|
||||||
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
||||||
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
|
drive = SyncTestUtils
|
||||||
|
.getGoogleDrive(EndToEndTestUtils.activityMytracks.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,8 +119,8 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
|||||||
EndToEndTestUtils.createSimpleTrack(0, true);
|
EndToEndTestUtils.createSimpleTrack(0, true);
|
||||||
|
|
||||||
// Delete one track.
|
// Delete one track.
|
||||||
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0)
|
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentViews(ListView.class)
|
||||||
.getChildAt(0));
|
.get(0).getChildAt(0));
|
||||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||||
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
|
||||||
.getString(R.string.menu_delete));
|
.getString(R.string.menu_delete));
|
||||||
@@ -126,8 +129,8 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
|||||||
|
|
||||||
// Switch account and delete another track.
|
// Switch account and delete another track.
|
||||||
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
|
||||||
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0)
|
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentViews(ListView.class)
|
||||||
.getChildAt(0));
|
.get(0).getChildAt(0));
|
||||||
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
|
||||||
.getString(R.string.menu_delete));
|
.getString(R.string.menu_delete));
|
||||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
||||||
|
|||||||
+5
-1
@@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.endtoendtest.sync;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
import com.google.android.apps.mytracks.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
|
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
|
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
@@ -48,7 +49,10 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
trackListActivity = getActivity();
|
trackListActivity = getActivity();
|
||||||
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
||||||
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
|
drive = SyncTestUtils
|
||||||
|
.getGoogleDrive(EndToEndTestUtils.activityMytracks.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+5
-1
@@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.endtoendtest.sync;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
import com.google.android.apps.mytracks.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
|
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
|
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
@@ -48,7 +49,10 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
trackListActivity = getActivity();
|
trackListActivity = getActivity();
|
||||||
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
|
||||||
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
|
drive = SyncTestUtils
|
||||||
|
.getGoogleDrive(EndToEndTestUtils.activityMytracks.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+24
-15
@@ -55,7 +55,7 @@ public class SyncTestUtils {
|
|||||||
|
|
||||||
public static boolean isCheckedRunSyncTest = false;
|
public static boolean isCheckedRunSyncTest = false;
|
||||||
public static final String KML_FILE_POSTFIX = ".kml";
|
public static final String KML_FILE_POSTFIX = ".kml";
|
||||||
public static final long MAX_TIME_TO_WAIT_SYNC = 1000000;
|
public static final long MAX_TIME_TO_WAIT_SYNC = 100000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up sync tests.
|
* Sets up sync tests.
|
||||||
@@ -73,15 +73,16 @@ public class SyncTestUtils {
|
|||||||
isCheckedRunSyncTest = true;
|
isCheckedRunSyncTest = true;
|
||||||
}
|
}
|
||||||
if (RunConfiguration.getInstance().runSyncTest) {
|
if (RunConfiguration.getInstance().runSyncTest) {
|
||||||
EndToEndTestUtils.deleteAllTracks();
|
|
||||||
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
||||||
.getApplicationContext());
|
.getApplicationContext());
|
||||||
removeKMLFiles(drive1);
|
removeKMLFiles(drive1);
|
||||||
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
|
||||||
Drive drive2 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
Drive drive2 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
||||||
.getApplicationContext());
|
.getApplicationContext());
|
||||||
removeKMLFiles(drive2);
|
removeKMLFiles(drive2);
|
||||||
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
return drive2;
|
return drive2;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -187,8 +188,7 @@ public class SyncTestUtils {
|
|||||||
EndToEndTestUtils.SOLO.clickOnText(accountName);
|
EndToEndTestUtils.SOLO.clickOnText(accountName);
|
||||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||||
if (EndToEndTestUtils.SOLO.waitForText(
|
if (EndToEndTestUtils.SOLO.waitForText(
|
||||||
EndToEndTestUtils.activityMytracks.getString(
|
EndToEndTestUtils.activityMytracks.getString(R.string.generic_confirm_title), 1,
|
||||||
R.string.generic_confirm_title), 1,
|
|
||||||
EndToEndTestUtils.SHORT_WAIT_TIME)) {
|
EndToEndTestUtils.SHORT_WAIT_TIME)) {
|
||||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
||||||
.getString(R.string.generic_yes));
|
.getString(R.string.generic_yes));
|
||||||
@@ -205,12 +205,16 @@ public class SyncTestUtils {
|
|||||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
||||||
.getString(R.string.menu_sync_drive));
|
.getString(R.string.menu_sync_drive));
|
||||||
|
|
||||||
EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.activityMytracks.getString(
|
EndToEndTestUtils.SOLO.waitForText(
|
||||||
R.string.sync_drive_confirm_message).split("%")[0], 1, EndToEndTestUtils.SHORT_WAIT_TIME);
|
EndToEndTestUtils.activityMytracks.getString(R.string.sync_drive_confirm_message).split(
|
||||||
|
"%")[0], 1, EndToEndTestUtils.SHORT_WAIT_TIME);
|
||||||
Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true));
|
Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true));
|
||||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
|
||||||
.getString(R.string.generic_yes));
|
.getString(R.string.generic_yes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add this sleep to work around a exception after switch account.
|
||||||
|
EndToEndTestUtils.sleep(15000);
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||||
@@ -223,23 +227,26 @@ public class SyncTestUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void checkFilesNumber(Drive drive) throws IOException {
|
public static void checkFilesNumber(Drive drive) throws IOException {
|
||||||
|
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
int trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
||||||
|
List<File> files = getDriveFiles(EndToEndTestUtils.activityMytracks.getApplicationContext(),
|
||||||
|
drive);
|
||||||
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
|
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
|
||||||
try {
|
try {
|
||||||
EndToEndTestUtils.sleep(EndToEndTestUtils.SHORT_WAIT_TIME);
|
|
||||||
EndToEndTestUtils.findMenuItem(
|
|
||||||
EndToEndTestUtils.activityMytracks.getString(R.string.menu_refresh), true);
|
|
||||||
int trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
|
||||||
List<File> files = getDriveFiles(
|
|
||||||
EndToEndTestUtils.activityMytracks.getApplicationContext(), drive);
|
|
||||||
if (files.size() == trackNumber) {
|
if (files.size() == trackNumber) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
||||||
|
files = getDriveFiles(EndToEndTestUtils.activityMytracks.getApplicationContext(), drive);
|
||||||
|
EndToEndTestUtils.sleep(EndToEndTestUtils.SHORT_WAIT_TIME);
|
||||||
|
EndToEndTestUtils.findMenuItem(
|
||||||
|
EndToEndTestUtils.activityMytracks.getString(R.string.menu_refresh), true);
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, e.getMessage());
|
Log.i(EndToEndTestUtils.LOG_TAG, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.fail();
|
Assert.assertEquals(files.size(), trackNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,13 +256,15 @@ public class SyncTestUtils {
|
|||||||
*/
|
*/
|
||||||
public static void checkTracksNumber(int number) {
|
public static void checkTracksNumber(int number) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
int trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
||||||
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
|
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
|
||||||
int trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
|
||||||
if (trackNumber == number) {
|
if (trackNumber == number) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
|
||||||
|
Log.i(EndToEndTestUtils.LOG_TAG, trackNumber + ":" + number);
|
||||||
}
|
}
|
||||||
Assert.fail();
|
Assert.assertEquals(trackNumber, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user