1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 18:36:50 +01:00

work towards a Pebble Misfit raw sample table

This commit is contained in:
Andreas Shimokawa 2016-07-25 22:19:39 +02:00
parent f5ba09ebe0
commit 726f767576
6 changed files with 97 additions and 28 deletions

View File

@ -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(7, MAIN_PACKAGE + ".entities");
Schema schema = new Schema(8, MAIN_PACKAGE + ".entities");
addActivityDescription(schema);
@ -46,6 +46,7 @@ public class GBDaoGenerator {
addMiBandActivitySample(schema, user, device);
addPebbleActivitySample(schema, user, device);
addPebbleMisfitActivitySample(schema, user, device);
new DaoGenerator().generateAll(schema, "app/src/main/java");
}
@ -130,7 +131,9 @@ public class GBDaoGenerator {
private static Entity addMiBandActivitySample(Schema schema, Entity user, Entity device) {
// public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
Entity activitySample = addEntity(schema, "MiBandActivitySample");
addCommonActivitySampleProperties(schema, activitySample, user, device);
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
addDefaultActivitySampleAttributes(activitySample);
addCommonActivitySampleProperties2(activitySample, user, device);
addHeartRateProperties(activitySample);
return activitySample;
}
@ -144,12 +147,22 @@ public class GBDaoGenerator {
private static Entity addPebbleActivitySample(Schema schema, Entity user, Entity device) {
// public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
Entity activitySample = addEntity(schema, "PebbleActivitySample");
addCommonActivitySampleProperties(schema, activitySample, user, device);
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
addDefaultActivitySampleAttributes(activitySample);
addCommonActivitySampleProperties2(activitySample, user, device);
return activitySample;
}
private static void addCommonActivitySampleProperties(Schema schema, Entity activitySample, Entity user, Entity device) {
activitySample.setSuperclass("AbstractActivitySample");
private static Entity addPebbleMisfitActivitySample(Schema schema, Entity user, Entity device) {
Entity activitySample = addEntity(schema, "PebbleMisfitSample");
addCommonActivitySampleProperties("AbstractPebbleMisfitActivitySample", activitySample, user, device);
activitySample.addIntProperty("rawPebbleMisfitSample").notNull();
addCommonActivitySampleProperties2(activitySample, user, device);
return activitySample;
}
private static void addCommonActivitySampleProperties(String superClass, Entity activitySample, Entity user, Entity device) {
activitySample.setSuperclass(superClass);
activitySample.addImport(MODEL_PACKAGE + ".ActivitySample");
activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider");
activitySample.implementsInterface("ActivitySample");
@ -158,10 +171,10 @@ public class GBDaoGenerator {
"intensity, are device specific. Normalized values can be retrieved through the\n" +
"corresponding {@link SampleProvider}.");
activitySample.addIdProperty();
}
private static void addCommonActivitySampleProperties2(Entity activitySample, Entity user, Entity device) {
Property timestamp = activitySample.addIntProperty("timestamp").notNull().getProperty();
activitySample.addIntProperty("rawIntensity").notNull();
activitySample.addIntProperty("steps").notNull();
activitySample.addIntProperty("rawKind").notNull();
Property userId = activitySample.addLongProperty("userId").getProperty();
activitySample.addToOne(user, userId);
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
@ -173,7 +186,13 @@ public class GBDaoGenerator {
indexUnique.makeUnique();
activitySample.addIndex(indexUnique);
}
private static void addDefaultActivitySampleAttributes(Entity activitySample) {
activitySample.addIntProperty("rawIntensity").notNull();
activitySample.addIntProperty("steps").notNull();
activitySample.addIntProperty("rawKind").notNull();
}
private static Entity addEntity(Schema schema, String className) {
Entity entity = schema.addEntity(className);
entity.addImport("de.greenrobot.dao.AbstractDao");

View File

@ -1,15 +1,18 @@
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class MisfitSampleProvider extends AbstractPebbleSampleProvider {
public class MisfitSampleProvider implements SampleProvider {
protected final float movementDivisor = 300f;
public MisfitSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}
@Override
@ -22,12 +25,55 @@ public class MisfitSampleProvider extends AbstractPebbleSampleProvider {
return (byte) activityKind;
}
@Override
public float normalizeIntensity(int rawIntensity) {
return rawIntensity / movementDivisor;
}
@Override
public List getAllActivitySamples(int timestamp_from, int timestamp_to) {
return null;
}
@Override
public List getActivitySamples(int timestamp_from, int timestamp_to) {
return null;
}
@Override
public List getSleepSamples(int timestamp_from, int timestamp_to) {
return null;
}
@Override
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind) {
}
@Override
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind) {
}
@Override
public int fetchLatestTimestamp() {
return 0;
}
@Override
public void addGBActivitySample(AbstractActivitySample activitySample) {
}
@Override
public void addGBActivitySamples(AbstractActivitySample[] activitySamples) {
}
@Override
public AbstractActivitySample createActivitySample() {
return null;
}
@Override
public int getID() {

View File

@ -1,15 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.model;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
public interface ActivitySample extends TimeStamped {
/**
* Returns the provider of the data.
*
* @return who created the sample data
*/
SampleProvider getProvider();
public interface ActivitySample extends Sample {
/**
* Returns the raw activity kind value as recorded by the SampleProvider
*/

View File

@ -1,6 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.model;
public interface HeartRateSample extends TimeStamped {
public interface HeartRateSample extends Sample {
/**
* Returns the heart rate measured at the corresponding timestamp.
* The value is returned in heart beats per minute, in the range from

View File

@ -0,0 +1,12 @@
package nodomain.freeyourgadget.gadgetbridge.model;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
public interface Sample extends TimeStamped {
/**
* Returns the provider of the data.
*
* @return who created the sample data
*/
SampleProvider getProvider();
}

View File

@ -13,15 +13,13 @@ import java.util.SimpleTimeZone;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MisfitSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMisfitSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -81,6 +79,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
int totalSteps = 0;
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples];
PebbleMisfitSample[] misfitSamples = new PebbleMisfitSample[samples];
try (DBHandler db = GBApplication.acquireDB()) {
MisfitSampleProvider sampleProvider = new MisfitSampleProvider(device, db.getDaoSession());
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
@ -115,8 +114,10 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
totalSteps += steps;
LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")");
activitySamples[i] = new PebbleActivitySample(null, timestamp + i * 60, intensity, steps, activityKind, userId, deviceId);
activitySamples[i].setProvider(sampleProvider);
//activitySamples[i] = new PebbleActivitySample(null, timestamp + i * 60, intensity, steps, activityKind, userId, deviceId);
//activitySamples[i].setProvider(sampleProvider);
misfitSamples[i] = new PebbleMisfitSample(null, sample & 0xffff, timestamp + i * 60, userId, deviceId);
misfitSamples[i].setProvider(sampleProvider);
}
LOG.info("total steps for above period: " + totalSteps);