Search in sources :

Example 1 with ActivityTrack

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack 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 2 with ActivityTrack

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack 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)

Example 3 with ActivityTrack

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

the class FetchSportsDetailsOperation method handleActivityFetchFinish.

@Override
protected void handleActivityFetchFinish(boolean success) {
    LOG.info(getName() + " has finished round " + fetchCount);
    if (success) {
        HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
        // is already stripped
        parser.setSkipCounterByte(false);
        try {
            ActivityTrack track = parser.parse(buffer.toByteArray());
            ActivityTrackExporter exporter = createExporter();
            String trackType = "track";
            switch(summary.getActivityKind()) {
                case ActivityKind.TYPE_CYCLING:
                    trackType = getContext().getString(R.string.activity_type_biking);
                    break;
                case ActivityKind.TYPE_RUNNING:
                    trackType = getContext().getString(R.string.activity_type_running);
                    break;
                case ActivityKind.TYPE_WALKING:
                    trackType = getContext().getString(R.string.activity_type_walking);
                    break;
                case ActivityKind.TYPE_HIKING:
                    trackType = getContext().getString(R.string.activity_type_hiking);
                    break;
                case ActivityKind.TYPE_CLIMBING:
                    trackType = getContext().getString(R.string.activity_type_climbing);
                    break;
                case ActivityKind.TYPE_SWIMMING:
                    trackType = getContext().getString(R.string.activity_type_swimming);
                    break;
            }
            String fileName = FileUtils.makeValidFileName("gadgetbridge-" + trackType.toLowerCase() + "-" + DateTimeUtils.formatIso8601(summary.getStartTime()) + ".gpx");
            File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
            try {
                exporter.performExport(track, targetFile);
                try (DBHandler dbHandler = GBApplication.acquireDB()) {
                    summary.setGpxTrack(targetFile.getAbsolutePath());
                    dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
                }
            } catch (ActivityTrackExporter.GPXTrackEmptyException ex) {
                GB.toast(getContext(), "This activity does not contain GPX tracks.", Toast.LENGTH_LONG, GB.ERROR, ex);
            }
            GregorianCalendar endTime = BLETypeConversions.createCalendar();
            endTime.setTime(summary.getEndTime());
            saveLastSyncTimestamp(endTime);
        } catch (Exception ex) {
            GB.toast(getContext(), "Error getting activity details: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
        }
    }
    super.handleActivityFetchFinish(success);
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) GregorianCalendar(java.util.GregorianCalendar) ActivityTrackExporter(nodomain.freeyourgadget.gadgetbridge.export.ActivityTrackExporter) HuamiActivityDetailsParser(nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiActivityDetailsParser) ActivityTrack(nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack) File(java.io.File)

Example 4 with ActivityTrack

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

the class GPXExporterTest method createTestTrack.

private ActivityTrack createTestTrack(List<ActivityPoint> points) {
    final User user = new User();
    user.setName("Test User");
    Device device = new Device();
    device.setName("Test Device");
    final ActivityTrack track = new ActivityTrack();
    track.setName("Test Track");
    track.setBaseTime(new Date());
    track.setUser(user);
    track.setDevice(device);
    for (final ActivityPoint point : points) {
        track.addTrackPoint(point);
    }
    return track;
}
Also used : User(nodomain.freeyourgadget.gadgetbridge.entities.User) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) ActivityTrack(nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack) Date(java.util.Date)

Example 5 with ActivityTrack

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

the class GPXExporterTest method shouldCreateValidGpxFromSimulatedDataWithHeartrate.

@Test
public void shouldCreateValidGpxFromSimulatedDataWithHeartrate() throws IOException, ParseException, GPXTrackEmptyException, ParserConfigurationException, SAXException {
    final List<ActivityPoint> points = readActivityPoints("/GPXExporterTest-SampleTracksHR.csv");
    final GPXExporter gpxExporter = new GPXExporter();
    gpxExporter.setCreator("Gadgetbridge Test");
    final ActivityTrack track = createTestTrack(points);
    final File tempFile = File.createTempFile("gpx-exporter-test-track", ".gpx");
    tempFile.deleteOnExit();
    gpxExporter.performExport(track, tempFile);
    validateGpxFile(tempFile);
}
Also used : ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) ActivityTrack(nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack) File(java.io.File) Test(org.junit.Test)

Aggregations

ActivityTrack (nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack)6 ActivityPoint (nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint)5 File (java.io.File)4 Test (org.junit.Test)4 HuamiActivityDetailsParser (nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiActivityDetailsParser)3 InputStream (java.io.InputStream)2 BipActivitySummary (nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.BipActivitySummary)2 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 ActivityTrackExporter (nodomain.freeyourgadget.gadgetbridge.export.ActivityTrackExporter)1 GPXExporter (nodomain.freeyourgadget.gadgetbridge.export.GPXExporter)1