Merge pull request #1710 from OpenTracksApp/cleanup

Cleanup: use record if possible
This commit is contained in:
Dennis Guse
2023-09-28 21:58:17 +02:00
committed by GitHub
17 changed files with 183 additions and 262 deletions
@@ -1,7 +1,6 @@
package de.dennisguse.opentracks;
import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
@@ -12,7 +11,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withParentIndex;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static de.dennisguse.opentracks.util.EspressoUtils.childAtPosition;
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
@@ -1,6 +1,5 @@
package de.dennisguse.opentracks;
import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
@@ -11,7 +10,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withParentIndex;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static de.dennisguse.opentracks.util.EspressoUtils.selectTabAtIndex;
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
@@ -27,10 +27,10 @@ public class ChartPointTest {
statistics.setTotalTime(Duration.ofSeconds(1000));
// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);
// then
assertEquals(1000000, (long) point.getTimeOrDistance());
assertEquals(1000000, (long) point.timeOrDistance());
}
@Test
@@ -40,10 +40,10 @@ public class ChartPointTest {
statistics.setTotalDistance(Distance.of(1000));
// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);
// then
assertEquals(1, (long) point.getTimeOrDistance());
assertEquals(1, (long) point.timeOrDistance());
}
@Test
@@ -54,12 +54,12 @@ public class ChartPointTest {
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertEquals(50, point.getAltitude(), 0.01);
assertEquals(36, point.getSpeed(), 0.01);
assertEquals(1.66, point.getPace(), 0.01);
assertEquals(50, point.altitude(), 0.01);
assertEquals(36, point.speed(), 0.01);
assertEquals(1.66, point.pace(), 0.01);
}
@Test
@@ -69,12 +69,12 @@ public class ChartPointTest {
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertNull(point.getHeartRate());
assertNull(point.getCadence());
assertNull(point.getPower());
assertNull(point.heartRate());
assertNull(point.cadence());
assertNull(point.power());
}
@Test
@@ -89,11 +89,11 @@ public class ChartPointTest {
TrackStatistics statistics = new TrackStatistics();
// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertEquals(100.0, point.getHeartRate(), 0.01);
assertEquals(101.0, point.getCadence(), 0.01);
assertEquals(102.0, point.getPower(), 0.01);
assertEquals(100.0, point.heartRate(), 0.01);
assertEquals(101.0, point.cadence(), 0.01);
assertEquals(102.0, point.power(), 0.01);
}
}
@@ -54,7 +54,7 @@ public class ChartValueSeriesTest {
18) {
@Override
Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getAltitude();
return chartPoint.altitude();
}
@Override
@@ -80,9 +80,9 @@ public class ChartValueSeriesTest {
@Test
public void testVerySmallUpdates() {
series.update(new ChartPoint(1f));
series.update(new ChartPoint(2f));
series.update(new ChartPoint(3f));
series.update(withAltitude(1f));
series.update(withAltitude(2f));
series.update(withAltitude(3f));
series.updateDimension();
assertEquals(1, series.getInterval());
assertEquals(1, series.getMinMarkerValue());
@@ -91,8 +91,8 @@ public class ChartValueSeriesTest {
@Test
public void testSmallUpdates() {
series.update(new ChartPoint(0));
series.update(new ChartPoint(10));
series.update(withAltitude(0));
series.update(withAltitude(10));
series.updateDimension();
assertEquals(100, series.getInterval());
assertEquals(0, series.getMinMarkerValue());
@@ -101,8 +101,8 @@ public class ChartValueSeriesTest {
@Test
public void testBigUpdates() {
series.update(new ChartPoint(0));
series.update(new ChartPoint(901));
series.update(withAltitude(0));
series.update(withAltitude(901));
series.updateDimension();
assertEquals(1000, series.getInterval());
assertEquals(0, series.getMinMarkerValue());
@@ -111,11 +111,23 @@ public class ChartValueSeriesTest {
@Test
public void testNotZeroBasedUpdates() {
series.update(new ChartPoint(220));
series.update(new ChartPoint(250));
series.update(withAltitude(220));
series.update(withAltitude(250));
series.updateDimension();
assertEquals(100, series.getInterval());
assertEquals(200, series.getMinMarkerValue());
assertEquals(700, series.getMaxMarkerValue());
}
static ChartPoint withAltitude(double altitude) {
return new ChartPoint(
0,
altitude,
null,
null,
null,
null,
null
);
}
}
@@ -986,13 +986,13 @@ public class CustomContentProviderUtilsTest {
// then
assertTrue(sensorStatistics.hasHeartRate());
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertTrue(sensorStatistics.hasCadence());
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertTrue(sensorStatistics.hasPower());
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}
@Test
@@ -1018,8 +1018,8 @@ public class CustomContentProviderUtilsTest {
// then
assertTrue(sensorStatistics.hasHeartRate());
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertFalse(sensorStatistics.hasCadence());
assertFalse(sensorStatistics.hasPower());
}
@@ -1048,8 +1048,8 @@ public class CustomContentProviderUtilsTest {
// then
assertFalse(sensorStatistics.hasHeartRate());
assertTrue(sensorStatistics.hasCadence());
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertFalse(sensorStatistics.hasPower());
}
@@ -1078,7 +1078,7 @@ public class CustomContentProviderUtilsTest {
assertFalse(sensorStatistics.hasHeartRate());
assertFalse(sensorStatistics.hasCadence());
assertTrue(sensorStatistics.hasPower());
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}
@Test
@@ -1111,11 +1111,11 @@ public class CustomContentProviderUtilsTest {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();
// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}
@Test
@@ -1156,11 +1156,11 @@ public class CustomContentProviderUtilsTest {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();
// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}
@Test
@@ -1201,11 +1201,11 @@ public class CustomContentProviderUtilsTest {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();
// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}
private void testGetSensorStats_randomData(int totalPoints, boolean withStartSegments) {
@@ -1232,11 +1232,11 @@ public class CustomContentProviderUtilsTest {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();
// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0.01f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0.01f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0.01f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0.01f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0.01f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0.01f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0.01f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0.01f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0.01f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0.01f);
}
@Test
@@ -23,8 +23,8 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertNull(selection.getSelection());
assertNull(selection.getSelectionArgs());
assertNull(selection.selection());
assertNull(selection.selectionArgs());
}
@Test
@@ -37,9 +37,9 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "_id IN (?)");
assertEquals(selection.getSelectionArgs().length, 1);
assertEquals(selection.getSelectionArgs()[0], "1");
assertEquals(selection.selection(), "_id IN (?)");
assertEquals(selection.selectionArgs().length, 1);
assertEquals(selection.selectionArgs()[0], "1");
}
@Test
@@ -57,11 +57,11 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "_id IN (?,?,?)");
assertEquals(selection.getSelectionArgs().length, 3);
assertEquals(selection.getSelectionArgs()[0], "1");
assertEquals(selection.getSelectionArgs()[1], "2");
assertEquals(selection.getSelectionArgs()[2], "3");
assertEquals(selection.selection(), "_id IN (?,?,?)");
assertEquals(selection.selectionArgs().length, 3);
assertEquals(selection.selectionArgs()[0], "1");
assertEquals(selection.selectionArgs()[1], "2");
assertEquals(selection.selectionArgs()[2], "3");
}
@Test
@@ -73,9 +73,9 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "category IN (?)");
assertEquals(selection.getSelectionArgs().length, 1);
assertEquals(selection.getSelectionArgs()[0], "running");
assertEquals(selection.selection(), "category IN (?)");
assertEquals(selection.selectionArgs().length, 1);
assertEquals(selection.selectionArgs()[0], "running");
}
@Test
@@ -91,12 +91,12 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "category IN (?,?,?,?)");
assertEquals(selection.getSelectionArgs().length, 4);
assertEquals(selection.getSelectionArgs()[0], "running");
assertEquals(selection.getSelectionArgs()[1], "road biking");
assertEquals(selection.getSelectionArgs()[2], "mountain biking");
assertEquals(selection.getSelectionArgs()[3], "trail walking");
assertEquals(selection.selection(), "category IN (?,?,?,?)");
assertEquals(selection.selectionArgs().length, 4);
assertEquals(selection.selectionArgs()[0], "running");
assertEquals(selection.selectionArgs()[1], "road biking");
assertEquals(selection.selectionArgs()[2], "mountain biking");
assertEquals(selection.selectionArgs()[3], "trail walking");
}
@Test
@@ -114,16 +114,16 @@ public class TrackSelectionTest extends TestCase {
SelectionData selectionOk = filterOk.buildSelection();
// Then
assertNull(selectionWrong1.getSelection());
assertNull(selectionWrong1.getSelectionArgs());
assertNull(selectionWrong1.selection());
assertNull(selectionWrong1.selectionArgs());
assertNull(selectionWrong2.getSelection());
assertNull(selectionWrong2.getSelectionArgs());
assertNull(selectionWrong2.selection());
assertNull(selectionWrong2.selectionArgs());
assertEquals(selectionOk.getSelection(), "starttime BETWEEN ? AND ?");
assertEquals(selectionOk.getSelectionArgs().length, 2);
assertEquals(selectionOk.getSelectionArgs()[0], Long.toString(instant.toEpochMilli()));
assertEquals(selectionOk.getSelectionArgs()[1], Long.toString(instant.toEpochMilli() + oneDay));
assertEquals(selectionOk.selection(), "starttime BETWEEN ? AND ?");
assertEquals(selectionOk.selectionArgs().length, 2);
assertEquals(selectionOk.selectionArgs()[0], Long.toString(instant.toEpochMilli()));
assertEquals(selectionOk.selectionArgs()[1], Long.toString(instant.toEpochMilli() + oneDay));
}
@Test
@@ -143,13 +143,13 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "_id IN (?,?,?) AND category IN (?,?)");
assertEquals(selection.getSelectionArgs().length, 5);
assertEquals(selection.getSelectionArgs()[0], "1");
assertEquals(selection.getSelectionArgs()[1], "2");
assertEquals(selection.getSelectionArgs()[2], "3");
assertEquals(selection.getSelectionArgs()[3], "running");
assertEquals(selection.getSelectionArgs()[4], "road biking");
assertEquals(selection.selection(), "_id IN (?,?,?) AND category IN (?,?)");
assertEquals(selection.selectionArgs().length, 5);
assertEquals(selection.selectionArgs()[0], "1");
assertEquals(selection.selectionArgs()[1], "2");
assertEquals(selection.selectionArgs()[2], "3");
assertEquals(selection.selectionArgs()[3], "running");
assertEquals(selection.selectionArgs()[4], "road biking");
}
@Test
@@ -172,13 +172,13 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "_id IN (?,?,?) AND starttime BETWEEN ? AND ?");
assertEquals(selection.getSelectionArgs().length, 5);
assertEquals(selection.getSelectionArgs()[0], "1");
assertEquals(selection.getSelectionArgs()[1], "2");
assertEquals(selection.getSelectionArgs()[2], "3");
assertEquals(selection.getSelectionArgs()[3], Long.toString(instant.toEpochMilli()));
assertEquals(selection.getSelectionArgs()[4], Long.toString(instant.toEpochMilli() + oneDay));
assertEquals(selection.selection(), "_id IN (?,?,?) AND starttime BETWEEN ? AND ?");
assertEquals(selection.selectionArgs().length, 5);
assertEquals(selection.selectionArgs()[0], "1");
assertEquals(selection.selectionArgs()[1], "2");
assertEquals(selection.selectionArgs()[2], "3");
assertEquals(selection.selectionArgs()[3], Long.toString(instant.toEpochMilli()));
assertEquals(selection.selectionArgs()[4], Long.toString(instant.toEpochMilli() + oneDay));
}
@Test
@@ -196,11 +196,11 @@ public class TrackSelectionTest extends TestCase {
SelectionData selection = filter.buildSelection();
// Then
assertEquals(selection.getSelection(), "category IN (?,?) AND starttime BETWEEN ? AND ?");
assertEquals(selection.getSelectionArgs().length, 4);
assertEquals(selection.getSelectionArgs()[0], "running");
assertEquals(selection.getSelectionArgs()[1], "road biking");
assertEquals(selection.getSelectionArgs()[2], Long.toString(instant.toEpochMilli()));
assertEquals(selection.getSelectionArgs()[3], Long.toString(instant.toEpochMilli() + oneDay));
assertEquals(selection.selection(), "category IN (?,?) AND starttime BETWEEN ? AND ?");
assertEquals(selection.selectionArgs().length, 4);
assertEquals(selection.selectionArgs()[0], "running");
assertEquals(selection.selectionArgs()[1], "road biking");
assertEquals(selection.selectionArgs()[2], Long.toString(instant.toEpochMilli()));
assertEquals(selection.selectionArgs()[3], Long.toString(instant.toEpochMilli() + oneDay));
}
}
@@ -188,7 +188,7 @@ public class ChartFragment extends Fragment implements TrackDataHub.Listener {
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics) {
if (isResumed()) {
ChartPoint point = new ChartPoint(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem());
ChartPoint point = ChartPoint.create(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem());
pendingPoints.add(point);
}
}
@@ -1,7 +1,6 @@
package de.dennisguse.opentracks.chart;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed;
@@ -9,81 +8,43 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics;
public class ChartPoint {
//X-axis
private double timeOrDistance;
public record ChartPoint(
//X-axis
double timeOrDistance,
//Y-axis
private Double altitude;
private Double speed;
private Double pace;
private Double heartRate;
private Double cadence;
private Double power;
//Y-axis
Double altitude,
Double speed,
Double pace,
Double heartRate,
Double cadence,
Double power
) {
@Deprecated
@VisibleForTesting
ChartPoint(double altitude) {
this.altitude = altitude;
}
public ChartPoint(@NonNull TrackStatistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
if (chartByDistance) {
timeOrDistance = trackStatistics.getTotalDistance().toKM_Miles(unitSystem);
} else {
timeOrDistance = trackStatistics.getTotalTime().toMillis();
}
if (trackPoint.hasAltitude()) {
altitude = Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem);
}
if (smoothedSpeed != null) {
speed = smoothedSpeed.to(unitSystem);
pace = smoothedSpeed.toPace(unitSystem).toSeconds() / 60d;
}
if (trackPoint.hasHeartRate()) {
heartRate = (double) trackPoint.getHeartRate().getBPM();
}
if (trackPoint.hasCadence()) {
cadence = (double) trackPoint.getCadence().getRPM();
}
if (trackPoint.hasPower()) {
power = (double) trackPoint.getPower().getW();
}
}
public double getTimeOrDistance() {
return timeOrDistance;
}
public Double getAltitude() {
return altitude;
}
public Double getSpeed() {
return speed;
}
public Double getPace() {
return pace;
}
public Double getHeartRate() {
return heartRate;
}
public Double getCadence() {
return cadence;
}
public Double getPower() {
return power;
}
@NonNull
@Override
public String toString() {
return "ChartPoint{" + "timeOrDistance=" + timeOrDistance + '}';
public static ChartPoint create(@NonNull TrackStatistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
return new ChartPoint(
chartByDistance
? trackStatistics.getTotalDistance().toKM_Miles(unitSystem)
: trackStatistics.getTotalTime().toMillis(),
trackPoint.hasAltitude()
? Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem)
: null,
smoothedSpeed != null
? smoothedSpeed.to(unitSystem)
: null,
smoothedSpeed != null
? smoothedSpeed.toPace(unitSystem).toSeconds() / 60d
: null,
trackPoint.hasHeartRate()
? (double) trackPoint.getHeartRate().getBPM()
: null,
trackPoint.hasCadence()
? (double) trackPoint.getCadence().getRPM()
: null,
trackPoint.hasPower()
? (double) trackPoint.getPower().getW()
: null
);
}
}
@@ -210,7 +210,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getAltitude();
return chartPoint.altitude();
}
@Override
@@ -232,7 +232,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getSpeed();
return chartPoint.speed();
}
@Override
@@ -255,7 +255,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getPace();
return chartPoint.pace();
}
@Override
@@ -278,7 +278,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getHeartRate();
return chartPoint.heartRate();
}
@Override
@@ -300,7 +300,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getCadence();
return chartPoint.cadence();
}
@Override
@@ -321,7 +321,7 @@ public class ChartView extends View {
fontSizeMedium) {
@Override
protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getPower();
return chartPoint.power();
}
@Override
@@ -425,7 +425,7 @@ public class ChartView extends View {
synchronized (chartPoints) {
chartPoints.addAll(dataPoints);
for (ChartPoint dataPoint : dataPoints) {
xExtremityMonitor.update(dataPoint.getTimeOrDistance());
xExtremityMonitor.update(dataPoint.timeOrDistance());
for (ChartValueSeries i : seriesList) {
i.update(dataPoint);
}
@@ -887,7 +887,7 @@ public class ChartView extends View {
}
double value = series.extractDataFromChartPoint(point);
int x = getX(point.getTimeOrDistance());
int x = getX(point.timeOrDistance());
int y = getY(series, value);
// start from lower left corner
@@ -216,7 +216,7 @@ public class ContentProviderUtils {
public List<Track> getTracks(ContentProviderSelectionInterface selection) {
SelectionData selectionData = selection.buildSelection();
ArrayList<Track> tracks = new ArrayList<>();
try (Cursor cursor = getTrackCursor(selectionData.getSelection(), selectionData.getSelectionArgs(), TracksColumns._ID)) {
try (Cursor cursor = getTrackCursor(selectionData.selection(), selectionData.selectionArgs(), TracksColumns._ID)) {
if (cursor != null && cursor.moveToFirst()) {
tracks.ensureCapacity(cursor.getCount());
do {
@@ -1,24 +1,11 @@
package de.dennisguse.opentracks.data;
public class SelectionData {
private final String selection;
private final String[] selectionArgs;
public record SelectionData(
String selection,
String[] selectionArgs
) {
public SelectionData() {
selection = null;
selectionArgs = null;
}
public SelectionData(String selection, String[] selectionArgs) {
this.selection = selection;
this.selectionArgs = selectionArgs;
}
public String getSelection() {
return selection;
}
public String[] getSelectionArgs() {
return selectionArgs;
this(null, null);
}
}
@@ -254,24 +254,24 @@ public class StatisticsRecordedFragment extends Fragment {
}
if (sensorStatistics.hasHeartRate()) {
String maxBPM = String.valueOf(Math.round(sensorStatistics.getMaxHeartRate().getBPM()));
String avgBPM = String.valueOf(Math.round(sensorStatistics.getAvgHeartRate().getBPM()));
String maxBPM = String.valueOf(Math.round(sensorStatistics.maxHeartRate().getBPM()));
String avgBPM = String.valueOf(Math.round(sensorStatistics.avgHeartRate().getBPM()));
viewBinding.statsHeartRateGroup.setVisibility(View.VISIBLE);
viewBinding.statsMaxHeartRateValue.setText(maxBPM);
viewBinding.statsAvgHeartRateValue.setText(avgBPM);
}
if (sensorStatistics.hasCadence()) {
String maxRPM = String.valueOf(Math.round(sensorStatistics.getMaxCadence().getRPM()));
String avgRPM = String.valueOf(Math.round(sensorStatistics.getAvgCadence().getRPM()));
String maxRPM = String.valueOf(Math.round(sensorStatistics.maxCadence().getRPM()));
String avgRPM = String.valueOf(Math.round(sensorStatistics.avgCadence().getRPM()));
viewBinding.statsCadenceGroup.setVisibility(View.VISIBLE);
viewBinding.statsMaxCadenceValue.setText(maxRPM);
viewBinding.statsAvgCadenceValue.setText(avgRPM);
}
if (sensorStatistics.hasPower()) {
String maxW = String.valueOf(Math.round(sensorStatistics.getMaxPower().getW()));
String avgW = String.valueOf(Math.round(sensorStatistics.getAvgPower().getW()));
String maxW = String.valueOf(Math.round(sensorStatistics.maxPower().getW()));
String avgW = String.valueOf(Math.round(sensorStatistics.avgPower().getW()));
viewBinding.statsPowerGroup.setVisibility(View.VISIBLE);
viewBinding.statsMaxPowerValue.setText(maxW);
@@ -85,7 +85,7 @@ public class KMLTrackExporter implements TrackExporter {
private PrintWriter printWriter;
private ArrayList<TrackPoint.Type> trackpointTypeList = new ArrayList<>();
private final ArrayList<TrackPoint.Type> trackpointTypeList = new ArrayList<>();
private final List<Float> speedList = new ArrayList<>();
private final List<Float> distanceList = new ArrayList<>();
@@ -249,7 +249,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
if (notificationManager == null) {
StringWriter writer = new StringWriter();
Exception e = new RuntimeException("TrackRecording.newGpsStatus() called after onDestroy(); objectID: " + this + " with thread: " + Thread.currentThread().toString());
Exception e = new RuntimeException("TrackRecording.newGpsStatus() called after onDestroy(); objectID: " + this + " with thread: " + Thread.currentThread());
e.printStackTrace(new PrintWriter(writer));
Log.e(TAG, e.getMessage() + " " + writer);
@@ -138,7 +138,7 @@ class VoiceAnnouncementUtils {
}
if (shouldVoiceAnnounceAverageHeartRate() && sensorStatistics != null && sensorStatistics.hasHeartRate()) {
int averageHeartRate = Math.round(sensorStatistics.getAvgHeartRate().getBPM());
int averageHeartRate = Math.round(sensorStatistics.avgHeartRate().getBPM());
builder.append(" ")
.append(context.getString(R.string.average_heart_rate));
@@ -4,56 +4,24 @@ import de.dennisguse.opentracks.data.models.Cadence;
import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Power;
public class SensorStatistics {
private final HeartRate maxHr;
private final HeartRate avgHr;
private final Cadence maxCadence;
private final Cadence avgCadence;
private final Power maxPower;
private final Power avgPower;
public SensorStatistics(HeartRate maxHr, HeartRate avgHr, Cadence maxCadence, Cadence avgCadence, Power maxPower, Power avgPower) {
this.maxHr = maxHr;
this.avgHr = avgHr;
this.maxCadence = maxCadence;
this.avgCadence = avgCadence;
this.maxPower = maxPower;
this.avgPower = avgPower;
}
public record SensorStatistics(
HeartRate maxHeartRate,
HeartRate avgHeartRate,
Cadence maxCadence,
Cadence avgCadence,
Power maxPower,
Power avgPower
) {
public boolean hasHeartRate() {
return avgHr != null && maxHr != null;
}
public HeartRate getMaxHeartRate() {
return maxHr;
}
public HeartRate getAvgHeartRate() {
return avgHr;
return avgHeartRate != null && maxHeartRate != null;
}
public boolean hasCadence() {
return avgCadence != null && maxCadence != null;
}
public Cadence getMaxCadence() {
return maxCadence;
}
public Cadence getAvgCadence() {
return avgCadence;
}
public boolean hasPower() {
return avgPower != null;
}
public Power getMaxPower() {
return maxPower;
}
public Power getAvgPower() {
return avgPower;
}
}
@@ -14,7 +14,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
@@ -23,9 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.io.IOException;
import java.io.InputStream;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;