Search in sources :

Example 1 with PebbleHealthActivityOverlay

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

the class DatalogSessionHealthOverlayData method store.

private void store(OverlayRecord[] overlayRecords) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        Long userId = DBHelper.getUser(session).getId();
        Long deviceId = DBHelper.getDevice(getDevice(), session).getId();
        PebbleHealthActivityOverlayDao overlayDao = session.getPebbleHealthActivityOverlayDao();
        List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
        for (OverlayRecord overlayRecord : overlayRecords) {
            overlayList.add(new PebbleHealthActivityOverlay(overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds, overlayRecord.type, deviceId, userId, overlayRecord.getRawData()));
        }
        overlayDao.insertOrReplaceInTx(overlayList);
    } catch (Exception ex) {
        LOG.debug(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) ArrayList(java.util.ArrayList) PebbleHealthActivityOverlayDao(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao) PebbleHealthActivityOverlay(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Example 2 with PebbleHealthActivityOverlay

use of nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay 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)

Example 3 with PebbleHealthActivityOverlay

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

the class DatalogSessionHealthSleep method store.

private void store(SleepRecord[] sleepRecords) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        Long userId = DBHelper.getUser(session).getId();
        Long deviceId = DBHelper.getDevice(getDevice(), session).getId();
        PebbleHealthActivityOverlayDao overlayDao = session.getPebbleHealthActivityOverlayDao();
        List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
        for (SleepRecord sleepRecord : sleepRecords) {
            //TODO: check the firmware version and don't use the sleep record if overlay is available?
            overlayList.add(new PebbleHealthActivityOverlay(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sleepRecord.type, deviceId, userId, sleepRecord.getRawData()));
        }
        overlayDao.insertOrReplaceInTx(overlayList);
    } catch (Exception ex) {
        LOG.debug(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) ArrayList(java.util.ArrayList) PebbleHealthActivityOverlayDao(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao) PebbleHealthActivityOverlay(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Aggregations

PebbleHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay)3 ArrayList (java.util.ArrayList)2 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)2 PebbleHealthActivityOverlayDao (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao)2 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 PebbleHealthActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1