mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +01:00
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)
This commit is contained in:
parent
eabe625c47
commit
8ba1ae3f3e
@ -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");
|
||||
|
@ -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<PebbleHealthActivitySample> {
|
||||
protected AbstractPebbleSampleProvider(GBDevice device, DaoSession session) {
|
||||
super(device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractDao<PebbleHealthActivitySample, ?> 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();
|
||||
}
|
||||
}
|
@ -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<PebbleHealthActivitySample> {
|
||||
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<PebbleHealthActivitySample, ?> 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) {
|
||||
|
@ -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<PebbleMorpheuzSample> {
|
||||
// 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<PebbleMorpheuzSample, ?> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user