forked from upstream-mirrors/OpenTracks
+9
-9
@@ -157,7 +157,7 @@ public class ExportImportTest {
|
|||||||
contentProviderUtils.insertMarker(new Marker("Marker 2", "Marker 2 desc", "Marker 2 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));
|
contentProviderUtils.insertMarker(new Marker("Marker 2", "Marker 2 desc", "Marker 2 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:02:18Z");
|
trackPointCreator.setClock("2020-02-02T02:02:18Z");
|
||||||
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet();
|
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet(trackPointCreator);
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
trackPointCreator.setClock("2020-02-02T02:03:20Z");
|
trackPointCreator.setClock("2020-02-02T02:03:20Z");
|
||||||
@@ -172,7 +172,7 @@ public class ExportImportTest {
|
|||||||
|
|
||||||
sendLocation(trackPointCreator, "2020-02-02T02:03:50Z", 3, 16.001, 10, 27, 15, 10, 0f);
|
sendLocation(trackPointCreator, "2020-02-02T02:03:50Z", 3, 16.001, 10, 27, 15, 10, 0f);
|
||||||
|
|
||||||
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet();
|
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet(trackPointCreator);
|
||||||
trackPointCreator.setClock("2020-02-02T02:04:00Z");
|
trackPointCreator.setClock("2020-02-02T02:04:00Z");
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
@@ -550,22 +550,22 @@ public class ExportImportTest {
|
|||||||
|
|
||||||
AggregatorCyclingPower cyclingPower = Mockito.mock(AggregatorCyclingPower.class);
|
AggregatorCyclingPower cyclingPower = Mockito.mock(AggregatorCyclingPower.class);
|
||||||
Mockito.when(cyclingPower.hasValue()).thenReturn(true);
|
Mockito.when(cyclingPower.hasValue()).thenReturn(true);
|
||||||
Mockito.when(cyclingPower.getValue()).thenReturn(Power.of(power));
|
Mockito.when(cyclingPower.getValue(Mockito.any())).thenReturn(Power.of(power));
|
||||||
sensorDataSet.add(cyclingPower);
|
sensorDataSet.add(cyclingPower);
|
||||||
|
|
||||||
AggregatorHeartRate agheartRate = Mockito.mock(AggregatorHeartRate.class);
|
AggregatorHeartRate avgHeartRate = Mockito.mock(AggregatorHeartRate.class);
|
||||||
Mockito.when(agheartRate.getValue()).thenReturn(HeartRate.of(heartRate));
|
Mockito.when(avgHeartRate.getValue(Mockito.any())).thenReturn(HeartRate.of(heartRate));
|
||||||
sensorDataSet.add(agheartRate);
|
sensorDataSet.add(avgHeartRate);
|
||||||
|
|
||||||
AggregatorCyclingCadence cyclingCadence = Mockito.mock(AggregatorCyclingCadence.class);
|
AggregatorCyclingCadence cyclingCadence = Mockito.mock(AggregatorCyclingCadence.class);
|
||||||
Mockito.when(cyclingCadence.hasValue()).thenReturn(true);
|
Mockito.when(cyclingCadence.hasValue()).thenReturn(true);
|
||||||
Mockito.when(cyclingCadence.getValue()).thenReturn(Cadence.of(cadence));
|
Mockito.when(cyclingCadence.getValue(Mockito.any())).thenReturn(Cadence.of(cadence));
|
||||||
sensorDataSet.add(cyclingCadence);
|
sensorDataSet.add(cyclingCadence);
|
||||||
|
|
||||||
if (distance != null && speed != null) {
|
if (distance != null && speed != null) {
|
||||||
AggregatorCyclingDistanceSpeed distanceSpeed = Mockito.mock(AggregatorCyclingDistanceSpeed.class);
|
AggregatorCyclingDistanceSpeed distanceSpeed = Mockito.mock(AggregatorCyclingDistanceSpeed.class);
|
||||||
Mockito.when(distanceSpeed.hasValue()).thenReturn(true);
|
Mockito.when(distanceSpeed.hasValue()).thenReturn(true);
|
||||||
Mockito.when(distanceSpeed.getValue()).thenReturn(new AggregatorCyclingDistanceSpeed.Data(null, distance, Speed.of(speed)));
|
Mockito.when(distanceSpeed.getValue(Mockito.any())).thenReturn(new AggregatorCyclingDistanceSpeed.Data(null, distance, Speed.of(speed)));
|
||||||
sensorDataSet.add(distanceSpeed);
|
sensorDataSet.add(distanceSpeed);
|
||||||
} else {
|
} else {
|
||||||
sensorDataSet.add(new AggregatorCyclingDistanceSpeed("", ""));
|
sensorDataSet.add(new AggregatorCyclingDistanceSpeed("", ""));
|
||||||
@@ -582,7 +582,7 @@ public class ExportImportTest {
|
|||||||
if (altitudeGain != null) {
|
if (altitudeGain != null) {
|
||||||
AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class);
|
AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class);
|
||||||
Mockito.when(barometer.hasValue()).thenReturn(true);
|
Mockito.when(barometer.hasValue()).thenReturn(true);
|
||||||
Mockito.when(barometer.getValue()).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
|
Mockito.when(barometer.getValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
|
||||||
sensorDataSet.add(barometer);
|
sensorDataSet.add(barometer);
|
||||||
} else {
|
} else {
|
||||||
sensorDataSet.add(new AggregatorBarometer("test", null));
|
sensorDataSet.add(new AggregatorBarometer("test", null));
|
||||||
|
|||||||
+3
-1
@@ -3,13 +3,15 @@ package de.dennisguse.opentracks.sensors.sensorData;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.data.models.AtmosphericPressure;
|
import de.dennisguse.opentracks.data.models.AtmosphericPressure;
|
||||||
|
|
||||||
public class AggregatorBarometerTest {
|
public class AggregatorBarometerTest {
|
||||||
|
|
||||||
private static void addSensorValue(AggregatorBarometer aggregatorBarometer, float[] values) {
|
private static void addSensorValue(AggregatorBarometer aggregatorBarometer, float[] values) {
|
||||||
for (float f : values) {
|
for (float f : values) {
|
||||||
aggregatorBarometer.add(new Raw<>(AtmosphericPressure.ofHPA(f)));
|
aggregatorBarometer.add(new Raw<>(Instant.MIN, AtmosphericPressure.ofHPA(f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-24
@@ -9,6 +9,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.data.models.Cadence;
|
import de.dennisguse.opentracks.data.models.Cadence;
|
||||||
import de.dennisguse.opentracks.data.models.Distance;
|
import de.dennisguse.opentracks.data.models.Distance;
|
||||||
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingCadence;
|
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingCadence;
|
||||||
@@ -23,11 +25,11 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(2, 2048)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 2048)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(60, current.getValue().getRPM(), 0.01);
|
assertEquals(60, current.getValue(Instant.MIN).getRPM(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -35,11 +37,11 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, 6184)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 6184)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(2, 8016)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 8016)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(33.53, current.getValue().getRPM(), 0.01);
|
assertEquals(33.53, current.getValue(Instant.MIN).getRPM(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -47,11 +49,11 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, 2048)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 2048)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(Cadence.of(0), current.getValue());
|
assertEquals(Cadence.of(0), current.getValue(Instant.MIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,8 +62,8 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(2, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 1024)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertFalse(current.hasValue()); //TODO Cadence should be 0?
|
assertFalse(current.hasValue()); //TODO Cadence should be 0?
|
||||||
@@ -72,11 +74,11 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(1, UintUtils.UINT16_MAX - 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, UintUtils.UINT16_MAX - 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(2, 0)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 0)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(60, current.getValue().getRPM(), 0.01);
|
assertEquals(60, current.getValue(Instant.MIN).getRPM(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -85,13 +87,13 @@ public class SensorDataCyclingTest {
|
|||||||
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
AggregatorCyclingCadence current = new AggregatorCyclingCadence("", "");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(UintUtils.UINT32_MAX - 1, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(UintUtils.UINT32_MAX - 1, 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingCadence.CrankData(0, 2048)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(0, 2048)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
// TODO See #953
|
// TODO See #953
|
||||||
// assertEquals(60, current.getValue().getRPM(), 0.01);
|
// assertEquals(60, current.getValue().getRPM(), 0.01);
|
||||||
assertNull(current.getValue());
|
assertNull(current.getValue(Instant.MIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -100,12 +102,12 @@ public class SensorDataCyclingTest {
|
|||||||
current.setWheelCircumference(Distance.ofMM(2150));
|
current.setWheelCircumference(Distance.ofMM(2150));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingDistanceSpeed.WheelData(1, 6184)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(1, 6184)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingDistanceSpeed.WheelData(2, 8016)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(2, 8016)));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(2.15, current.getValue().distance().toM(), 0.01);
|
assertEquals(2.15, current.getValue(Instant.MIN).distance().toM(), 0.01);
|
||||||
assertEquals(1.20, current.getValue().speed().toMPS(), 0.01);
|
assertEquals(1.20, current.getValue(Instant.MIN).speed().toMPS(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -115,14 +117,14 @@ public class SensorDataCyclingTest {
|
|||||||
current.setWheelCircumference(Distance.ofMM(2000));
|
current.setWheelCircumference(Distance.ofMM(2000));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingDistanceSpeed.WheelData(UintUtils.UINT32_MAX - 1, 1024)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(UintUtils.UINT32_MAX - 1, 1024)));
|
||||||
current.add(new Raw<>(new BluetoothHandlerCyclingDistanceSpeed.WheelData(0, 2048)));
|
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(0, 2048)));
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
// TODO See #953
|
// TODO See #953
|
||||||
// assertEquals(2, current.getValue().getDistance().toM(), 0.01);
|
// assertEquals(2, current.getValue().getDistance().toM(), 0.01);
|
||||||
// assertEquals(2, current.getValue().getSpeed().toMPS(), 0.01);
|
// assertEquals(2, current.getValue().getSpeed().toMPS(), 0.01);
|
||||||
assertNull(current.getValue());
|
assertNull(current.getValue(Instant.MIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-8
@@ -304,11 +304,11 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
String sensor1 = "2020-02-02T02:02:03Z";
|
String sensor1 = "2020-02-02T02:02:03Z";
|
||||||
trackPointCreator.setClock(sensor1);
|
trackPointCreator.setClock(sensor1);
|
||||||
|
|
||||||
sensorManager.onChanged(new Raw<>(HeartRate.of(5))); //Should be ignored
|
sensorManager.onChanged(new Raw<>(sensor1, HeartRate.of(5))); //Should be ignored
|
||||||
|
|
||||||
String sensor3 = "2020-02-02T02:02:13Z";
|
String sensor3 = "2020-02-02T02:02:13Z";
|
||||||
trackPointCreator.setClock(sensor3);
|
trackPointCreator.setClock(sensor3);
|
||||||
sensorManager.onChanged(new Raw<>(HeartRate.of(7)));
|
sensorManager.onChanged(new Raw<>(sensor3, HeartRate.of(7)));
|
||||||
|
|
||||||
String stopTime = "2020-02-02T02:02:15Z";
|
String stopTime = "2020-02-02T02:02:15Z";
|
||||||
trackPointCreator.setClock(stopTime);
|
trackPointCreator.setClock(stopTime);
|
||||||
@@ -646,12 +646,12 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
// when
|
// when
|
||||||
String sensor1 = "2020-02-02T02:02:03Z";
|
String sensor1 = "2020-02-02T02:02:03Z";
|
||||||
trackPointCreator.setClock(sensor1);
|
trackPointCreator.setClock(sensor1);
|
||||||
sensorManager.onChanged(new Raw<>(new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(0)))); //Should be ignored
|
sensorManager.onChanged(new Raw<>(sensor1, new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(0)))); //Should be ignored
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String sensor2 = "2020-02-02T02:02:04Z";
|
String sensor2 = "2020-02-02T02:02:04Z";
|
||||||
trackPointCreator.setClock(sensor2);
|
trackPointCreator.setClock(sensor2);
|
||||||
sensorManager.onChanged(new Raw<>(new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(2))));
|
sensorManager.onChanged(new Raw<>(sensor2, new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(2))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String gps1 = "2020-02-02T02:02:05Z";
|
String gps1 = "2020-02-02T02:02:05Z";
|
||||||
@@ -660,12 +660,12 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
// when
|
// when
|
||||||
String sensor3 = "2020-02-02T02:02:06Z";
|
String sensor3 = "2020-02-02T02:02:06Z";
|
||||||
trackPointCreator.setClock(sensor3);
|
trackPointCreator.setClock(sensor3);
|
||||||
sensorManager.onChanged(new Raw<>(new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(12))));
|
sensorManager.onChanged(new Raw<>(sensor3, new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(12))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String sensor4 = "2020-02-02T02:02:07Z";
|
String sensor4 = "2020-02-02T02:02:07Z";
|
||||||
trackPointCreator.setClock(sensor4);
|
trackPointCreator.setClock(sensor4);
|
||||||
sensorManager.onChanged(new Raw<>(new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(14)))); //Should be ignored
|
sensorManager.onChanged(new Raw<>(sensor4, new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(14)))); //Should be ignored
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String gps2 = "2020-02-02T02:02:08Z";
|
String gps2 = "2020-02-02T02:02:08Z";
|
||||||
@@ -674,7 +674,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
// when
|
// when
|
||||||
String sensor5 = "2020-02-02T02:02:10Z";
|
String sensor5 = "2020-02-02T02:02:10Z";
|
||||||
trackPointCreator.setClock(sensor5);
|
trackPointCreator.setClock(sensor5);
|
||||||
sensorManager.onChanged(new Raw<>(new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(16)))); //Should be ignored
|
sensorManager.onChanged(new Raw<>(sensor5, new BluetoothHandlerRunningSpeedAndCadence.Data(Speed.of(5), null, Distance.of(16)))); //Should be ignored
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String gps3 = "2020-02-02T02:02:12Z";
|
String gps3 = "2020-02-02T02:02:12Z";
|
||||||
@@ -730,7 +730,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
private void mockAltitudeChange(TrackPointCreator trackPointCreator, float altitudeGain) {
|
private void mockAltitudeChange(TrackPointCreator trackPointCreator, float altitudeGain) {
|
||||||
AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class);
|
AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class);
|
||||||
Mockito.when(barometer.hasValue()).thenReturn(true);
|
Mockito.when(barometer.hasValue()).thenReturn(true);
|
||||||
Mockito.when(barometer.getValue()).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
|
Mockito.when(barometer.getValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
|
||||||
|
|
||||||
trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer;
|
trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
|
|
||||||
//TODO Should be final and not be visible for testing
|
//TODO Should be final and not be visible for testing
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public SensorDataSet sensorDataSet = new SensorDataSet();
|
public SensorDataSet sensorDataSet;
|
||||||
|
|
||||||
private final TrackPointCreator observer;
|
private final TrackPointCreator observer;
|
||||||
|
|
||||||
@@ -64,6 +64,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
|
|
||||||
public SensorManager(TrackPointCreator observer) {
|
public SensorManager(TrackPointCreator observer) {
|
||||||
this.observer = observer;
|
this.observer = observer;
|
||||||
|
this.sensorDataSet = new SensorDataSet(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(Context context, Handler handler) {
|
public void start(Context context, Handler handler) {
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ public abstract class Aggregator<Input, Output> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
protected abstract Output getNoneValue();
|
protected abstract Output getNoneValue();
|
||||||
|
|
||||||
public Output getValue() {
|
public Output getValue(Instant now) {
|
||||||
if (!hasValue()) {
|
if (!hasValue()) {
|
||||||
return null; //TODO Check if this is a good idea!
|
return null; //TODO Check if this is a good idea!
|
||||||
}
|
}
|
||||||
if (isRecent()) {
|
if (isRecent(now)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
return getNoneValue();
|
return getNoneValue();
|
||||||
@@ -62,12 +62,12 @@ public abstract class Aggregator<Input, Output> {
|
|||||||
/**
|
/**
|
||||||
* Is the data recent considering the current time.
|
* Is the data recent considering the current time.
|
||||||
*/
|
*/
|
||||||
private boolean isRecent() {
|
private boolean isRecent(Instant now) {
|
||||||
if (previous == null) {
|
if (previous == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Instant.now()
|
return now
|
||||||
.isBefore(previous.time().plus(BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE));
|
.isBefore(previous.time().plus(BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,21 @@ package de.dennisguse.opentracks.sensors.sensorData;
|
|||||||
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
public record Raw<T>(
|
public record Raw<T>(
|
||||||
@NonNull Instant time,
|
@NonNull Instant time,
|
||||||
@NonNull T value
|
@NonNull T value
|
||||||
) {
|
) {
|
||||||
@Deprecated
|
public Raw(@NonNull Clock clock, @NonNull T value) {
|
||||||
public Raw(@NonNull T value) {
|
this(clock.instant(), value);
|
||||||
this(Instant.now(), value); //TODO We should be using the MonotonicClock
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public Raw(@NonNull String time, @NonNull T value) {
|
||||||
|
this(Instant.parse(time), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingCadence;
|
|||||||
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingDistanceSpeed;
|
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingDistanceSpeed;
|
||||||
import de.dennisguse.opentracks.sensors.BluetoothHandlerManagerCyclingPower;
|
import de.dennisguse.opentracks.sensors.BluetoothHandlerManagerCyclingPower;
|
||||||
import de.dennisguse.opentracks.sensors.BluetoothHandlerRunningSpeedAndCadence;
|
import de.dennisguse.opentracks.sensors.BluetoothHandlerRunningSpeedAndCadence;
|
||||||
|
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
|
|
||||||
public final class SensorDataSet {
|
public final class SensorDataSet {
|
||||||
@@ -43,11 +44,15 @@ public final class SensorDataSet {
|
|||||||
|
|
||||||
public AggregatorGPS gps;
|
public AggregatorGPS gps;
|
||||||
|
|
||||||
public SensorDataSet() {
|
private TrackPointCreator trackPointCreator;
|
||||||
|
|
||||||
|
public SensorDataSet(TrackPointCreator trackPointCreator) {
|
||||||
|
this.trackPointCreator = trackPointCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated //TODO This is not a copy constructor anymore, but it should be - aggregators are no value objects; best guess: can be removed
|
||||||
public SensorDataSet(SensorDataSet toCopy) {
|
public SensorDataSet(SensorDataSet toCopy) {
|
||||||
//TODO This is not a copy constructor anymore, but it should be - aggregators are no value objects
|
this.trackPointCreator = toCopy.trackPointCreator;
|
||||||
this.heartRate = toCopy.heartRate;
|
this.heartRate = toCopy.heartRate;
|
||||||
this.cyclingCadence = toCopy.cyclingCadence;
|
this.cyclingCadence = toCopy.cyclingCadence;
|
||||||
this.cyclingDistanceSpeed = toCopy.cyclingDistanceSpeed;
|
this.cyclingDistanceSpeed = toCopy.cyclingDistanceSpeed;
|
||||||
@@ -59,7 +64,7 @@ public final class SensorDataSet {
|
|||||||
|
|
||||||
public Pair<HeartRate, String> getHeartRate() {
|
public Pair<HeartRate, String> getHeartRate() {
|
||||||
if (heartRate != null) {
|
if (heartRate != null) {
|
||||||
return new Pair<>(heartRate.getValue(), heartRate.getSensorNameOrAddress());
|
return new Pair<>(heartRate.getValue(trackPointCreator.createNow()), heartRate.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -67,7 +72,7 @@ public final class SensorDataSet {
|
|||||||
|
|
||||||
public Pair<Cadence, String> getCadence() {
|
public Pair<Cadence, String> getCadence() {
|
||||||
if (cyclingCadence != null) {
|
if (cyclingCadence != null) {
|
||||||
return new Pair<>(cyclingCadence.getValue(), cyclingCadence.getSensorNameOrAddress());
|
return new Pair<>(cyclingCadence.getValue(trackPointCreator.createNow()), cyclingCadence.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.value.cadence() != null) {
|
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.value.cadence() != null) {
|
||||||
@@ -78,11 +83,11 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Pair<Speed, String> getSpeed() {
|
public Pair<Speed, String> getSpeed() {
|
||||||
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue() && cyclingDistanceSpeed.getValue().speed() != null) {
|
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue() && cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).speed() != null) {
|
||||||
return new Pair<>(cyclingDistanceSpeed.getValue().speed(), cyclingDistanceSpeed.getSensorNameOrAddress());
|
return new Pair<>(cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).speed(), cyclingDistanceSpeed.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().speed() != null) {
|
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue(trackPointCreator.createNow()).speed() != null) {
|
||||||
return new Pair<>(runningDistanceSpeedCadence.value.speed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
|
return new Pair<>(runningDistanceSpeedCadence.value.speed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +157,7 @@ public final class SensorDataSet {
|
|||||||
|
|
||||||
public void fillTrackPoint(TrackPoint trackPoint) {
|
public void fillTrackPoint(TrackPoint trackPoint) {
|
||||||
if (gps != null && gps.hasValue()) {
|
if (gps != null && gps.hasValue()) {
|
||||||
trackPoint.setPosition(gps.getValue());
|
trackPoint.setPosition(gps.getValue(trackPointCreator.createNow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getHeartRate() != null) {
|
if (getHeartRate() != null) {
|
||||||
@@ -168,20 +173,20 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue()) {
|
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue()) {
|
||||||
trackPoint.setSensorDistance(cyclingDistanceSpeed.getValue().distanceOverall());
|
trackPoint.setSensorDistance(cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).distanceOverall());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cyclingPower != null && cyclingPower.hasValue()) {
|
if (cyclingPower != null && cyclingPower.hasValue()) {
|
||||||
trackPoint.setPower(cyclingPower.getValue());
|
trackPoint.setPower(cyclingPower.getValue(trackPointCreator.createNow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) {
|
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) {
|
||||||
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue().distance());
|
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue(trackPointCreator.createNow()).distance());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barometer != null && barometer.hasValue()) {
|
if (barometer != null && barometer.hasValue()) {
|
||||||
trackPoint.setAltitudeGain(barometer.getValue().gain_m());
|
trackPoint.setAltitudeGain(barometer.getValue(trackPointCreator.createNow()).gain_m());
|
||||||
trackPoint.setAltitudeLoss(barometer.getValue().loss_m());
|
trackPoint.setAltitudeLoss(barometer.getValue(trackPointCreator.createNow()).loss_m());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.dennisguse.opentracks.viewmodels;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.data.models.HeartRateZones;
|
import de.dennisguse.opentracks.data.models.HeartRateZones;
|
||||||
import de.dennisguse.opentracks.databinding.StatsSensorItemBinding;
|
import de.dennisguse.opentracks.databinding.StatsSensorItemBinding;
|
||||||
@@ -92,7 +94,7 @@ public abstract class SensorStatisticsViewHolder extends StatisticViewHolder<Sta
|
|||||||
|
|
||||||
Pair<String, String> valueAndUnit;
|
Pair<String, String> valueAndUnit;
|
||||||
if (sensorDataSet != null && sensorDataSet.getCyclingPower() != null) {
|
if (sensorDataSet != null && sensorDataSet.getCyclingPower() != null) {
|
||||||
valueAndUnit = StringUtils.getPowerParts(getContext(), sensorDataSet.getCyclingPower().getValue());
|
valueAndUnit = StringUtils.getPowerParts(getContext(), sensorDataSet.getCyclingPower().getValue(Instant.now())); //TODO Use MonotonicClock
|
||||||
sensorName = sensorDataSet.getCyclingPower().getSensorNameOrAddress();
|
sensorName = sensorDataSet.getCyclingPower().getSensorNameOrAddress();
|
||||||
} else {
|
} else {
|
||||||
valueAndUnit = StringUtils.getCadenceParts(getContext(), null);
|
valueAndUnit = StringUtils.getCadenceParts(getContext(), null);
|
||||||
|
|||||||
Reference in New Issue
Block a user