Search in sources :

Example 1 with ActivityPoint

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.

the class GPXExporter method exportTrack.

private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException, GPXTrackEmptyException {
    String uuid = UUID.randomUUID().toString();
    ser.startTag(NS_GPX_URI, "trk");
    ser.startTag(NS_GPX_URI, "extensions");
    ser.startTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid").text(uuid).endTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid");
    ser.endTag(NS_GPX_URI, "extensions");
    ser.startTag(NS_GPX_URI, "trkseg");
    List<ActivityPoint> trackPoints = track.getTrackPoints();
    String source = getSource(track);
    boolean atLeastOnePointExported = false;
    for (ActivityPoint point : trackPoints) {
        atLeastOnePointExported |= exportTrackPoint(ser, point, source, trackPoints);
    }
    if (!atLeastOnePointExported) {
        throw new GPXTrackEmptyException();
    }
    ser.endTag(NS_GPX_URI, "trkseg");
    ser.endTag(NS_GPX_URI, "trk");
}
Also used : ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint)

Example 2 with ActivityPoint

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.

the class GPXExporter method findClosestSensibleActivityPoint.

@Nullable
private ActivityPoint findClosestSensibleActivityPoint(Date time, List<ActivityPoint> trackPoints) {
    ActivityPoint closestPointItem = null;
    HeartRateUtils heartRateUtilsInstance = HeartRateUtils.getInstance();
    // minimum distance is 2min
    long lowestDifference = 60 * 2 * 1000;
    for (ActivityPoint pointItem : trackPoints) {
        int hrItem = pointItem.getHeartRate();
        if (heartRateUtilsInstance.isValidHeartRateValue(hrItem)) {
            Date timeItem = pointItem.getTime();
            if (timeItem.after(time) || timeItem.equals(time)) {
                // we assume that the given trackPoints are sorted in time ascending order (oldest first)
                break;
            }
            long difference = time.getTime() - timeItem.getTime();
            if (difference < lowestDifference) {
                lowestDifference = difference;
                closestPointItem = pointItem;
            }
        }
    }
    return closestPointItem;
}
Also used : HeartRateUtils(nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) Date(java.util.Date) Nullable(androidx.annotation.Nullable)

Example 3 with ActivityPoint

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.

the class HuamiActivityDetailsParser method consumeGPSAndUpdateBaseLocation.

private int consumeGPSAndUpdateBaseLocation(byte[] bytes, int offset, long timeOffset) {
    int i = 0;
    int longitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    int latitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    int altitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    baseLongitude += longitudeDelta;
    baseLatitude += latitudeDelta;
    if (baseAltitude != -20000) {
        baseAltitude += altitudeDelta;
    }
    GPSCoordinate coordinate = new GPSCoordinate(convertHuamiValueToDecimalDegrees(baseLongitude), convertHuamiValueToDecimalDegrees(baseLatitude), baseAltitude);
    ActivityPoint ap = getActivityPointFor(timeOffset, coordinate);
    ap.setLocation(coordinate);
    add(ap);
    return i;
}
Also used : ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)

Example 4 with ActivityPoint

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.

the class HuamiActivityDetailsParserTest method testGPXExport.

@Test
public void testGPXExport() throws Exception {
    BipActivitySummary summary = createSummary();
    int baseLongi = BLETypeConversions.toUint32((byte) 0xd6, (byte) 0xc4, (byte) 0x62, (byte) 0x02);
    int baseLati = BLETypeConversions.toUint32((byte) 0xff, (byte) 0xa9, (byte) 0x61, (byte) 0x9);
    int baseAlti = BLETypeConversions.toUint32((byte) 0x30, (byte) 0x0, (byte) 0x0, (byte) 0x0);
    summary.setBaseLongitude(baseLongi);
    summary.setBaseLatitude(baseLati);
    summary.setBaseAltitude(baseAlti);
    HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
    parser.setSkipCounterByte(true);
    try (InputStream in = getContents(DETAILS_1)) {
        ActivityTrack track = parser.parse(FileUtils.readAll(in, MAX_DETAILS));
        List<ActivityPoint> trackPoints = track.getTrackPoints();
        assertEquals(972, trackPoints.size());
        GPXExporter exporter = new GPXExporter();
        exporter.setIncludeHeartRate(false);
        exporter.setCreator(getClass().getName());
        File targetFile = File.createTempFile("gadgetbridge-track", ".gpx");
        System.out.println("Writing GPX file: " + targetFile);
        exporter.performExport(track, targetFile);
        assertTrue(targetFile.length() > 1024);
    }
}
Also used : GPXExporter(nodomain.freeyourgadget.gadgetbridge.export.GPXExporter) InputStream(java.io.InputStream) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) BipActivitySummary(nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.BipActivitySummary) HuamiActivityDetailsParser(nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiActivityDetailsParser) ActivityTrack(nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack) File(java.io.File) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) Test(org.junit.Test)

Example 5 with ActivityPoint

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.

the class HuamiActivityDetailsParserTest method testActivityDetails.

@Test
public void testActivityDetails() throws Exception {
    BipActivitySummary summary = createSummary();
    HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
    parser.setSkipCounterByte(true);
    try (InputStream in = getContents(DETAILS_1)) {
        ActivityTrack track = parser.parse(FileUtils.readAll(in, MAX_DETAILS));
        assertEquals("SuperBand 2000", track.getDevice().getName());
        assertEquals("Elvis", track.getUser().getName());
        List<ActivityPoint> trackPoints = track.getTrackPoints();
        assertEquals(972, trackPoints.size());
    }
}
Also used : InputStream(java.io.InputStream) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) BipActivitySummary(nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.BipActivitySummary) HuamiActivityDetailsParser(nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiActivityDetailsParser) ActivityTrack(nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack) Test(org.junit.Test)

Aggregations

ActivityPoint (nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint)12 ActivityTrack (nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack)5 Test (org.junit.Test)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 BipActivitySummary (nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.BipActivitySummary)2 GPSCoordinate (nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)2 HuamiActivityDetailsParser (nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiActivityDetailsParser)2 Nullable (androidx.annotation.Nullable)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ParsePosition (java.text.ParsePosition)1 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)1 HeartRateUtils (nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 GPXExporter (nodomain.freeyourgadget.gadgetbridge.export.GPXExporter)1