mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
More improvements of GPX export, optimize nearest closest trackpoint finding a bit
This commit is contained in:
parent
1b9b5f821e
commit
66063256a7
@ -1,6 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.export;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Xml;
|
||||
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
@ -31,7 +32,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
||||
|
||||
private String creator;
|
||||
private boolean includeHeartRate = true;
|
||||
private boolean includeHeartRateByTime = true;
|
||||
private boolean includeHeartRateOfNearestSample = true;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@ -90,7 +91,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
||||
String source = getSource(track);
|
||||
boolean atLeastOnePointExported = false;
|
||||
for (ActivityPoint point : trackPoints) {
|
||||
atLeastOnePointExported = exportTrackPoint(ser, point, source, trackPoints) | atLeastOnePointExported ;
|
||||
atLeastOnePointExported |= exportTrackPoint(ser, point, source, trackPoints);
|
||||
}
|
||||
|
||||
if(!atLeastOnePointExported) {
|
||||
@ -135,31 +136,20 @@ public class GPXExporter implements ActivityTrackExporter {
|
||||
|
||||
int hr = point.getHeartRate();
|
||||
if (!HeartRateUtils.isValidHeartRateValue(hr)) {
|
||||
if(!includeHeartRateByTime) { return; }
|
||||
if (!includeHeartRateOfNearestSample) {
|
||||
return;
|
||||
}
|
||||
|
||||
Date time = point.getTime();
|
||||
ActivityPoint closestPointItem = null;
|
||||
long lowestDifference = Long.MAX_VALUE;
|
||||
for (ActivityPoint pointItem : trackPoints) {
|
||||
int hrItem = pointItem.getHeartRate();
|
||||
if(HeartRateUtils.isValidHeartRateValue(hrItem)) {
|
||||
Date timeItem = pointItem.getTime();
|
||||
if (timeItem.after(time) || timeItem.equals(time)) continue;
|
||||
long difference = time.getTime() - timeItem.getTime();
|
||||
if (difference < lowestDifference) {
|
||||
lowestDifference = difference;
|
||||
closestPointItem = pointItem;
|
||||
ActivityPoint closestPointItem = findClosestSensibleActivityPoint(point.getTime(), trackPoints);
|
||||
if(closestPointItem == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(closestPointItem != null) {
|
||||
|
||||
hr = closestPointItem.getHeartRate();
|
||||
if (!HeartRateUtils.isValidHeartRateValue(hr)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ser.startTag(NS_DEFAULT, "extensions");
|
||||
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
||||
@ -169,6 +159,27 @@ public class GPXExporter implements ActivityTrackExporter {
|
||||
ser.endTag(NS_DEFAULT, "extensions");
|
||||
}
|
||||
|
||||
private @Nullable ActivityPoint findClosestSensibleActivityPoint(Date time, List<ActivityPoint> trackPoints) {
|
||||
ActivityPoint closestPointItem = null;
|
||||
|
||||
long lowestDifference = 60 * 2 * 1000; // minimum distance is 2min
|
||||
for (ActivityPoint pointItem : trackPoints) {
|
||||
int hrItem = pointItem.getHeartRate();
|
||||
if (HeartRateUtils.isValidHeartRateValue(hrItem)) {
|
||||
Date timeItem = pointItem.getTime();
|
||||
if (timeItem.after(time) || timeItem.equals(time)) {
|
||||
break; // we assume that the given trackPoints are sorted in time ascending order (oldest first)
|
||||
}
|
||||
long difference = time.getTime() - timeItem.getTime();
|
||||
if (difference < lowestDifference) {
|
||||
lowestDifference = difference;
|
||||
closestPointItem = pointItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
return closestPointItem;
|
||||
}
|
||||
|
||||
private String formatLocation(double value) {
|
||||
return new BigDecimal(value).setScale(GPSCoordinate.GPS_DECIMAL_DEGREES_SCALE, RoundingMode.HALF_UP).toPlainString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user