mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Merge branch 'composite-key-dao'
This commit is contained in:
commit
ce8af615d1
@ -7,7 +7,8 @@ archivesBaseName = 'gadgetbridge-daogenerator'
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// compile 'org.greenrobot:greendao-generator:2.2.0'
|
// compile 'org.greenrobot:greendao-generator:2.2.0'
|
||||||
compile 'com.github.freeyourgadget:greendao:c3830951e5dd3d1e63d7bac600d5f773b81df363'
|
// compile project(":DaoGenerator")
|
||||||
|
compile 'com.github.freeyourgadget:greendao:1998d7cd2d21f662c6044f6ccf3b3a251bbad341'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
@ -34,7 +34,7 @@ public class GBDaoGenerator {
|
|||||||
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Schema schema = new Schema(12, MAIN_PACKAGE + ".entities");
|
Schema schema = new Schema(13, MAIN_PACKAGE + ".entities");
|
||||||
|
|
||||||
addActivityDescription(schema);
|
addActivityDescription(schema);
|
||||||
|
|
||||||
@ -137,7 +137,6 @@ public class GBDaoGenerator {
|
|||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
activitySample.addIntProperty("steps").notNull();
|
activitySample.addIntProperty("steps").notNull();
|
||||||
activitySample.addIntProperty("rawKind").notNull();
|
activitySample.addIntProperty("rawKind").notNull();
|
||||||
addCommonActivitySampleProperties2(activitySample, user, device);
|
|
||||||
addHeartRateProperties(activitySample);
|
addHeartRateProperties(activitySample);
|
||||||
return activitySample;
|
return activitySample;
|
||||||
}
|
}
|
||||||
@ -149,7 +148,6 @@ public class GBDaoGenerator {
|
|||||||
private static Entity addPebbleHealthActivitySample(Schema schema, Entity user, Entity device) {
|
private static Entity addPebbleHealthActivitySample(Schema schema, Entity user, Entity device) {
|
||||||
Entity activitySample = addEntity(schema, "PebbleHealthActivitySample");
|
Entity activitySample = addEntity(schema, "PebbleHealthActivitySample");
|
||||||
addCommonActivitySampleProperties("AbstractPebbleHealthActivitySample", activitySample, user, device);
|
addCommonActivitySampleProperties("AbstractPebbleHealthActivitySample", activitySample, user, device);
|
||||||
addCommonActivitySampleProperties2(activitySample, user, device);
|
|
||||||
activitySample.addByteArrayProperty("rawPebbleHealthData");
|
activitySample.addByteArrayProperty("rawPebbleHealthData");
|
||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
activitySample.addIntProperty("steps").notNull();
|
activitySample.addIntProperty("steps").notNull();
|
||||||
@ -158,31 +156,22 @@ public class GBDaoGenerator {
|
|||||||
|
|
||||||
private static Entity addPebbleHealthActivityKindOverlay(Schema schema, Entity user, Entity device) {
|
private static Entity addPebbleHealthActivityKindOverlay(Schema schema, Entity user, Entity device) {
|
||||||
Entity activityOverlay = addEntity(schema, "PebbleHealthActivityOverlay");
|
Entity activityOverlay = addEntity(schema, "PebbleHealthActivityOverlay");
|
||||||
activityOverlay.addIdProperty();
|
|
||||||
|
activityOverlay.addIntProperty("timestampFrom").notNull().primaryKey();
|
||||||
|
activityOverlay.addIntProperty("timestampTo").notNull().primaryKey();
|
||||||
|
Property deviceId = activityOverlay.addLongProperty("deviceId").primaryKey().getProperty();
|
||||||
|
activityOverlay.addToOne(device, deviceId);
|
||||||
|
|
||||||
Property userId = activityOverlay.addLongProperty("userId").getProperty();
|
Property userId = activityOverlay.addLongProperty("userId").getProperty();
|
||||||
activityOverlay.addToOne(user, userId);
|
activityOverlay.addToOne(user, userId);
|
||||||
Property deviceId = activityOverlay.addLongProperty("deviceId").getProperty();
|
|
||||||
activityOverlay.addToOne(device, deviceId);
|
|
||||||
|
|
||||||
Property timestampFrom = activityOverlay.addIntProperty("timestampFrom").notNull().getProperty();
|
|
||||||
Property timestampTo = activityOverlay.addIntProperty("timestampTo").notNull().getProperty();
|
|
||||||
activityOverlay.addIntProperty("rawKind").notNull();
|
activityOverlay.addIntProperty("rawKind").notNull();
|
||||||
|
|
||||||
Index indexUnique = new Index();
|
|
||||||
indexUnique.addProperty(deviceId);
|
|
||||||
indexUnique.addProperty(timestampFrom);
|
|
||||||
indexUnique.addProperty(timestampTo);
|
|
||||||
indexUnique.makeUnique();
|
|
||||||
activityOverlay.addIndex(indexUnique);
|
|
||||||
|
|
||||||
return activityOverlay;
|
return activityOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity addPebbleMisfitActivitySample(Schema schema, Entity user, Entity device) {
|
private static Entity addPebbleMisfitActivitySample(Schema schema, Entity user, Entity device) {
|
||||||
Entity activitySample = addEntity(schema, "PebbleMisfitSample");
|
Entity activitySample = addEntity(schema, "PebbleMisfitSample");
|
||||||
addCommonActivitySampleProperties("AbstractPebbleMisfitActivitySample", activitySample, user, device);
|
addCommonActivitySampleProperties("AbstractPebbleMisfitActivitySample", activitySample, user, device);
|
||||||
addCommonActivitySampleProperties2(activitySample, user, device);
|
|
||||||
activitySample.addIntProperty("rawPebbleMisfitSample").notNull();
|
activitySample.addIntProperty("rawPebbleMisfitSample").notNull();
|
||||||
return activitySample;
|
return activitySample;
|
||||||
}
|
}
|
||||||
@ -190,7 +179,6 @@ public class GBDaoGenerator {
|
|||||||
private static Entity addPebbleMorpheuzActivitySample(Schema schema, Entity user, Entity device) {
|
private static Entity addPebbleMorpheuzActivitySample(Schema schema, Entity user, Entity device) {
|
||||||
Entity activitySample = addEntity(schema, "PebbleMorpheuzSample");
|
Entity activitySample = addEntity(schema, "PebbleMorpheuzSample");
|
||||||
addCommonActivitySampleProperties("AbstractPebbleMorpheuzActivitySample", activitySample, user, device);
|
addCommonActivitySampleProperties("AbstractPebbleMorpheuzActivitySample", activitySample, user, device);
|
||||||
addCommonActivitySampleProperties2(activitySample, user, device);
|
|
||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
return activitySample;
|
return activitySample;
|
||||||
}
|
}
|
||||||
@ -202,21 +190,11 @@ public class GBDaoGenerator {
|
|||||||
"This class represents a sample specific to the device. Values like activity kind or\n" +
|
"This class represents a sample specific to the device. Values like activity kind or\n" +
|
||||||
"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.addIntProperty("timestamp").notNull().primaryKey();
|
||||||
activitySample.addIntProperty("timestamp").notNull();
|
Property deviceId = activitySample.addLongProperty("deviceId").primaryKey().getProperty();
|
||||||
}
|
activitySample.addToOne(device, deviceId);
|
||||||
|
|
||||||
private static void addCommonActivitySampleProperties2(Entity activitySample, Entity user, Entity device) {
|
|
||||||
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();
|
|
||||||
activitySample.addToOne(device, deviceId);
|
|
||||||
|
|
||||||
Index indexUnique = new Index();
|
|
||||||
indexUnique.addProperty(findProperty(activitySample, "timestamp"));
|
|
||||||
indexUnique.addProperty(deviceId);
|
|
||||||
indexUnique.makeUnique();
|
|
||||||
activitySample.addIndex(indexUnique);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Property findProperty(Entity entity, String propertyName) {
|
private static Property findProperty(Entity entity, String propertyName) {
|
||||||
|
@ -59,8 +59,10 @@ dependencies {
|
|||||||
compile 'com.github.pfichtner:durationformatter:0.1.1'
|
compile 'com.github.pfichtner:durationformatter:0.1.1'
|
||||||
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
|
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
|
||||||
compile 'net.e175.klaus:solarpositioning:0.0.9'
|
compile 'net.e175.klaus:solarpositioning:0.0.9'
|
||||||
compile 'com.github.freeyourgadget:greendao:c3830951e5dd3d1e63d7bac600d5f773b81df363'
|
compile 'com.github.freeyourgadget:greendao:1998d7cd2d21f662c6044f6ccf3b3a251bbad341'
|
||||||
compile 'com.github.woxthebox:draglistview:1.2.6'
|
compile 'com.github.woxthebox:draglistview:1.2.6'
|
||||||
|
|
||||||
|
// compile project(":DaoCore")
|
||||||
}
|
}
|
||||||
|
|
||||||
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
||||||
|
@ -146,8 +146,7 @@ public class GBApplication extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void setupDatabase(Context context) {
|
static void setupDatabase(Context context) {
|
||||||
// DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "test-db", null);
|
DBOpenHelper helper = new DBOpenHelper(context, "test-db5", null);
|
||||||
DBOpenHelper helper = new DBOpenHelper(context, "test-db4", null);
|
|
||||||
SQLiteDatabase db = helper.getWritableDatabase();
|
SQLiteDatabase db = helper.getWritableDatabase();
|
||||||
DaoMaster daoMaster = new DaoMaster(db);
|
DaoMaster daoMaster = new DaoMaster(db);
|
||||||
if (lockHandler == null) {
|
if (lockHandler == null) {
|
||||||
|
@ -328,13 +328,12 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
samples[minutes] = new MiBandActivitySample(
|
samples[minutes] = new MiBandActivitySample(
|
||||||
null,
|
|
||||||
timestampInSeconds,
|
timestampInSeconds,
|
||||||
|
deviceId,
|
||||||
|
userId,
|
||||||
intensity & 0xff,
|
intensity & 0xff,
|
||||||
steps & 0xff,
|
steps & 0xff,
|
||||||
category & 0xff,
|
category & 0xff,
|
||||||
userId,
|
|
||||||
deviceId,
|
|
||||||
heartrate & 0xff);
|
heartrate & 0xff);
|
||||||
samples[minutes].setProvider(provider);
|
samples[minutes].setProvider(provider);
|
||||||
|
|
||||||
|
@ -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, timestamp + i * 60, userId, deviceId, sample & 0xffff);
|
misfitSamples[i] = new PebbleMisfitSample(timestamp + i * 60, userId, deviceId, sample & 0xffff);
|
||||||
misfitSamples[i].setProvider(sampleProvider);
|
misfitSamples[i].setProvider(sampleProvider);
|
||||||
int steps = misfitSamples[i].getSteps();
|
int steps = misfitSamples[i].getSteps();
|
||||||
totalSteps += steps;
|
totalSteps += steps;
|
||||||
|
@ -114,7 +114,7 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
|
|||||||
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
|
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
|
||||||
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
|
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
|
||||||
PebbleMorpheuzSampleProvider sampleProvider = new PebbleMorpheuzSampleProvider(getDevice(), db.getDaoSession());
|
PebbleMorpheuzSampleProvider sampleProvider = new PebbleMorpheuzSampleProvider(getDevice(), db.getDaoSession());
|
||||||
PebbleMorpheuzSample sample = new PebbleMorpheuzSample(null, recording_base_timestamp + index * 600, userId, deviceId, intensity);
|
PebbleMorpheuzSample sample = new PebbleMorpheuzSample(recording_base_timestamp + index * 600, userId, deviceId, intensity);
|
||||||
sample.setProvider(sampleProvider);
|
sample.setProvider(sampleProvider);
|
||||||
sampleProvider.addGBActivitySample(sample);
|
sampleProvider.addGBActivitySample(sample);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -72,7 +72,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
||||||
for (OverlayRecord overlayRecord : overlayRecords) {
|
for (OverlayRecord overlayRecord : overlayRecords) {
|
||||||
overlayList.add(new PebbleHealthActivityOverlay(null, userId, deviceId, overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds - 1, overlayRecord.type)); //TODO: consider if "-1" is what we really want
|
overlayList.add(new PebbleHealthActivityOverlay(overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds - 1, deviceId, userId, overlayRecord.type)); //TODO: consider if "-1" is what we really want
|
||||||
}
|
}
|
||||||
overlayDao.insertOrReplaceInTx(overlayList);
|
overlayDao.insertOrReplaceInTx(overlayList);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -71,7 +71,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
||||||
for (SleepRecord sleepRecord : sleepRecords) {
|
for (SleepRecord sleepRecord : sleepRecords) {
|
||||||
overlayList.add(new PebbleHealthActivityOverlay(null, userId, deviceId, sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd - 1, sleepRecord.type)); //TODO: consider if "-1" is what we really want
|
overlayList.add(new PebbleHealthActivityOverlay(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd - 1, deviceId, userId, sleepRecord.type)); //TODO: consider if "-1" is what we really want
|
||||||
}
|
}
|
||||||
overlayDao.insertOrReplaceInTx(overlayList);
|
overlayDao.insertOrReplaceInTx(overlayList);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -82,7 +82,6 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||||||
for (int j = 0; j < stepsRecords.length; j++) {
|
for (int j = 0; j < stepsRecords.length; j++) {
|
||||||
StepsRecord stepsRecord = stepsRecords[j];
|
StepsRecord stepsRecord = stepsRecords[j];
|
||||||
samples[j] = new PebbleHealthActivitySample(
|
samples[j] = new PebbleHealthActivitySample(
|
||||||
null,
|
|
||||||
stepsRecord.timestamp,
|
stepsRecord.timestamp,
|
||||||
userId, deviceId,
|
userId, deviceId,
|
||||||
null, // raw data here
|
null, // raw data here
|
||||||
|
Loading…
Reference in New Issue
Block a user