forked from upstream-mirrors/OpenTracks
+32
-27
@@ -155,26 +155,31 @@ public class ExportImportTest {
|
|||||||
mockAltitudeChange(trackPointCreator, 1);
|
mockAltitudeChange(trackPointCreator, 1);
|
||||||
mockBLESensorData(trackPointCreator, 15f, sensorDistance, 66f, 3f, 50f);
|
mockBLESensorData(trackPointCreator, 15f, sensorDistance, 66f, 3f, 50f);
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:02:05Z");
|
trackPointCreator.setClock("2020-02-02T02:02:14Z");
|
||||||
|
mockBLESensorData(trackPointCreator, 15f, null, 66f, 3f, 50f);
|
||||||
|
trackPointCreator.setClock("2020-02-02T02:02:15Z");
|
||||||
|
mockBLESensorData(trackPointCreator, null, null, 66f, 3f, 50f);
|
||||||
|
|
||||||
|
trackPointCreator.setClock("2020-02-02T02:02:16Z");
|
||||||
mockBLESensorData(trackPointCreator, 5f, Distance.of(2), 66f, 3f, 50f); // Distance will be added to next TrackPoint
|
mockBLESensorData(trackPointCreator, 5f, Distance.of(2), 66f, 3f, 50f); // Distance will be added to next TrackPoint
|
||||||
|
|
||||||
sendLocation(trackPointCreator, "2020-02-02T02:02:05Z", 3, 14.001, 10, 13, 15, 10, 0);
|
sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3, 14.001, 10, 13, 15, 10, 0);
|
||||||
service.insertMarker("Marker 2", "Marker 2 category", "Marker 2 desc", null);
|
service.insertMarker("Marker 2", "Marker 2 category", "Marker 2 desc", null);
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:02:06Z");
|
trackPointCreator.setClock("2020-02-02T02:02:18Z");
|
||||||
trackPointCreator.setRemoteSensorManager(new BluetoothRemoteSensorManager(context, null, trackPointCreator));
|
trackPointCreator.setRemoteSensorManager(new BluetoothRemoteSensorManager(context, null, trackPointCreator));
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:02:20Z");
|
trackPointCreator.setClock("2020-02-02T02:03:20Z");
|
||||||
service.resumeTrack(trackId);
|
service.resumeTrack(trackId);
|
||||||
|
|
||||||
sendLocation(trackPointCreator, "2020-02-02T02:02:21Z", 3, 14.002, 10, 13, 15, 10, 0);
|
sendLocation(trackPointCreator, "2020-02-02T02:03:21Z", 3, 14.002, 10, 13, 15, 10, 0);
|
||||||
|
|
||||||
sendLocation(trackPointCreator, "2020-02-02T02:02:22Z", 3, 16, 10, 13, 15, 10, 0);
|
sendLocation(trackPointCreator, "2020-02-02T02:03:22Z", 3, 16, 10, 13, 15, 10, 0);
|
||||||
|
|
||||||
sendLocation(trackPointCreator, "2020-02-02T02:02:23Z", 3, 16.001, 10, 27, 15, 10, 0);
|
sendLocation(trackPointCreator, "2020-02-02T02:03:23Z", 3, 16.001, 10, 27, 15, 10, 0);
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:02:24Z");
|
trackPointCreator.setClock("2020-02-02T02:03:24Z");
|
||||||
trackPointCreator.setRemoteSensorManager(new BluetoothRemoteSensorManager(context, null, trackPointCreator));
|
trackPointCreator.setRemoteSensorManager(new BluetoothRemoteSensorManager(context, null, trackPointCreator));
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
@@ -187,7 +192,7 @@ public class ExportImportTest {
|
|||||||
track = contentProviderUtils.getTrack(trackId);
|
track = contentProviderUtils.getTrack(trackId);
|
||||||
trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
|
trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
|
||||||
markers = contentProviderUtils.getMarkers(trackId);
|
markers = contentProviderUtils.getMarkers(trackId);
|
||||||
assertEquals(10, trackPoints.size());
|
assertEquals(12, trackPoints.size());
|
||||||
assertEquals(2, markers.size());
|
assertEquals(2, markers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,29 +236,29 @@ public class ExportImportTest {
|
|||||||
// Time
|
// Time
|
||||||
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
|
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
|
||||||
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), importedTrackStatistics.getStartTime());
|
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), importedTrackStatistics.getStartTime());
|
||||||
assertEquals(Instant.parse("2020-02-02T02:02:24Z"), importedTrackStatistics.getStopTime());
|
assertEquals(Instant.parse("2020-02-02T02:03:24Z"), importedTrackStatistics.getStopTime());
|
||||||
|
|
||||||
TrackStatistics originalTrackStatistics = track.getTrackStatistics();
|
TrackStatistics originalTrackStatistics = track.getTrackStatistics();
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getTotalTime(), importedTrackStatistics.getTotalTime());
|
assertEquals(originalTrackStatistics.getTotalTime(), importedTrackStatistics.getTotalTime());
|
||||||
assertEquals(Duration.ofSeconds(7), importedTrackStatistics.getTotalTime());
|
assertEquals(Duration.ofSeconds(19), importedTrackStatistics.getTotalTime());
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getMovingTime(), importedTrackStatistics.getMovingTime());
|
assertEquals(originalTrackStatistics.getMovingTime(), importedTrackStatistics.getMovingTime());
|
||||||
assertEquals(Duration.ofSeconds(3), importedTrackStatistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(3), importedTrackStatistics.getMovingTime());
|
||||||
|
|
||||||
// Distance
|
// Distance
|
||||||
assertEquals(originalTrackStatistics.getTotalDistance(), importedTrackStatistics.getTotalDistance());
|
assertEquals(originalTrackStatistics.getTotalDistance(), importedTrackStatistics.getTotalDistance());
|
||||||
assertEquals(123.16, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
assertEquals(125.16, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
assertEquals(originalTrackStatistics.getMaxSpeed(), importedTrackStatistics.getMaxSpeed());
|
assertEquals(originalTrackStatistics.getMaxSpeed(), importedTrackStatistics.getMaxSpeed());
|
||||||
assertEquals(41.05, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(41.72, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getAverageSpeed(), importedTrackStatistics.getAverageSpeed());
|
assertEquals(originalTrackStatistics.getAverageSpeed(), importedTrackStatistics.getAverageSpeed());
|
||||||
assertEquals(17.59, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
assertEquals(6.58, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getAverageMovingSpeed(), importedTrackStatistics.getAverageMovingSpeed());
|
assertEquals(originalTrackStatistics.getAverageMovingSpeed(), importedTrackStatistics.getAverageMovingSpeed());
|
||||||
assertEquals(41.05, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(41.72, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
// Altitude
|
// Altitude
|
||||||
assertEquals(originalTrackStatistics.getMinAltitude(), importedTrackStatistics.getMinAltitude(), 0.01);
|
assertEquals(originalTrackStatistics.getMinAltitude(), importedTrackStatistics.getMinAltitude(), 0.01);
|
||||||
@@ -345,19 +350,19 @@ public class ExportImportTest {
|
|||||||
.setAltitudeLoss(1f)
|
.setAltitudeLoss(1f)
|
||||||
.setAltitudeGain(1f)
|
.setAltitudeGain(1f)
|
||||||
.setHorizontalAccuracy(Distance.of(10)),
|
.setHorizontalAccuracy(Distance.of(10)),
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:05Z"))
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:17Z"))
|
||||||
.setLatitude(3)
|
.setLatitude(3)
|
||||||
.setLongitude(14.001)
|
.setLongitude(14.001)
|
||||||
.setAltitude(10)
|
.setAltitude(10)
|
||||||
.setSpeed(Speed.of(5))
|
.setSpeed(Speed.of(5))
|
||||||
.setAltitudeLoss(1f)
|
.setAltitudeLoss(1f)
|
||||||
.setAltitudeGain(1f)
|
.setAltitudeGain(1f)
|
||||||
.setSensorDistance(Distance.of(12))
|
.setSensorDistance(Distance.of(14))
|
||||||
.setHeartRate(66f)
|
.setHeartRate(66f)
|
||||||
.setPower(50f)
|
.setPower(50f)
|
||||||
.setCadence(3f)
|
.setCadence(3f)
|
||||||
.setHorizontalAccuracy(Distance.of(10)),
|
.setHorizontalAccuracy(Distance.of(10)),
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:02:21Z"))
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:21Z"))
|
||||||
.setLatitude(3)
|
.setLatitude(3)
|
||||||
.setLongitude(14.002)
|
.setLongitude(14.002)
|
||||||
.setAltitude(10)
|
.setAltitude(10)
|
||||||
@@ -365,7 +370,7 @@ public class ExportImportTest {
|
|||||||
.setAltitudeGain(0f)
|
.setAltitudeGain(0f)
|
||||||
.setSpeed(Speed.of(15))
|
.setSpeed(Speed.of(15))
|
||||||
.setHorizontalAccuracy(Distance.of(10)),
|
.setHorizontalAccuracy(Distance.of(10)),
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:02:22Z"))
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:22Z"))
|
||||||
.setLatitude(3)
|
.setLatitude(3)
|
||||||
.setLongitude(16)
|
.setLongitude(16)
|
||||||
.setAltitude(10)
|
.setAltitude(10)
|
||||||
@@ -373,7 +378,7 @@ public class ExportImportTest {
|
|||||||
.setAltitudeGain(0f)
|
.setAltitudeGain(0f)
|
||||||
.setSpeed(Speed.of(15))
|
.setSpeed(Speed.of(15))
|
||||||
.setHorizontalAccuracy(Distance.of(10)),
|
.setHorizontalAccuracy(Distance.of(10)),
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:23Z"))
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:23Z"))
|
||||||
.setLatitude(3)
|
.setLatitude(3)
|
||||||
.setLongitude(16.001)
|
.setLongitude(16.001)
|
||||||
.setAltitude(10)
|
.setAltitude(10)
|
||||||
@@ -390,18 +395,18 @@ public class ExportImportTest {
|
|||||||
// Time
|
// Time
|
||||||
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
|
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
|
||||||
assertEquals(Instant.parse("2020-02-02T02:02:03Z"), importedTrackStatistics.getStartTime());
|
assertEquals(Instant.parse("2020-02-02T02:02:03Z"), importedTrackStatistics.getStartTime());
|
||||||
assertEquals(Instant.parse("2020-02-02T02:02:23Z"), importedTrackStatistics.getStopTime());
|
assertEquals(Instant.parse("2020-02-02T02:03:23Z"), importedTrackStatistics.getStopTime());
|
||||||
|
|
||||||
assertEquals(Duration.ofSeconds(3), importedTrackStatistics.getTotalTime());
|
assertEquals(Duration.ofSeconds(15), importedTrackStatistics.getTotalTime());
|
||||||
assertEquals(Duration.ofSeconds(3), importedTrackStatistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(15), importedTrackStatistics.getMovingTime());
|
||||||
|
|
||||||
// Distance
|
// Distance
|
||||||
assertEquals(123.16, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
assertEquals(125.16, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
assertEquals(41.05, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(8.34, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
assertEquals(41.05, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
assertEquals(8.34, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
||||||
assertEquals(41.05, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
|
assertEquals(8.34, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
// Altitude
|
// Altitude
|
||||||
assertEquals(10, importedTrackStatistics.getMinAltitude(), 0.01);
|
assertEquals(10, importedTrackStatistics.getMinAltitude(), 0.01);
|
||||||
|
|||||||
+43
@@ -31,12 +31,14 @@ import de.dennisguse.opentracks.R;
|
|||||||
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
||||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.data.models.Distance;
|
import de.dennisguse.opentracks.data.models.Distance;
|
||||||
|
import de.dennisguse.opentracks.data.models.HeartRate;
|
||||||
import de.dennisguse.opentracks.data.models.Speed;
|
import de.dennisguse.opentracks.data.models.Speed;
|
||||||
import de.dennisguse.opentracks.data.models.Track;
|
import de.dennisguse.opentracks.data.models.Track;
|
||||||
import de.dennisguse.opentracks.data.models.TrackPoint;
|
import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||||
import de.dennisguse.opentracks.io.file.importer.TrackPointAssert;
|
import de.dennisguse.opentracks.io.file.importer.TrackPointAssert;
|
||||||
import de.dennisguse.opentracks.sensors.AltitudeSumManager;
|
import de.dennisguse.opentracks.sensors.AltitudeSumManager;
|
||||||
import de.dennisguse.opentracks.sensors.BluetoothRemoteSensorManager;
|
import de.dennisguse.opentracks.sensors.BluetoothRemoteSensorManager;
|
||||||
|
import de.dennisguse.opentracks.sensors.sensorData.SensorDataHeartRate;
|
||||||
import de.dennisguse.opentracks.sensors.sensorData.SensorDataRunning;
|
import de.dennisguse.opentracks.sensors.sensorData.SensorDataRunning;
|
||||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
@@ -257,6 +259,47 @@ public class TrackRecordingServiceTestRecording {
|
|||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MediumTest
|
||||||
|
@Test
|
||||||
|
public void testRecording_blesensor_only_no_distance() {
|
||||||
|
// given
|
||||||
|
String startTime = "2020-02-02T02:02:02Z";
|
||||||
|
TrackPointCreator trackPointCreator = service.getTrackPointCreator();
|
||||||
|
|
||||||
|
trackPointCreator.setClock(startTime);
|
||||||
|
Track.Id trackId = service.startNewTrack();
|
||||||
|
trackPointCreator.stopGPS();
|
||||||
|
trackPointCreator.setAltitudeSumManager(altitudeSumManager);
|
||||||
|
BluetoothRemoteSensorManager remoteSensorManager = trackPointCreator.getRemoteSensorManager();
|
||||||
|
|
||||||
|
// when
|
||||||
|
String sensor1 = "2020-02-02T02:02:03Z";
|
||||||
|
trackPointCreator.setClock(sensor1);
|
||||||
|
remoteSensorManager.onChanged(new SensorDataHeartRate("", "", HeartRate.of(5))); //Should be ignored
|
||||||
|
|
||||||
|
String sensor3 = "2020-02-02T02:02:13Z";
|
||||||
|
trackPointCreator.setClock(sensor3);
|
||||||
|
remoteSensorManager.onChanged(new SensorDataHeartRate("", "", HeartRate.of(7)));
|
||||||
|
|
||||||
|
String stopTime = "2020-02-02T02:02:15Z";
|
||||||
|
trackPointCreator.setClock(stopTime);
|
||||||
|
service.endCurrentTrack();
|
||||||
|
|
||||||
|
// then
|
||||||
|
new TrackPointAssert().assertEquals(List.of(
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
|
||||||
|
new TrackPoint(TrackPoint.Type.SENSORPOINT, Instant.parse(sensor3))
|
||||||
|
.setAltitudeGain(0f)
|
||||||
|
.setAltitudeLoss(0f)
|
||||||
|
.setHeartRate(HeartRate.of(7)),
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
|
||||||
|
.setAltitudeGain(0f)
|
||||||
|
.setAltitudeLoss(0f)
|
||||||
|
.setHeartRate(HeartRate.of(7))
|
||||||
|
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testRecording_gpsOnly_recordingDistance_above() {
|
public void testRecording_gpsOnly_recordingDistance_above() {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class TrackPoint {
|
|||||||
|
|
||||||
SEGMENT_START_AUTOMATIC(-1), //Start of a segment due to too much distance from previous TrackPoint
|
SEGMENT_START_AUTOMATIC(-1), //Start of a segment due to too much distance from previous TrackPoint
|
||||||
TRACKPOINT(0), //Just GPS data and may contain BLE sensor data
|
TRACKPOINT(0), //Just GPS data and may contain BLE sensor data
|
||||||
SENSORPOINT(2), //Just BLE sensor data; required to have speed and sensorDistance
|
SENSORPOINT(2), //Just BLE sensor data; may have speed and sensorDistance
|
||||||
|
|
||||||
SEGMENT_END_MANUAL(1); //End of a segment
|
SEGMENT_END_MANUAL(1); //End of a segment
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.util.Pair;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
@@ -180,8 +181,16 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!trackPoint.hasLocation() && !trackPoint.hasSensorDistance()) {
|
if (!trackPoint.hasLocation() && !trackPoint.hasSensorDistance()) {
|
||||||
Log.d(TAG, "Ignoring TrackPoint as it has no distance.");
|
Duration minStorageInterval = Duration.ofSeconds(10); // TODO Should be configurable.
|
||||||
return false;
|
boolean shouldStore = lastStoredTrackPoint.getTime().plus(minStorageInterval)
|
||||||
|
.isBefore(trackPoint.getTime());
|
||||||
|
if (!shouldStore) {
|
||||||
|
Log.d(TAG, "Ignoring TrackPoint as it has no distance (and sensor data is not new enough).");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
insertTrackPoint(trackPoint, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Distance distanceToLastStoredTrackPoint;
|
Distance distanceToLastStoredTrackPoint;
|
||||||
|
|||||||
Reference in New Issue
Block a user