forked from upstream-mirrors/OpenTracks
ContentProviderUtils use Statistics for saving.
This commit is contained in:
@@ -352,30 +352,30 @@ public class ContentProviderUtils {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Use Statistics
|
public void updateTrackStatistics(@NonNull Track.Id trackId, @NonNull Statistics trackStatistics) {
|
||||||
public void updateTrackStatistics(@NonNull Track.Id trackId, @NonNull SegmentStatisticUpdater trackStatistics) {
|
|
||||||
contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(trackStatistics), TracksColumns._ID + "=?", new String[]{Long.toString(trackId.id())});
|
contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(trackStatistics), TracksColumns._ID + "=?", new String[]{Long.toString(trackId.id())});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Use Statistics
|
private ContentValues createContentValues(Statistics trackStatistics) {
|
||||||
private ContentValues createContentValues(SegmentStatisticUpdater trackStatistics) {
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
if (trackStatistics.getStartTime() != null) {
|
if (trackStatistics.startTime() != null) {
|
||||||
values.put(TracksColumns.STARTTIME, trackStatistics.getStartTime().toEpochMilli());
|
values.put(TracksColumns.STARTTIME, trackStatistics.startTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
if (trackStatistics.getStopTime() != null) {
|
if (trackStatistics.stopTime() != null) {
|
||||||
values.put(TracksColumns.STOPTIME, trackStatistics.getStopTime().toEpochMilli());
|
values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.getTotalDistance().toM());
|
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM());
|
||||||
values.put(TracksColumns.TOTALTIME, trackStatistics.getTotalTime().toMillis());
|
values.put(TracksColumns.TOTALTIME, trackStatistics.totalTime().toMillis());
|
||||||
values.put(TracksColumns.MOVINGTIME, trackStatistics.getMovingTime().toMillis());
|
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingTime().toMillis());
|
||||||
values.put(TracksColumns.AVGSPEED, trackStatistics.getAverageSpeed().toMPS());
|
values.put(TracksColumns.AVGSPEED, trackStatistics.getAverageSpeed().toMPS());
|
||||||
values.put(TracksColumns.AVGMOVINGSPEED, trackStatistics.getAverageMovingSpeed().toMPS());
|
values.put(TracksColumns.AVGMOVINGSPEED, trackStatistics.getAverageMovingSpeed().toMPS());
|
||||||
values.put(TracksColumns.MAXSPEED, trackStatistics.getMaxSpeed().toMPS());
|
values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS());
|
||||||
values.put(TracksColumns.MIN_ALTITUDE, trackStatistics.getMinAltitude());
|
values.put(TracksColumns.MIN_ALTITUDE, trackStatistics.getMinAltitude());
|
||||||
values.put(TracksColumns.MAX_ALTITUDE, trackStatistics.getMaxAltitude());
|
values.put(TracksColumns.MAX_ALTITUDE, trackStatistics.getMaxAltitude());
|
||||||
values.put(TracksColumns.ALTITUDE_GAIN, trackStatistics.getTotalAltitudeGain());
|
if (trackStatistics.altitudeGainLoss() != null) {
|
||||||
values.put(TracksColumns.ALTITUDE_LOSS, trackStatistics.getTotalAltitudeLoss());
|
values.put(TracksColumns.ALTITUDE_GAIN, trackStatistics.altitudeGainLoss().gain_m());
|
||||||
|
values.put(TracksColumns.ALTITUDE_LOSS, trackStatistics.altitudeGainLoss().loss_m());
|
||||||
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorData
|
|||||||
return new SegmentStatisticUpdater().getStatistics();
|
return new SegmentStatisticUpdater().getStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
return track.getTrackStatistics().getStatistics();
|
return track.getStatistics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
|
|||||||
contentProviderUtils.insertTrackPoint(trackPoint, trackId);
|
contentProviderUtils.insertTrackPoint(trackPoint, trackId);
|
||||||
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
||||||
|
|
||||||
contentProviderUtils.updateTrackStatistics(trackId, trackStatisticsUpdater.getTrackStatistics());
|
contentProviderUtils.updateTrackStatistics(trackId, trackStatisticsUpdater.getTrackStatistics().getStatistics());
|
||||||
lastStoredTrackPoint = trackPoint;
|
lastStoredTrackPoint = trackPoint;
|
||||||
if (trackPoint.hasLocation()) {
|
if (trackPoint.hasLocation()) {
|
||||||
lastStoredTrackPointWithLocation = lastStoredTrackPoint;
|
lastStoredTrackPointWithLocation = lastStoredTrackPoint;
|
||||||
|
|||||||
@@ -100,14 +100,15 @@ public class ExtremityMonitor {
|
|||||||
* @param min the minimum value
|
* @param min the minimum value
|
||||||
* @param max the maximum value
|
* @param max the maximum value
|
||||||
*/
|
*/
|
||||||
public void set(double min, double max) {
|
public void set(Double min, Double max) {
|
||||||
|
if (min == null || max == null) {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if has data.
|
|
||||||
*/
|
|
||||||
public boolean hasData() {
|
public boolean hasData() {
|
||||||
return min != Double.POSITIVE_INFINITY && max != Double.NEGATIVE_INFINITY;
|
return min != Double.POSITIVE_INFINITY && max != Double.NEGATIVE_INFINITY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
|
|||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
//TODO Check that data ranges are valid (not less than zero etc.)
|
//TODO Check that data ranges are valid (not less than zero etc.)
|
||||||
//TODO Should be a Java record
|
|
||||||
public class SegmentStatisticUpdater {
|
public class SegmentStatisticUpdater {
|
||||||
|
|
||||||
// The min and max altitude (meters) seen on this track.
|
// The min and max altitude (meters) seen on this track.
|
||||||
@@ -76,18 +75,24 @@ public class SegmentStatisticUpdater {
|
|||||||
* @param other another statistics data object to copy from
|
* @param other another statistics data object to copy from
|
||||||
*/
|
*/
|
||||||
public SegmentStatisticUpdater(SegmentStatisticUpdater other) {
|
public SegmentStatisticUpdater(SegmentStatisticUpdater other) {
|
||||||
startTime = other.startTime;
|
this(other.getStatistics());
|
||||||
stopTime = other.stopTime;
|
}
|
||||||
totalDistance = other.totalDistance;
|
|
||||||
totalTime = other.totalTime;
|
public SegmentStatisticUpdater(Statistics statistics) {
|
||||||
movingTime = other.movingTime;
|
startTime = statistics.startTime();
|
||||||
maxSpeed = other.maxSpeed;
|
stopTime = statistics.stopTime();
|
||||||
altitudeExtremities.set(other.altitudeExtremities.getMin(), other.altitudeExtremities.getMax());
|
totalDistance = statistics.totalDistance();
|
||||||
totalAltitudeGain_m = other.totalAltitudeGain_m;
|
totalTime = statistics.totalTime();
|
||||||
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
|
movingTime = statistics.movingTime();
|
||||||
avgHeartRate = other.avgHeartRate;
|
maxSpeed = statistics.maxSpeed();
|
||||||
avgPower = other.avgPower;
|
altitudeExtremities.set(statistics.altitudeMin_m(), statistics.altitudeMax_m());
|
||||||
isIdle = other.isIdle;
|
if (statistics.altitudeGainLoss() != null) {
|
||||||
|
totalAltitudeGain_m = statistics.altitudeGainLoss().gain_m();
|
||||||
|
totalAltitudeLoss_m = statistics.altitudeGainLoss().loss_m();
|
||||||
|
}
|
||||||
|
avgHeartRate = statistics.avgHeartRate();
|
||||||
|
avgPower = statistics.avgPower();
|
||||||
|
isIdle = statistics.isIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated //TODO Remove
|
@Deprecated //TODO Remove
|
||||||
@@ -101,6 +106,7 @@ public class SegmentStatisticUpdater {
|
|||||||
this.maxSpeed = Speed.of(maxSpeed_mps);
|
this.maxSpeed = Speed.of(maxSpeed_mps);
|
||||||
this.totalAltitudeGain_m = totalAltitudeGain_m;
|
this.totalAltitudeGain_m = totalAltitudeGain_m;
|
||||||
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
|
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
|
||||||
|
altitudeExtremities.set(0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user