Sensor: add temperature.

Fixes #2241.
This commit is contained in:
Dennis Guse
2026-01-04 09:56:44 +01:00
parent 738201c1c2
commit 54844b9a9a
36 changed files with 435 additions and 44 deletions
@@ -60,6 +60,7 @@ import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Power;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.Temperature;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackBuilder;
import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -72,6 +73,7 @@ import de.dennisguse.opentracks.sensors.sensorData.AggregatorCyclingCadence;
import de.dennisguse.opentracks.sensors.sensorData.AggregatorCyclingDistanceSpeed;
import de.dennisguse.opentracks.sensors.sensorData.AggregatorCyclingPower;
import de.dennisguse.opentracks.sensors.sensorData.AggregatorHeartRate;
import de.dennisguse.opentracks.sensors.sensorData.AggregatorTemperature;
import de.dennisguse.opentracks.sensors.sensorData.Raw;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataAggregator;
import de.dennisguse.opentracks.services.TrackRecordingService;
@@ -173,14 +175,14 @@ public class ExportImportTest {
// A sensor-only TrackPoint
trackPointCreator.setClock("2020-02-02T02:02:04Z");
mockSensorData(trackPointCreator, 15f, sensorDistance, 66f, 3f, 50f, 1f);
mockSensorData(trackPointCreator, 15f, sensorDistance, 66f, 3f, 50f, 1f, 27);
trackPointCreator.setClock("2020-02-02T02:02:14Z"); //ignored
mockSensorData(trackPointCreator, 15f, null, 67f, 3f, 50f, null);
mockSensorData(trackPointCreator, 15f, null, 67f, 3f, 50f, null, 28);
trackPointCreator.setClock("2020-02-02T02:02:15Z");
mockSensorData(trackPointCreator, null, null, 68f, 3f, 50f, null);
mockSensorData(trackPointCreator, null, null, 68f, 3f, 50f, null, 29);
trackPointCreator.setClock("2020-02-02T02:02:16Z");
mockSensorData(trackPointCreator, 5f, Distance.of(2), 69f, 3f, 50f, null); // Distance will be added to next TrackPoint
mockSensorData(trackPointCreator, 5f, Distance.of(2), 69f, 3f, 50f, null, 30); //Distance will be added to next TrackPoint
sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3.1234567, 14.0014567, 10, 13, 15, 1020.25, 0f);
contentProviderUtils.insertMarker(
@@ -248,6 +250,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(1, 1)
),
new TrackPoint(
@@ -261,6 +264,7 @@ public class ExportImportTest {
Speed.of(15)),
Distance.of(10),
HeartRate.of(66),
Temperature.of(27),
Cadence.of(3),
Power.of(50),
new AltitudeGainLoss(1, 1)
@@ -271,6 +275,7 @@ public class ExportImportTest {
Position.of(Instant.parse("2020-02-02T02:02:15Z")),
null,
HeartRate.of(68),
Temperature.of(29),
Cadence.of(3),
Power.of(50),
null
@@ -286,6 +291,7 @@ public class ExportImportTest {
Speed.of(5)),
Distance.of(2),
HeartRate.of(69),
Temperature.of(30),
Cadence.of(3),
Power.of(50),
new AltitudeGainLoss(0, 0)
@@ -305,6 +311,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -319,6 +326,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -329,6 +337,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -343,6 +352,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:04:00Z"))
), actual);
@@ -365,7 +375,7 @@ public class ExportImportTest {
//TODO Does not test marker images
@LargeTest
@Test
public void kmz_with_trackdetail_and_sensordata() throws TimeoutException, IOException {
public void kmz_with_trackdetail_and_sensordata() throws IOException {
// given
Track track = contentProviderUtils.getTrack(trackId);
@@ -417,7 +427,7 @@ public class ExportImportTest {
@LargeTest
@Test(expected = ImportAlreadyExistsException.class)
public void kml_with_trackdetail_and_sensordata_duplicate_trackUUID() throws TimeoutException, IOException {
public void kml_with_trackdetail_and_sensordata_duplicate_trackUUID() throws IOException {
// given
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(context.getString(R.string.import_prevent_reimport_key), true);
@@ -487,6 +497,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(1, 1)
),
new TrackPoint(
@@ -500,6 +511,7 @@ public class ExportImportTest {
Speed.of(5)),
Distance.of(12),
HeartRate.of(69),
Temperature.of(30),
Cadence.of(3),
Power.of(50),
new AltitudeGainLoss(1, 1)
@@ -517,6 +529,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -532,6 +545,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -547,6 +561,7 @@ public class ExportImportTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
)
), actual);
@@ -575,7 +590,7 @@ public class ExportImportTest {
@LargeTest
@Test(expected = ImportAlreadyExistsException.class)
public void gpx_duplicate_trackUUID() throws TimeoutException, IOException {
public void gpx_duplicate_trackUUID() throws IOException {
// given
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(context.getString(R.string.import_prevent_reimport_key), true);
@@ -601,7 +616,7 @@ public class ExportImportTest {
@LargeTest
@Test
public void csv_export_only() throws TimeoutException, IOException {
public void csv_export_only() throws IOException {
// given
Track track = contentProviderUtils.getTrack(trackId);
@@ -645,7 +660,7 @@ public class ExportImportTest {
}
}
private void mockSensorData(TrackPointCreator trackPointCreator, Float speed, Distance distance, float heartRate, float cadence, Float power, Float altitudeGain) {
private void mockSensorData(TrackPointCreator trackPointCreator, Float speed, Distance distance, float heartRate, float cadence, Float power, Float altitudeGain, float temperature) {
SensorDataAggregator sensorDataAggregator = trackPointCreator.getSensorManager().sensorDataAggregator;
AggregatorCyclingPower cyclingPower = new AggregatorCyclingPower("", "");
@@ -691,6 +706,19 @@ public class ExportImportTest {
mockAltitudeChange(trackPointCreator, altitudeGain);
sensorDataAggregator.add(new AggregatorTemperature("", "'") {
@NonNull
@Override
public Temperature getAggregatedValue(Instant now) {
return Temperature.of(temperature);
}
@Override
public boolean hasReceivedData() {
return true;
}
});
trackPointCreator.onChange();
}
@@ -210,6 +210,7 @@ public class GPXTrackImporterTest {
null,
null,
null,
null,
new AltitudeGainLoss(1, 1)
),
new TrackPoint(
@@ -223,6 +224,7 @@ public class GPXTrackImporterTest {
Speed.of(5)),
Distance.of(12),
HeartRate.of(69),
null,
Cadence.of(3),
Power.of(50),
new AltitudeGainLoss(1, 1)
@@ -240,6 +242,7 @@ public class GPXTrackImporterTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -255,6 +258,7 @@ public class GPXTrackImporterTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
),
new TrackPoint(
@@ -270,6 +274,7 @@ public class GPXTrackImporterTest {
null,
null,
null,
null,
new AltitudeGainLoss(0, 0)
)
), actual);
@@ -52,6 +52,8 @@ public class TrackPointAssert {
Assert.assertEquals("heartRate", expected.heartRate(), actual.heartRate());
Assert.assertEquals("temperature", expected.temperature(), actual.temperature());
Assert.assertEquals("power", expected.power(), actual.power());
Assert.assertEquals("cadence", expected.cadence(), actual.cadence());