forked from upstream-mirrors/OpenTracks
For TrackStatisticsUpdater there may no pre-existing Statistics.
This commit is contained in:
@@ -70,7 +70,9 @@ public record Statistics(
|
|||||||
*/
|
*/
|
||||||
//TODO Should be refactored to append only
|
//TODO Should be refactored to append only
|
||||||
@NonNull
|
@NonNull
|
||||||
public Statistics merge(@NonNull Statistics other) {
|
public Statistics merge(Statistics other) {
|
||||||
|
if (other == null) return this;
|
||||||
|
|
||||||
HeartRate newAvgHeartRate = avgHeartRate;
|
HeartRate newAvgHeartRate = avgHeartRate;
|
||||||
if (avgHeartRate == null) {
|
if (avgHeartRate == null) {
|
||||||
newAvgHeartRate = other.avgHeartRate;
|
newAvgHeartRate = other.avgHeartRate;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class SegmentStatisticUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Statistics merge(Statistics statistics) {
|
public Statistics merge(Statistics statistics) {
|
||||||
return statistics.merge(getStatistics());
|
return getStatistics().merge(statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
|
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
|
||||||
|
|
||||||
@NonNull
|
private Statistics statisticsWithoutCurrentSegment = null;
|
||||||
private Statistics statisticsWithoutCurrentSegment;
|
|
||||||
|
|
||||||
private float averageHeartRateBPM;
|
private float averageHeartRateBPM;
|
||||||
private Duration totalHeartRateDuration = Duration.ZERO;
|
private Duration totalHeartRateDuration = Duration.ZERO;
|
||||||
@@ -56,18 +55,11 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private boolean isIdle;
|
private boolean isIdle;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public TrackStatisticsUpdater() {
|
|
||||||
this(Statistics.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrackStatisticsUpdater(@NonNull TrackPoint trackPoint) {
|
public TrackStatisticsUpdater(@NonNull TrackPoint trackPoint) {
|
||||||
this();
|
|
||||||
addTrackPoint(trackPoint);
|
addTrackPoint(trackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackStatisticsUpdater(List<TrackPoint> trackPoints) {
|
public TrackStatisticsUpdater(List<TrackPoint> trackPoints) {
|
||||||
this();
|
|
||||||
assert !trackPoints.isEmpty(); //TODO Enforce that this is always true (e.g., import)
|
assert !trackPoints.isEmpty(); //TODO Enforce that this is always true (e.g., import)
|
||||||
|
|
||||||
trackPoints.forEach(this::addTrackPoint);
|
trackPoints.forEach(this::addTrackPoint);
|
||||||
@@ -163,10 +155,10 @@ public class TrackStatisticsUpdater {
|
|||||||
currentSegment.addTotalDistance(movingDistance);
|
currentSegment.addTotalDistance(movingDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isIdle) {
|
if (!isIdle
|
||||||
if (!trackPoint.isSegmentManualStart() && lastTrackPoint != null) {
|
&& !trackPoint.isSegmentManualStart()
|
||||||
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
|
&& lastTrackPoint != null) {
|
||||||
}
|
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackPoint.isIdleTriggered()) {
|
if (trackPoint.isIdleTriggered()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user