1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +01:00

Pebble Health: read overlay data in sample provider and patch in raw kind

completely untested
This commit is contained in:
Andreas Shimokawa 2016-08-09 11:56:05 +02:00
parent 5072d6b959
commit fe5ec74ca1

View File

@ -1,10 +1,17 @@
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
import java.util.Collections;
import java.util.List;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -21,6 +28,37 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider<PebbleHea
super(device, session);
}
@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(getmDevice(), getSession());
if (dbDevice == null) {
// no device, no samples
return Collections.emptyList();
}
Property timestampProperty = getTimestampSampleProperty();
Property deviceProperty = getDeviceIdentifierSampleProperty();
QueryBuilder<PebbleHealthActivityOverlay> qb = getSession().getPebbleHealthActivityOverlayDao().queryBuilder();
// I assume it returns the records by id ascending ... (last overlay is dominant)
qb.where(deviceProperty.eq(dbDevice.getId()), timestampProperty.ge(timestamp_from))
.where(timestampProperty.le(timestamp_to));
List<PebbleHealthActivityOverlay> overlayRecords = qb.build().list();
for (PebbleHealthActivitySample sample : samples) {
for (PebbleHealthActivityOverlay overlay : overlayRecords) {
if (overlay.getTimestampFrom() <= sample.getTimestamp() && overlay.getTimestampTo() >= sample.getTimestamp()) {
// patch in the raw kind
sample.setRawKind(overlay.getRawKind());
}
}
}
return samples;
}
@Override
public AbstractDao<PebbleHealthActivitySample, ?> getSampleDao() {
return getSession().getPebbleHealthActivitySampleDao();
@ -33,7 +71,9 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider<PebbleHea
@Override
protected Property getRawKindSampleProperty() {
return PebbleHealthActivitySampleDao.Properties.RawKind;
return null;
// it is still in the database just hide it for now. remove these two commented lines later
//return PebbleHealthActivitySampleDao.Properties.RawKind;
}
@Override
@ -54,6 +94,7 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider<PebbleHea
case TYPE_LIGHT_SLEEP:
return ActivityKind.TYPE_LIGHT_SLEEP;
case TYPE_ACTIVITY:
return ActivityKind.TYPE_ACTIVITY;
default:
return ActivityKind.TYPE_UNKNOWN;
}
@ -68,7 +109,6 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider<PebbleHea
return TYPE_DEEP_SLEEP;
case ActivityKind.TYPE_LIGHT_SLEEP:
return TYPE_LIGHT_SLEEP;
case ActivityKind.TYPE_UNKNOWN: // fall through
default:
return TYPE_ACTIVITY;
}