mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-03 04:56:27 +02:00
DB refactoring: remove activity type from Morpheuz database, determinate it in PebbleMorpheuzSampleProvider instead
This commit is contained in:
parent
e05d40dc7e
commit
6b2565e4c9
@ -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(10, MAIN_PACKAGE + ".entities");
|
Schema schema = new Schema(11, MAIN_PACKAGE + ".entities");
|
||||||
|
|
||||||
addActivityDescription(schema);
|
addActivityDescription(schema);
|
||||||
|
|
||||||
@ -164,7 +164,6 @@ public class GBDaoGenerator {
|
|||||||
Entity activitySample = addEntity(schema, "PebbleMorpheuzSample");
|
Entity activitySample = addEntity(schema, "PebbleMorpheuzSample");
|
||||||
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
|
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
|
||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
activitySample.addIntProperty("rawKind").notNull();
|
|
||||||
addCommonActivitySampleProperties2(activitySample, user, device);
|
addCommonActivitySampleProperties2(activitySample, user, device);
|
||||||
return activitySample;
|
return activitySample;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,10 @@ public abstract class AbstractSampleProvider<T extends AbstractActivitySample> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
|
protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
|
||||||
|
if (getRawKindSampleProperty() == null && activityType != ActivityKind.TYPE_ALL) {
|
||||||
|
// if we do not have a raw kind property we cannot query anything else then TYPE_ALL
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
QueryBuilder<T> qb = getSampleDao().queryBuilder();
|
QueryBuilder<T> qb = getSampleDao().queryBuilder();
|
||||||
Property timestampProperty = getTimestampSampleProperty();
|
Property timestampProperty = getTimestampSampleProperty();
|
||||||
Device dbDevice = DBHelper.findDevice(getmDevice(), getSession());
|
Device dbDevice = DBHelper.findDevice(getmDevice(), getSession());
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.greenrobot.dao.AbstractDao;
|
import de.greenrobot.dao.AbstractDao;
|
||||||
import de.greenrobot.dao.Property;
|
import de.greenrobot.dao.Property;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||||
@ -15,7 +18,7 @@ public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider<PebbleM
|
|||||||
public static final int TYPE_DEEP_SLEEP = 5;
|
public static final int TYPE_DEEP_SLEEP = 5;
|
||||||
public static final int TYPE_LIGHT_SLEEP = 4;
|
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;
|
public static final int TYPE_UNKNOWN = 0;
|
||||||
|
|
||||||
protected float movementDivisor = 5000f;
|
protected float movementDivisor = 5000f;
|
||||||
|
|
||||||
@ -35,7 +38,7 @@ public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider<PebbleM
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Property getRawKindSampleProperty() {
|
protected Property getRawKindSampleProperty() {
|
||||||
return PebbleMorpheuzSampleDao.Properties.RawKind;
|
return null; // not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +74,6 @@ public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider<PebbleM
|
|||||||
return TYPE_DEEP_SLEEP;
|
return TYPE_DEEP_SLEEP;
|
||||||
case ActivityKind.TYPE_LIGHT_SLEEP:
|
case ActivityKind.TYPE_LIGHT_SLEEP:
|
||||||
return TYPE_LIGHT_SLEEP;
|
return TYPE_LIGHT_SLEEP;
|
||||||
case ActivityKind.TYPE_UNKNOWN: // fall through
|
|
||||||
default:
|
default:
|
||||||
return TYPE_UNKNOWN;
|
return TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
@ -82,6 +84,38 @@ public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider<PebbleM
|
|||||||
return rawIntensity / movementDivisor;
|
return rawIntensity / movementDivisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PebbleMorpheuzSample> getActivitySamples(int timestamp_from, int timestamp_to) {
|
||||||
|
List<PebbleMorpheuzSample> samples = getAllActivitySamples(timestamp_from, timestamp_to);
|
||||||
|
List<PebbleMorpheuzSample> filteredSamples = new ArrayList<>();
|
||||||
|
for (PebbleMorpheuzSample sample : samples) {
|
||||||
|
if (sample.getRawIntensity() > 1000) {
|
||||||
|
sample.setRawKind(ActivityKind.TYPE_ACTIVITY);
|
||||||
|
filteredSamples.add(sample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PebbleMorpheuzSample> getSleepSamples(int timestamp_from, int timestamp_to) {
|
||||||
|
List<PebbleMorpheuzSample> samples = getAllActivitySamples(timestamp_from, timestamp_to);
|
||||||
|
List<PebbleMorpheuzSample> filteredSamples = new ArrayList<>();
|
||||||
|
for (PebbleMorpheuzSample sample : samples) {
|
||||||
|
if (sample.getRawIntensity() < 1000) {
|
||||||
|
if (sample.getRawIntensity() <= 120) {
|
||||||
|
sample.setRawKind(ActivityKind.TYPE_DEEP_SLEEP);
|
||||||
|
} else {
|
||||||
|
sample.setRawKind(ActivityKind.TYPE_LIGHT_SLEEP);
|
||||||
|
}
|
||||||
|
filteredSamples.add(sample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredSamples;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getID() {
|
public int getID() {
|
||||||
return SampleProvider.PROVIDER_PEBBLE_MORPHEUZ;
|
return SampleProvider.PROVIDER_PEBBLE_MORPHEUZ;
|
||||||
|
@ -109,18 +109,12 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
|
|||||||
int index = ((int) pair.second >> 16);
|
int index = ((int) pair.second >> 16);
|
||||||
int intensity = ((int) pair.second & 0xffff);
|
int intensity = ((int) pair.second & 0xffff);
|
||||||
LOG.info("got point:" + index + " " + intensity);
|
LOG.info("got point:" + index + " " + intensity);
|
||||||
int type = PebbleMorpheuzSampleProvider.TYPE_ACTIVITY;
|
|
||||||
if (intensity <= 120) {
|
|
||||||
type = PebbleMorpheuzSampleProvider.TYPE_DEEP_SLEEP;
|
|
||||||
} else if (intensity <= 1000) {
|
|
||||||
type = PebbleMorpheuzSampleProvider.TYPE_LIGHT_SLEEP;
|
|
||||||
}
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
try (DBHandler db = GBApplication.acquireDB()) {
|
try (DBHandler db = GBApplication.acquireDB()) {
|
||||||
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, intensity, type, userId, deviceId);
|
PebbleMorpheuzSample sample = new PebbleMorpheuzSample(null, recording_base_timestamp + index * 600, intensity, userId, deviceId);
|
||||||
sample.setProvider(sampleProvider);
|
sample.setProvider(sampleProvider);
|
||||||
sampleProvider.addGBActivitySample(sample);
|
sampleProvider.addGBActivitySample(sample);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user