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