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());
}
}
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;
}
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());
}
}
Aggregations