mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 01:55:50 +01:00
Fix field ordering of ActivitySample (c'tor!) and improve importer #206
This commit is contained in:
parent
8ea29e6e1d
commit
b22111df9d
@ -167,22 +167,31 @@ public class GBDaoGenerator {
|
|||||||
"intensity, are device specific. Normalized values can be retrieved through the\n" +
|
"intensity, are device specific. Normalized values can be retrieved through the\n" +
|
||||||
"corresponding {@link SampleProvider}.");
|
"corresponding {@link SampleProvider}.");
|
||||||
activitySample.addIdProperty();
|
activitySample.addIdProperty();
|
||||||
|
activitySample.addIntProperty("timestamp").notNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addCommonActivitySampleProperties2(Entity activitySample, Entity user, Entity device) {
|
private static void addCommonActivitySampleProperties2(Entity activitySample, Entity user, Entity device) {
|
||||||
Property timestamp = activitySample.addIntProperty("timestamp").notNull().getProperty();
|
|
||||||
Property userId = activitySample.addLongProperty("userId").getProperty();
|
Property userId = activitySample.addLongProperty("userId").getProperty();
|
||||||
activitySample.addToOne(user, userId);
|
activitySample.addToOne(user, userId);
|
||||||
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
||||||
activitySample.addToOne(device, deviceId);
|
activitySample.addToOne(device, deviceId);
|
||||||
|
|
||||||
Index indexUnique = new Index();
|
Index indexUnique = new Index();
|
||||||
indexUnique.addProperty(timestamp);
|
indexUnique.addProperty(findProperty(activitySample, "timestamp"));
|
||||||
indexUnique.addProperty(deviceId);
|
indexUnique.addProperty(deviceId);
|
||||||
indexUnique.makeUnique();
|
indexUnique.makeUnique();
|
||||||
activitySample.addIndex(indexUnique);
|
activitySample.addIndex(indexUnique);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Property findProperty(Entity entity, String propertyName) {
|
||||||
|
for (Property prop : entity.getProperties()) {
|
||||||
|
if (propertyName.equals(prop.getPropertyName())) {
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Property " + propertyName + " not found in Entity " + entity.getClassName());
|
||||||
|
}
|
||||||
|
|
||||||
private static void addDefaultActivitySampleAttributes(Entity activitySample) {
|
private static void addDefaultActivitySampleAttributes(Entity activitySample) {
|
||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
activitySample.addIntProperty("steps").notNull();
|
activitySample.addIntProperty("steps").notNull();
|
||||||
|
@ -29,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ValidByDate;
|
import nodomain.freeyourgadget.gadgetbridge.model.ValidByDate;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
@ -373,19 +374,28 @@ public class DBHelper {
|
|||||||
List<T> newSamples = new ArrayList<>(cursor.getCount());
|
List<T> newSamples = new ArrayList<>(cursor.getCount());
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
T newSample = sampleProvider.createActivitySample();
|
T newSample = sampleProvider.createActivitySample();
|
||||||
|
newSample.setProvider(sampleProvider);
|
||||||
newSample.setUserId(userId);
|
newSample.setUserId(userId);
|
||||||
newSample.setDeviceId(deviceId);
|
newSample.setDeviceId(deviceId);
|
||||||
newSample.setTimestamp(cursor.getInt(colTimeStamp));
|
newSample.setTimestamp(cursor.getInt(colTimeStamp));
|
||||||
newSample.setRawKind(cursor.getInt(colType));
|
newSample.setRawKind(getNullableInt(cursor, colType, ActivitySample.NOT_MEASURED));
|
||||||
newSample.setProvider(sampleProvider);
|
newSample.setRawIntensity(getNullableInt(cursor, colIntensity, ActivitySample.NOT_MEASURED));
|
||||||
newSample.setRawIntensity(cursor.getInt(colIntensity));
|
newSample.setSteps(getNullableInt(cursor, colSteps, ActivitySample.NOT_MEASURED));
|
||||||
newSample.setSteps(cursor.getInt(colSteps));
|
if (colCustomShort > -1) {
|
||||||
|
newSample.setHeartRate(getNullableInt(cursor, colCustomShort, ActivitySample.NOT_MEASURED));
|
||||||
int hrValue = cursor.getInt(colCustomShort);
|
} else {
|
||||||
newSample.setHeartRate(hrValue);
|
newSample.setHeartRate(ActivitySample.NOT_MEASURED);
|
||||||
|
}
|
||||||
newSamples.add(newSample);
|
newSamples.add(newSample);
|
||||||
}
|
}
|
||||||
sampleProvider.getSampleDao().insertOrReplaceInTx(newSamples, true);
|
sampleProvider.getSampleDao().insertOrReplaceInTx(newSamples, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getNullableInt(Cursor cursor, int columnIndex, int defaultValue) {
|
||||||
|
if (cursor.isNull(columnIndex)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return cursor.getInt(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
|
|||||||
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
|
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
|
||||||
for (int i = 0; i < samples; i++) {
|
for (int i = 0; i < samples; i++) {
|
||||||
short sample = buf.getShort();
|
short sample = buf.getShort();
|
||||||
misfitSamples[i] = new PebbleMisfitSample(null, sample & 0xffff, timestamp + i * 60, userId, deviceId);
|
misfitSamples[i] = new PebbleMisfitSample(null, timestamp + i * 60, sample & 0xffff, userId, deviceId);
|
||||||
misfitSamples[i].setProvider(sampleProvider);
|
misfitSamples[i].setProvider(sampleProvider);
|
||||||
int steps = misfitSamples[i].getSteps();
|
int steps = misfitSamples[i].getSteps();
|
||||||
totalSteps += steps;
|
totalSteps += steps;
|
||||||
|
Loading…
Reference in New Issue
Block a user