From 8ba1ae3f3e7e4f0af5e11823251c2abf1d7adf6b Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 31 Jul 2016 00:06:26 +0200 Subject: [PATCH] create extra table for Morpheuz, remove more unused stuff Pebble activity tracker now do not share a common base anymore. TODO: consider creating a custom way of querying activity types like in Misfit. The activity kind stored in the database now is solely based on the intensity, so it is redundant. (#206) --- .../gadgetbridge/daogen/GBDaoGenerator.java | 12 +++++- .../pebble/AbstractPebbleSampleProvider.java | 40 ------------------- .../pebble/PebbleHealthSampleProvider.java | 32 ++++++++++++++- .../pebble/PebbleMorpheuzSampleProvider.java | 35 ++++++++++++++-- .../devices/pebble/AppMessageHandler.java | 7 ---- .../pebble/AppMessageHandlerMorpheuz.java | 12 +++--- 6 files changed, 79 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/AbstractPebbleSampleProvider.java diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 3858e5d5f..306134615 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -34,7 +34,7 @@ public class GBDaoGenerator { private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate"; public static void main(String[] args) throws Exception { - Schema schema = new Schema(9, MAIN_PACKAGE + ".entities"); + Schema schema = new Schema(10, MAIN_PACKAGE + ".entities"); addActivityDescription(schema); @@ -47,6 +47,7 @@ public class GBDaoGenerator { addMiBandActivitySample(schema, user, device); addPebbleHealthActivitySample(schema, user, device); addPebbleMisfitActivitySample(schema, user, device); + addPebbleMorpheuzActivitySample(schema, user, device); new DaoGenerator().generateAll(schema, "app/src/main/java"); } @@ -159,6 +160,15 @@ public class GBDaoGenerator { return activitySample; } + private static Entity addPebbleMorpheuzActivitySample(Schema schema, Entity user, Entity device) { + Entity activitySample = addEntity(schema, "PebbleMorpheuzSample"); + addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device); + activitySample.addIntProperty("rawIntensity").notNull(); + activitySample.addIntProperty("rawKind").notNull(); + addCommonActivitySampleProperties2(activitySample, user, device); + return activitySample; + } + private static void addCommonActivitySampleProperties(String superClass, Entity activitySample, Entity user, Entity device) { activitySample.setSuperclass(superClass); activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/AbstractPebbleSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/AbstractPebbleSampleProvider.java deleted file mode 100644 index b69b251d4..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/AbstractPebbleSampleProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -package nodomain.freeyourgadget.gadgetbridge.devices.pebble; - -import de.greenrobot.dao.AbstractDao; -import de.greenrobot.dao.Property; -import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; -import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; -import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample; -import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; - -public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvider { - protected AbstractPebbleSampleProvider(GBDevice device, DaoSession session) { - super(device, session); - } - - @Override - public AbstractDao getSampleDao() { - return getSession().getPebbleHealthActivitySampleDao(); - } - - @Override - protected Property getTimestampSampleProperty() { - return PebbleHealthActivitySampleDao.Properties.Timestamp; - } - - @Override - protected Property getRawKindSampleProperty() { - return PebbleHealthActivitySampleDao.Properties.RawKind; - } - - @Override - protected Property getDeviceIdentifierSampleProperty() { - return PebbleHealthActivitySampleDao.Properties.DeviceId; - } - - @Override - public PebbleHealthActivitySample createActivitySample() { - return new PebbleHealthActivitySample(); - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java index df82de8d7..84be37125 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java @@ -1,11 +1,16 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble; +import de.greenrobot.dao.AbstractDao; +import de.greenrobot.dao.Property; +import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -public class PebbleHealthSampleProvider extends AbstractPebbleSampleProvider { +public class PebbleHealthSampleProvider extends AbstractSampleProvider { public static final int TYPE_DEEP_SLEEP = 5; public static final int TYPE_LIGHT_SLEEP = 4; public static final int TYPE_ACTIVITY = -1; @@ -16,6 +21,31 @@ public class PebbleHealthSampleProvider extends AbstractPebbleSampleProvider { super(device, session); } + @Override + public AbstractDao getSampleDao() { + return getSession().getPebbleHealthActivitySampleDao(); + } + + @Override + protected Property getTimestampSampleProperty() { + return PebbleHealthActivitySampleDao.Properties.Timestamp; + } + + @Override + protected Property getRawKindSampleProperty() { + return PebbleHealthActivitySampleDao.Properties.RawKind; + } + + @Override + protected Property getDeviceIdentifierSampleProperty() { + return PebbleHealthActivitySampleDao.Properties.DeviceId; + } + + @Override + public PebbleHealthActivitySample createActivitySample() { + return new PebbleHealthActivitySample(); + } + @Override public int normalizeType(int rawType) { switch (rawType) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleMorpheuzSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleMorpheuzSampleProvider.java index cee3c3a03..8cd3223e2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleMorpheuzSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleMorpheuzSampleProvider.java @@ -1,15 +1,20 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble; +import de.greenrobot.dao.AbstractDao; +import de.greenrobot.dao.Property; +import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMorpheuzSample; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMorpheuzSampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -public class PebbleMorpheuzSampleProvider extends AbstractPebbleSampleProvider { +public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider { // raw types public static final int TYPE_DEEP_SLEEP = 5; public static final int TYPE_LIGHT_SLEEP = 4; - public static final int TYPE_ACTIVITY = -1; + public static final int TYPE_ACTIVITY = 1; public static final int TYPE_UNKNOWN = -1; protected float movementDivisor = 5000f; @@ -18,6 +23,31 @@ public class PebbleMorpheuzSampleProvider extends AbstractPebbleSampleProvider { super(device, session); } + @Override + public AbstractDao getSampleDao() { + return getSession().getPebbleMorpheuzSampleDao(); + } + + @Override + protected Property getTimestampSampleProperty() { + return PebbleMorpheuzSampleDao.Properties.Timestamp; + } + + @Override + protected Property getRawKindSampleProperty() { + return PebbleMorpheuzSampleDao.Properties.RawKind; + } + + @Override + protected Property getDeviceIdentifierSampleProperty() { + return PebbleMorpheuzSampleDao.Properties.DeviceId; + } + + @Override + public PebbleMorpheuzSample createActivitySample() { + return new PebbleMorpheuzSample(); + } + @Override public int normalizeType(int rawType) { switch (rawType) { @@ -28,7 +58,6 @@ public class PebbleMorpheuzSampleProvider extends AbstractPebbleSampleProvider { case TYPE_ACTIVITY: return ActivityKind.TYPE_ACTIVITY; default: -// case TYPE_UNKNOWN: // fall through return ActivityKind.TYPE_UNKNOWN; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java index 956b703ae..1944f2d5f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java @@ -7,9 +7,6 @@ import java.util.ArrayList; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; -import nodomain.freeyourgadget.gadgetbridge.entities.Device; -import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample; -import nodomain.freeyourgadget.gadgetbridge.entities.User; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; public class AppMessageHandler { @@ -37,10 +34,6 @@ public class AppMessageHandler { return null; } - protected PebbleHealthActivitySample createSample(int timestamp, int intensity, int steps, int type, User user, Device device) { - return new PebbleHealthActivitySample(null, timestamp, intensity, steps, type, user.getId(), device.getId()); - } - protected GBDevice getDevice() { return mPebbleProtocol.getDevice(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java index fbd9d857a..f61f377cc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java @@ -17,9 +17,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonitorResult; import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMorpheuzSampleProvider; -import nodomain.freeyourgadget.gadgetbridge.entities.Device; -import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample; -import nodomain.freeyourgadget.gadgetbridge.entities.User; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMorpheuzSample; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public class AppMessageHandlerMorpheuz extends AppMessageHandler { @@ -92,7 +90,7 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler { int index = ((int) pair.second >> 16); int intensity = ((int) pair.second & 0xffff); LOG.info("got point:" + index + " " + intensity); - int type = PebbleMorpheuzSampleProvider.TYPE_UNKNOWN; + int type = PebbleMorpheuzSampleProvider.TYPE_ACTIVITY; if (intensity <= 120) { type = PebbleMorpheuzSampleProvider.TYPE_DEEP_SLEEP; } else if (intensity <= 1000) { @@ -100,10 +98,10 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler { } if (index >= 0) { try (DBHandler db = GBApplication.acquireDB()) { - User user = DBHelper.getUser(db.getDaoSession()); - Device device = DBHelper.getDevice(getDevice(), db.getDaoSession()); + Long userId = DBHelper.getUser(db.getDaoSession()).getId(); + Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId(); PebbleMorpheuzSampleProvider sampleProvider = new PebbleMorpheuzSampleProvider(getDevice(), db.getDaoSession()); - PebbleHealthActivitySample sample = createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device); + PebbleMorpheuzSample sample = new PebbleMorpheuzSample(null, recording_base_timestamp + index * 600, intensity, type, userId, deviceId); sample.setProvider(sampleProvider); sampleProvider.addGBActivitySample(sample); } catch (Exception e) {