Search in sources :

Example 1 with PebbleHealthActivitySample

use of nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample in project Gadgetbridge by Freeyourgadget.

the class DatalogSessionHealthSteps method store.

private void store(StepsRecord[] stepsRecords) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        PebbleHealthSampleProvider sampleProvider = new PebbleHealthSampleProvider(getDevice(), dbHandler.getDaoSession());
        PebbleHealthActivitySample[] samples = new PebbleHealthActivitySample[stepsRecords.length];
        // TODO: user and device
        Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
        Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
        for (int j = 0; j < stepsRecords.length; j++) {
            StepsRecord stepsRecord = stepsRecords[j];
            samples[j] = new PebbleHealthActivitySample(stepsRecord.timestamp, deviceId, userId, stepsRecord.getRawData(), stepsRecord.intensity, stepsRecord.steps, stepsRecord.heart_rate);
            samples[j].setProvider(sampleProvider);
        }
        sampleProvider.addGBActivitySamples(samples);
    } catch (Exception ex) {
        LOG.debug(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) PebbleHealthSampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider) PebbleHealthActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample)

Example 2 with PebbleHealthActivitySample

use of nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample in project Gadgetbridge by Freeyourgadget.

the class PebbleHealthSampleProvider method getAllActivitySamples.

@Override
public List<PebbleHealthActivitySample> getAllActivitySamples(int timestamp_from, int timestamp_to) {
    List<PebbleHealthActivitySample> samples = super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL);
    Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
    if (dbDevice == null) {
        // no device, no samples
        return Collections.emptyList();
    }
    QueryBuilder<PebbleHealthActivityOverlay> qb = getSession().getPebbleHealthActivityOverlayDao().queryBuilder();
    // I assume it returns the records by id ascending ... (last overlay is dominant)
    qb.where(PebbleHealthActivityOverlayDao.Properties.DeviceId.eq(dbDevice.getId()), PebbleHealthActivityOverlayDao.Properties.TimestampTo.ge(timestamp_from)).where(PebbleHealthActivityOverlayDao.Properties.TimestampFrom.le(timestamp_to));
    List<PebbleHealthActivityOverlay> overlayRecords = qb.build().list();
    for (PebbleHealthActivityOverlay overlay : overlayRecords) {
        for (PebbleHealthActivitySample sample : samples) {
            if (overlay.getTimestampFrom() <= sample.getTimestamp() && sample.getTimestamp() < overlay.getTimestampTo()) {
                // patch in the raw kind
                sample.setRawKind(overlay.getRawKind());
            }
        }
    }
    detachFromSession();
    return samples;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) PebbleHealthActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample) PebbleHealthActivityOverlay(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay)

Aggregations

PebbleHealthActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample)2 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)1 PebbleHealthSampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 PebbleHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1