Cleanup: renames in sensor data handling.

Part of #1995.
This commit is contained in:
Dennis Guse
2025-02-13 22:12:39 +01:00
parent a6d318d970
commit d4e9b5d3d7
14 changed files with 157 additions and 131 deletions
@@ -549,23 +549,23 @@ public class ExportImportTest {
SensorDataSet sensorDataSet = trackPointCreator.getSensorManager().sensorDataSet; SensorDataSet sensorDataSet = trackPointCreator.getSensorManager().sensorDataSet;
AggregatorCyclingPower cyclingPower = Mockito.mock(AggregatorCyclingPower.class); AggregatorCyclingPower cyclingPower = Mockito.mock(AggregatorCyclingPower.class);
Mockito.when(cyclingPower.hasValue()).thenReturn(true); Mockito.when(cyclingPower.hasAggregatedValue()).thenReturn(true);
Mockito.when(cyclingPower.getValue(Mockito.any())).thenReturn(Power.of(power)); Mockito.when(cyclingPower.getAggregatedValue(Mockito.any())).thenReturn(Power.of(power));
sensorDataSet.add(cyclingPower); sensorDataSet.add(cyclingPower);
AggregatorHeartRate avgHeartRate = Mockito.mock(AggregatorHeartRate.class); AggregatorHeartRate avgHeartRate = Mockito.mock(AggregatorHeartRate.class);
Mockito.when(avgHeartRate.getValue(Mockito.any())).thenReturn(HeartRate.of(heartRate)); Mockito.when(avgHeartRate.getAggregatedValue(Mockito.any())).thenReturn(HeartRate.of(heartRate));
sensorDataSet.add(avgHeartRate); sensorDataSet.add(avgHeartRate);
AggregatorCyclingCadence cyclingCadence = Mockito.mock(AggregatorCyclingCadence.class); AggregatorCyclingCadence cyclingCadence = Mockito.mock(AggregatorCyclingCadence.class);
Mockito.when(cyclingCadence.hasValue()).thenReturn(true); Mockito.when(cyclingCadence.hasAggregatedValue()).thenReturn(true);
Mockito.when(cyclingCadence.getValue(Mockito.any())).thenReturn(Cadence.of(cadence)); Mockito.when(cyclingCadence.getAggregatedValue(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.hasAggregatedValue()).thenReturn(true);
Mockito.when(distanceSpeed.getValue(Mockito.any())).thenReturn(new AggregatorCyclingDistanceSpeed.Data(null, distance, Speed.of(speed))); Mockito.when(distanceSpeed.getAggregatedValue(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("", ""));
@@ -581,8 +581,8 @@ 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.hasAggregatedValue()).thenReturn(true);
Mockito.when(barometer.getValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); Mockito.when(barometer.getAggregatedValue(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));
@@ -24,7 +24,7 @@ public class AggregatorBarometerTest {
addSensorValue(subject, new float[]{1015f, 1015.01f, 1015.02f, 1015.03f, 1015.04f, 1015.05f, 1015.06f, 1015.07f, 1015.08f, 1015.09f, 1015.10f, 1015.11f, 1015.12f, 1015.13f, 1018f, 1018.1f, 1018.1f, 1018.1f, 1018.1f}); addSensorValue(subject, new float[]{1015f, 1015.01f, 1015.02f, 1015.03f, 1015.04f, 1015.05f, 1015.06f, 1015.07f, 1015.08f, 1015.09f, 1015.10f, 1015.11f, 1015.12f, 1015.13f, 1018f, 1018.1f, 1018.1f, 1018.1f, 1018.1f});
// then // then
Assert.assertEquals(0f, subject.value.gain_m(), 0.01); Assert.assertEquals(0f, subject.aggregatedValue.gain_m(), 0.01);
Assert.assertEquals(15f, subject.value.loss_m(), 0.01); Assert.assertEquals(15f, subject.aggregatedValue.loss_m(), 0.01);
} }
} }
@@ -2,7 +2,6 @@ package de.dennisguse.opentracks.sensors.sensorData;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -13,6 +12,7 @@ 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.data.models.Speed;
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingCadence; import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingCadence;
import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingDistanceSpeed; import de.dennisguse.opentracks.sensors.BluetoothHandlerCyclingDistanceSpeed;
import de.dennisguse.opentracks.sensors.UintUtils; import de.dennisguse.opentracks.sensors.UintUtils;
@@ -29,7 +29,7 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 2048))); current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 2048)));
// then // then
assertEquals(60, current.getValue(Instant.MIN).getRPM(), 0.01); assertEquals(60, current.getAggregatedValue(Instant.MIN).getRPM(), 0.01);
} }
@Test @Test
@@ -41,7 +41,7 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 8016))); current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 8016)));
// then // then
assertEquals(33.53, current.getValue(Instant.MIN).getRPM(), 0.01); assertEquals(33.53, current.getAggregatedValue(Instant.MIN).getRPM(), 0.01);
} }
@Test @Test
@@ -53,7 +53,7 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 2048))); current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(1, 2048)));
// then // then
assertEquals(Cadence.of(0), current.getValue(Instant.MIN)); assertEquals(Cadence.of(0), current.getAggregatedValue(Instant.MIN));
} }
@@ -66,7 +66,7 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, 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.hasAggregatedValue()); //TODO Cadence should be 0?
} }
@Test @Test
@@ -78,7 +78,7 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 0))); current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingCadence.CrankData(2, 0)));
// then // then
assertEquals(60, current.getValue(Instant.MIN).getRPM(), 0.01); assertEquals(60, current.getAggregatedValue(Instant.MIN).getRPM(), 0.01);
} }
@Test @Test
@@ -93,7 +93,7 @@ public class SensorDataCyclingTest {
// 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(Instant.MIN)); assertEquals(Cadence.of(0), current.getAggregatedValue(Instant.MIN));
} }
@Test @Test
@@ -106,8 +106,8 @@ public class SensorDataCyclingTest {
current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(2, 8016))); current.add(new Raw<>(Instant.MIN, new BluetoothHandlerCyclingDistanceSpeed.WheelData(2, 8016)));
// then // then
assertEquals(2.15, current.getValue(Instant.MIN).distance().toM(), 0.01); assertEquals(2.15, current.getAggregatedValue(Instant.MIN).distance().toM(), 0.01);
assertEquals(1.20, current.getValue(Instant.MIN).speed().toMPS(), 0.01); assertEquals(1.20, current.getAggregatedValue(Instant.MIN).speed().toMPS(), 0.01);
} }
@Test @Test
@@ -125,6 +125,6 @@ public class SensorDataCyclingTest {
// 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(Instant.MIN)); assertEquals(new AggregatorCyclingDistanceSpeed.Data(Distance.of(0), Distance.of(0), Speed.of(0)), current.getAggregatedValue(Instant.MIN));
} }
} }
@@ -729,8 +729,8 @@ 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.hasAggregatedValue()).thenReturn(true);
Mockito.when(barometer.getValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer; trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer;
} }
@@ -1,5 +1,7 @@
package de.dennisguse.opentracks.sensors.sensorData; package de.dennisguse.opentracks.sensors.sensorData;
import android.util.Pair;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.time.Instant; import java.time.Instant;
@@ -10,7 +12,7 @@ public abstract class Aggregator<Input, Output> {
protected Raw<Input> previous; protected Raw<Input> previous;
protected Output value; protected Output aggregatedValue;
private final String sensorAddress; private final String sensorAddress;
private final String sensorName; private final String sensorName;
@@ -35,27 +37,35 @@ public abstract class Aggregator<Input, Output> {
protected abstract void computeValue(Raw<Input> current); protected abstract void computeValue(Raw<Input> current);
public boolean hasValue() { public boolean hasAggregatedValue() {
return value != null; return aggregatedValue != null;
} }
@NonNull @NonNull
protected abstract Output getNoneValue(); protected abstract Output getNoneValue();
public Output getValue(Instant now) { @NonNull
if (!hasValue()) { public Output getAggregatedValue(Instant now) {
return null; //TODO Check if this is a good idea! if (!hasAggregatedValue()) {
return getNoneValue();
} }
//TODO This should only affect measured data (like heartrate), but not aggregated values.
//Remove current measurements, but provide aggregates?
if (isRecent(now)) { if (isRecent(now)) {
return value; return aggregatedValue;
} }
return getNoneValue(); return getNoneValue();
} }
@NonNull
public Pair<Output, String> getAggregatedValueWithSensorName(Instant now) {
return new Pair<>(getAggregatedValue(now), getSensorNameOrAddress());
}
/** /**
* Reset long term aggregated values (more than derived from previous SensorData). e.g. overall distance. * Reset long term aggregated values (more than derived from previous SensorData). e.g. overall distance.
*/ */
public void reset() {} public abstract void reset();
/** /**
* Is the data recent considering the current time. * Is the data recent considering the current time.
@@ -66,12 +76,12 @@ public abstract class Aggregator<Input, Output> {
} }
return now return now
.isBefore(previous.time().plus(BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE)); .isBefore(previous.time().plus(BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE)); //TODO Per Sensor!
} }
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return "sensorAddress=" + sensorAddress + " data=" + value; return "sensorAddress=" + sensorAddress + " data=" + aggregatedValue;
} }
} }
@@ -19,28 +19,28 @@ public class AggregatorBarometer extends Aggregator<AtmosphericPressure, Altitud
protected void computeValue(Raw<AtmosphericPressure> current) { protected void computeValue(Raw<AtmosphericPressure> current) {
if (previous == null) { if (previous == null) {
lastAcceptedSensorValue = current.value(); lastAcceptedSensorValue = current.value();
value = getNoneValue(); aggregatedValue = getNoneValue();
return; return;
} }
PressureSensorUtils.AltitudeChange altitudeChange = PressureSensorUtils.computeChangesWithSmoothing_m(lastAcceptedSensorValue, previous.value(), current.value()); PressureSensorUtils.AltitudeChange altitudeChange = PressureSensorUtils.computeChangesWithSmoothing_m(lastAcceptedSensorValue, previous.value(), current.value());
if (altitudeChange != null) { if (altitudeChange != null) {
value = new AltitudeGainLoss(value.gain_m() + altitudeChange.getAltitudeGain_m(), value.loss_m() + altitudeChange.getAltitudeLoss_m()); aggregatedValue = new AltitudeGainLoss(aggregatedValue.gain_m() + altitudeChange.getAltitudeGain_m(), aggregatedValue.loss_m() + altitudeChange.getAltitudeLoss_m());
lastAcceptedSensorValue = altitudeChange.currentSensorValue(); lastAcceptedSensorValue = altitudeChange.currentSensorValue();
} }
} }
@Override
public void reset() {
aggregatedValue = getNoneValue();
}
@NonNull @NonNull
@Override @Override
protected AltitudeGainLoss getNoneValue() { protected AltitudeGainLoss getNoneValue() {
return new AltitudeGainLoss(0f, 0f); return new AltitudeGainLoss(0f, 0f);
} }
@Override
public void reset() {
value = getNoneValue();
}
public record Data(Altitude gain, Altitude loss) {} public record Data(Altitude gain, Altitude loss) {}
} }
@@ -20,28 +20,34 @@ public class AggregatorCyclingCadence extends Aggregator<BluetoothHandlerCycling
@Override @Override
protected void computeValue(Raw<BluetoothHandlerCyclingCadence.CrankData> current) { protected void computeValue(Raw<BluetoothHandlerCyclingCadence.CrankData> current) {
if (previous != null) { if (previous == null) {
float timeDiff_ms = UintUtils.diff(current.value().crankRevolutionsTime(), previous.value().crankRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000; return;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
value = null;
return;
}
// TODO We have to treat with overflow according to the documentation: read https://github.com/OpenTracksApp/OpenTracks/pull/953#discussion_r711625268
if (current.value().crankRevolutionsCount() < previous.value().crankRevolutionsCount()) {
Log.e(TAG, "Crank revolutions count difference is invalid: cannot compute cadence.");
return;
}
long crankDiff = UintUtils.diff(current.value().crankRevolutionsCount(), previous.value().crankRevolutionsCount(), UintUtils.UINT32_MAX);
value = Cadence.of(crankDiff, timeDiff);
} }
float timeDiff_ms = UintUtils.diff(current.value().crankRevolutionsTime(), previous.value().crankRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
aggregatedValue = null;
return;
}
// TODO We have to treat with overflow according to the documentation: read https://github.com/OpenTracksApp/OpenTracks/pull/953#discussion_r711625268
if (current.value().crankRevolutionsCount() < previous.value().crankRevolutionsCount()) {
Log.e(TAG, "Crank revolutions count difference is invalid: cannot compute cadence.");
return;
}
long crankDiff = UintUtils.diff(current.value().crankRevolutionsCount(), previous.value().crankRevolutionsCount(), UintUtils.UINT32_MAX);
aggregatedValue = Cadence.of(crankDiff, timeDiff);
}
@Override
public void reset() {
} }
@NonNull @NonNull
@@ -23,47 +23,49 @@ public class AggregatorCyclingDistanceSpeed extends Aggregator<BluetoothHandlerC
@Override @Override
protected void computeValue(Raw<BluetoothHandlerCyclingDistanceSpeed.WheelData> current) { protected void computeValue(Raw<BluetoothHandlerCyclingDistanceSpeed.WheelData> current) {
if (previous != null) { if (previous == null) {
float timeDiff_ms = UintUtils.diff(current.value().wheelRevolutionsTime(), previous.value().wheelRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000; return;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
value = null;
return;
}
if (current.value().wheelRevolutionsCount() < previous.value().wheelRevolutionsCount()) {
Log.e(TAG, "Wheel revolutions count difference is invalid: cannot compute speed.");
return;
}
long wheelDiff = UintUtils.diff(current.value().wheelRevolutionsCount(), previous.value().wheelRevolutionsCount(), UintUtils.UINT32_MAX);
Distance distance = wheelCircumference.multipliedBy(wheelDiff);
Distance distanceOverall = distance;
if (value != null) {
distanceOverall = distance.plus(value.distanceOverall);
}
Speed speed_mps = Speed.of(distance, timeDiff);
value = new Data(distance, distanceOverall, speed_mps);
} }
float timeDiff_ms = UintUtils.diff(current.value().wheelRevolutionsTime(), previous.value().wheelRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
aggregatedValue = null;
return;
}
if (current.value().wheelRevolutionsCount() < previous.value().wheelRevolutionsCount()) {
Log.e(TAG, "Wheel revolutions count difference is invalid: cannot compute speed.");
return;
}
long wheelDiff = UintUtils.diff(current.value().wheelRevolutionsCount(), previous.value().wheelRevolutionsCount(), UintUtils.UINT32_MAX);
Distance distance = wheelCircumference.multipliedBy(wheelDiff);
Distance distanceOverall = distance;
if (aggregatedValue != null) {
distanceOverall = distance.plus(aggregatedValue.distanceOverall);
}
Speed speed_mps = Speed.of(distance, timeDiff);
aggregatedValue = new Data(distance, distanceOverall, speed_mps);
} }
@Override @Override
public void reset() { public void reset() {
if (value != null) { if (aggregatedValue != null) {
value = new Data(value.distance, Distance.of(0), value.speed); aggregatedValue = new Data(aggregatedValue.distance, Distance.of(0), aggregatedValue.speed);
} }
} }
@NonNull @NonNull
@Override @Override
protected Data getNoneValue() { protected Data getNoneValue() {
if (value != null) { if (aggregatedValue != null) {
return new Data(value.distance, value.distanceOverall, Speed.zero()); return new Data(aggregatedValue.distance, aggregatedValue.distanceOverall, Speed.zero());
} else { } else {
return new Data(Distance.of(0), Distance.of(0), Speed.zero()); return new Data(Distance.of(0), Distance.of(0), Speed.zero());
} }
@@ -13,7 +13,11 @@ public class AggregatorCyclingPower extends Aggregator<BluetoothHandlerManagerCy
@Override @Override
public void computeValue(Raw<BluetoothHandlerManagerCyclingPower.Data> current) { public void computeValue(Raw<BluetoothHandlerManagerCyclingPower.Data> current) {
this.value = current.value().power(); this.aggregatedValue = current.value().power();
}
@Override
public void reset() {
} }
@NonNull @NonNull
@@ -13,12 +13,11 @@ public class AggregatorGPS extends Aggregator<Position, Position> {
@Override @Override
protected void computeValue(Raw<Position> current) { protected void computeValue(Raw<Position> current) {
value = current.value(); aggregatedValue = current.value();
} }
@Override @Override
public void reset() { public void reset() {
value = null;
} }
@NonNull @NonNull
@@ -12,7 +12,11 @@ public class AggregatorHeartRate extends Aggregator<HeartRate, HeartRate> {
@Override @Override
protected void computeValue(Raw<HeartRate> current) { protected void computeValue(Raw<HeartRate> current) {
this.value = current.value(); this.aggregatedValue = current.value();
}
@Override
public void reset() {
} }
@NonNull @NonNull
@@ -20,32 +20,33 @@ public final class AggregatorRunning extends Aggregator<BluetoothHandlerRunningS
@Override @Override
public void computeValue(Raw<BluetoothHandlerRunningSpeedAndCadence.Data> current) { public void computeValue(Raw<BluetoothHandlerRunningSpeedAndCadence.Data> current) {
if (previous != null) { if (previous == null) {
return;
Distance distance = null;
if (previous.value().totalDistance() != null && current.value().totalDistance() != null) {
distance = current.value().totalDistance().minus(previous.value().totalDistance());
if (value != null) {
distance = distance.plus(value.distance);
}
}
value = new Data(current.value().speed(), current.value().cadence(), distance);
} }
Distance distance = null;
if (previous.value().totalDistance() != null && current.value().totalDistance() != null) {
distance = current.value().totalDistance().minus(previous.value().totalDistance());
if (aggregatedValue != null) {
distance = distance.plus(aggregatedValue.distance);
}
}
aggregatedValue = new Data(current.value().speed(), current.value().cadence(), distance);
} }
@Override @Override
public void reset() { public void reset() {
if (value != null) { if (aggregatedValue != null) {
value = new Data(value.speed, value.cadence, Distance.of(0)); aggregatedValue = new Data(aggregatedValue.speed, aggregatedValue.cadence, Distance.of(0));
} }
} }
@NonNull @NonNull
@Override @Override
protected Data getNoneValue() { protected Data getNoneValue() {
if (value != null) { if (aggregatedValue != null) {
return new Data(Speed.zero(), Cadence.of(0f), value.distance); return new Data(Speed.zero(), Cadence.of(0f), aggregatedValue.distance);
} else { } else {
return new Data(Speed.zero(), Cadence.of(0f), Distance.of(0)); return new Data(Speed.zero(), Cadence.of(0f), Distance.of(0));
} }
@@ -44,7 +44,7 @@ public class SensorDataSet {
public AggregatorGPS gps; public AggregatorGPS gps;
private TrackPointCreator trackPointCreator; private final TrackPointCreator trackPointCreator;
public SensorDataSet(TrackPointCreator trackPointCreator) { public SensorDataSet(TrackPointCreator trackPointCreator) {
this.trackPointCreator = trackPointCreator; this.trackPointCreator = trackPointCreator;
@@ -64,7 +64,7 @@ public class SensorDataSet {
public Pair<HeartRate, String> getHeartRate() { public Pair<HeartRate, String> getHeartRate() {
if (heartRate != null) { if (heartRate != null) {
return new Pair<>(heartRate.getValue(trackPointCreator.createNow()), heartRate.getSensorNameOrAddress()); return heartRate.getAggregatedValueWithSensorName(trackPointCreator.createNow());
} }
return null; return null;
@@ -72,23 +72,23 @@ public class SensorDataSet {
public Pair<Cadence, String> getCadence() { public Pair<Cadence, String> getCadence() {
if (cyclingCadence != null) { if (cyclingCadence != null) {
return new Pair<>(cyclingCadence.getValue(trackPointCreator.createNow()), cyclingCadence.getSensorNameOrAddress()); return cyclingCadence.getAggregatedValueWithSensorName(trackPointCreator.createNow());
} }
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.value.cadence() != null) { if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasAggregatedValue() && runningDistanceSpeedCadence.aggregatedValue.cadence() != null) {
return new Pair<>(runningDistanceSpeedCadence.value.cadence(), runningDistanceSpeedCadence.getSensorNameOrAddress()); return new Pair<>(runningDistanceSpeedCadence.aggregatedValue.cadence(), runningDistanceSpeedCadence.getSensorNameOrAddress());
} }
return null; return null;
} }
public Pair<Speed, String> getSpeed() { public Pair<Speed, String> getSpeed() {
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue() && cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).speed() != null) { if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasAggregatedValue() && cyclingDistanceSpeed.getAggregatedValue(trackPointCreator.createNow()).speed() != null) {
return new Pair<>(cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).speed(), cyclingDistanceSpeed.getSensorNameOrAddress()); return new Pair<>(cyclingDistanceSpeed.getAggregatedValue(trackPointCreator.createNow()).speed(), cyclingDistanceSpeed.getSensorNameOrAddress());
} }
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue(trackPointCreator.createNow()).speed() != null) { if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasAggregatedValue() && runningDistanceSpeedCadence.getAggregatedValue(trackPointCreator.createNow()).speed() != null) {
return new Pair<>(runningDistanceSpeedCadence.value.speed(), runningDistanceSpeedCadence.getSensorNameOrAddress()); return new Pair<>(runningDistanceSpeedCadence.aggregatedValue.speed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
} }
return null; return null;
@@ -156,8 +156,8 @@ public class SensorDataSet {
} }
public void fillTrackPoint(TrackPoint trackPoint) { public void fillTrackPoint(TrackPoint trackPoint) {
if (gps != null && gps.hasValue()) { if (gps != null && gps.hasAggregatedValue()) {
trackPoint.setPosition(gps.getValue(trackPointCreator.createNow())); trackPoint.setPosition(gps.getAggregatedValue(trackPointCreator.createNow()));
} }
if (getHeartRate() != null) { if (getHeartRate() != null) {
@@ -172,21 +172,21 @@ public class SensorDataSet {
trackPoint.setSpeed(getSpeed().first); trackPoint.setSpeed(getSpeed().first);
} }
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue()) { if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasAggregatedValue()) {
trackPoint.setSensorDistance(cyclingDistanceSpeed.getValue(trackPointCreator.createNow()).distanceOverall()); trackPoint.setSensorDistance(cyclingDistanceSpeed.getAggregatedValue(trackPointCreator.createNow()).distanceOverall());
} }
if (cyclingPower != null && cyclingPower.hasValue()) { if (cyclingPower != null && cyclingPower.hasAggregatedValue()) {
trackPoint.setPower(cyclingPower.getValue(trackPointCreator.createNow())); trackPoint.setPower(cyclingPower.getAggregatedValue(trackPointCreator.createNow()));
} }
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) { if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasAggregatedValue()) {
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue(trackPointCreator.createNow()).distance()); trackPoint.setSensorDistance(runningDistanceSpeedCadence.getAggregatedValue(trackPointCreator.createNow()).distance());
} }
if (barometer != null && barometer.hasValue()) { if (barometer != null && barometer.hasAggregatedValue()) {
trackPoint.setAltitudeGain(barometer.getValue(trackPointCreator.createNow()).gain_m()); trackPoint.setAltitudeGain(barometer.getAggregatedValue(trackPointCreator.createNow()).gain_m());
trackPoint.setAltitudeLoss(barometer.getValue(trackPointCreator.createNow()).loss_m()); trackPoint.setAltitudeLoss(barometer.getAggregatedValue(trackPointCreator.createNow()).loss_m());
} }
} }
@@ -94,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(Instant.now())); //TODO Use MonotonicClock valueAndUnit = StringUtils.getPowerParts(getContext(), sensorDataSet.getCyclingPower().getAggregatedValue(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);