1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 05:52:57 +01:00

Moyoung: Split up (modernize) database tables

This commit is contained in:
Arjan Schrijver 2024-08-23 23:32:24 +02:00
parent c5102bdf70
commit af33b30f66
9 changed files with 231 additions and 40 deletions

View File

@ -49,9 +49,8 @@ public class GBDaoGenerator {
private static final String SAMPLE_TEMPERATURE = "temperature";
private static final String SAMPLE_TEMPERATURE_TYPE = "temperatureType";
private static final String SAMPLE_WEIGHT_KG = "weightKg";
private static final String SAMPLE_BLOOD_PRESSURE_SYSTOLIC = "bloodPressureSystolic";
private static final String SAMPLE_BLOOD_PRESSURE_DIASTOLIC = "bloodPressureDiastolic";
private static final String SAMPLE_BLOOD_OXIDATION = "bloodOxidation";
private static final String SAMPLE_BLOOD_PRESSURE_SYSTOLIC = "bpSystolic";
private static final String SAMPLE_BLOOD_PRESSURE_DIASTOLIC = "bpDiastolic";
private static final String TIMESTAMP_FROM = "timestampFrom";
private static final String TIMESTAMP_TO = "timestampTo";
@ -151,6 +150,9 @@ public class GBDaoGenerator {
addColmiHrvValueSample(schema, user, device);
addColmiHrvSummarySample(schema, user, device);
addMoyoungActivitySample(schema, user, device);
addMoyoungHeartRateSample(schema, user, device);
addMoyoungSpo2Sample(schema, user, device);
addMoyoungBloodPressureSample(schema, user, device);
addHuaweiActivitySample(schema, user, device);
@ -591,12 +593,8 @@ public class GBDaoGenerator {
}
private static void addBloodPressureProperies(Entity activitySample) {
activitySample.addIntProperty(SAMPLE_BLOOD_PRESSURE_SYSTOLIC).notNull().codeBeforeGetterAndSetter(OVERRIDE);
activitySample.addIntProperty(SAMPLE_BLOOD_PRESSURE_DIASTOLIC).notNull().codeBeforeGetterAndSetter(OVERRIDE);
}
private static void addBloodOxidationProperies(Entity activitySample) {
activitySample.addIntProperty(SAMPLE_BLOOD_OXIDATION).notNull().codeBeforeGetterAndSetter(OVERRIDE);
activitySample.addIntProperty(SAMPLE_BLOOD_PRESSURE_SYSTOLIC).notNull();
activitySample.addIntProperty(SAMPLE_BLOOD_PRESSURE_DIASTOLIC).notNull();
}
private static Entity addPebbleHealthActivitySample(Schema schema, Entity user, Entity device) {
@ -1046,13 +1044,32 @@ public class GBDaoGenerator {
activitySample.addIntProperty("dataSource").notNull();
activitySample.addIntProperty("caloriesBurnt").notNull();
activitySample.addIntProperty("distanceMeters").notNull();
// addHeartRateProperties(activitySample);
// addBloodPressureProperies(activitySample);
// addBloodOxidationProperies(activitySample);
activitySample.addIntProperty("batteryLevel").notNull();
addHeartRateProperties(activitySample);
return activitySample;
}
private static Entity addMoyoungHeartRateSample(Schema schema, Entity user, Entity device) {
Entity heartRateSample = addEntity(schema, "MoyoungHeartRateSample");
heartRateSample.implementsSerializable();
addCommonTimeSampleProperties("AbstractHeartRateSample", heartRateSample, user, device);
heartRateSample.addIntProperty(SAMPLE_HEART_RATE).notNull();
return heartRateSample;
}
private static Entity addMoyoungSpo2Sample(Schema schema, Entity user, Entity device) {
Entity spo2sample = addEntity(schema, "MoyoungSpo2Sample");
addCommonTimeSampleProperties("AbstractSpo2Sample", spo2sample, user, device);
spo2sample.addIntProperty("spo2").notNull().codeBeforeGetter(OVERRIDE);
return spo2sample;
}
private static Entity addMoyoungBloodPressureSample(Schema schema, Entity user, Entity device) {
Entity bpSample = addEntity(schema, "MoyoungBloodPressureSample");
addCommonTimeSampleProperties("AbstractBloodPressureSample", bpSample, user, device);
addBloodPressureProperies(bpSample);
return bpSample;
}
private static void addCommonActivitySampleProperties(String superClass, Entity activitySample, Entity user, Entity device) {
activitySample.setSuperclass(superClass);
activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider");

View File

@ -30,6 +30,8 @@ import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungSpo2SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumDeviceVersion;
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumMetricSystem;
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumTimeSystem;
@ -46,6 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung.MoyoungDeviceSupport;
@ -91,6 +94,11 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractDeviceCoo
return new MoyoungSampleProvider(device, session);
}
@Override
public TimeSampleProvider<? extends Spo2Sample> getSpo2SampleProvider(GBDevice device, DaoSession session) {
return new MoyoungSpo2SampleProvider(device, session);
}
@Override
public int getAlarmSlotCount(GBDevice device) {
return 3;

View File

@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.moyoung;
import androidx.annotation.DrawableRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,6 +38,19 @@ public class ColmiI28UltraCoordinator extends AbstractMoyoungDeviceCoordinator {
return R.string.devicetype_colmi_i28_ultra;
}
@Override
@DrawableRes
public int getDefaultIconResource() {
return R.drawable.ic_device_miwatch;
}
@Override
@DrawableRes
public int getDisabledIconResource() {
return R.drawable.ic_device_miwatch_disabled;
}
@Override
public String getManufacturer() {
return "Colmi";

View File

@ -0,0 +1,56 @@
/* Copyright (C) 2024 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples;
import androidx.annotation.NonNull;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractTimeSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSample;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class MoyoungHeartRateSampleProvider extends AbstractTimeSampleProvider<MoyoungHeartRateSample> {
public MoyoungHeartRateSampleProvider(final GBDevice device, final DaoSession session) {
super(device, session);
}
@NonNull
@Override
public AbstractDao<MoyoungHeartRateSample, ?> getSampleDao() {
return getSession().getMoyoungHeartRateSampleDao();
}
@NonNull
@Override
protected Property getTimestampSampleProperty() {
return MoyoungHeartRateSampleDao.Properties.Timestamp;
}
@NonNull
@Override
protected Property getDeviceIdentifierSampleProperty() {
return MoyoungHeartRateSampleDao.Properties.DeviceId;
}
@Override
public MoyoungHeartRateSample createSample() {
return new MoyoungHeartRateSample();
}
}

View File

@ -0,0 +1,56 @@
/* Copyright (C) 2024 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples;
import androidx.annotation.NonNull;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractTimeSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungSpo2Sample;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungSpo2SampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class MoyoungSpo2SampleProvider extends AbstractTimeSampleProvider<MoyoungSpo2Sample> {
public MoyoungSpo2SampleProvider(final GBDevice device, final DaoSession session) {
super(device, session);
}
@NonNull
@Override
public AbstractDao<MoyoungSpo2Sample, ?> getSampleDao() {
return getSession().getMoyoungSpo2SampleDao();
}
@NonNull
@Override
protected Property getTimestampSampleProperty() {
return MoyoungSpo2SampleDao.Properties.Timestamp;
}
@NonNull
@Override
protected Property getDeviceIdentifierSampleProperty() {
return MoyoungSpo2SampleDao.Properties.DeviceId;
}
@Override
public MoyoungSpo2Sample createSample() {
return new MoyoungSpo2Sample();
}
}

View File

@ -0,0 +1,36 @@
/* Copyright (C) 2024 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.entities;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.model.BloodPressureSample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public abstract class AbstractBloodPressureSample extends AbstractTimeSample implements BloodPressureSample {
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimestampMillis(getTimestamp())) +
", bpSystolic=" + getBpSystolic() +
", bpDiastolic=" + getBpDiastolic() +
", userId=" + getUserId() +
", deviceId=" + getDeviceId() +
"}";
}
}

View File

@ -0,0 +1,22 @@
/* Copyright (C) 2024 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.model;
public interface BloodPressureSample extends TimeSample {
int getBpSystolic();
int getBpDiastolic();
}

View File

@ -243,7 +243,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
sample.setSteps(ActivitySample.NOT_MEASURED);
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
@ -272,7 +272,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
sample.setSteps(ActivitySample.NOT_MEASURED);
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
@ -301,7 +301,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
sample.setSteps(ActivitySample.NOT_MEASURED);
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
@ -437,25 +437,6 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
LOG.warn("Battery info: " + info);
batteryCmd.level = (short) info.getPercentCharged();
handleGBDeviceEvent(batteryCmd);
MoyoungActivitySample sample = new MoyoungActivitySample();
sample.setTimestamp((int) (System.currentTimeMillis() / 1000));
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(MoyoungSampleProvider.SOURCE_BATTERY);
sample.setBatteryLevel(batteryCmd.level);
sample.setSteps(ActivitySample.NOT_MEASURED);
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
sample.setHeartRate(ActivitySample.NOT_MEASURED);
// sample.setBloodPressureSystolic(ActivitySample.NOT_MEASURED);
// sample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
addGBActivitySample(sample);
broadcastSample(sample);
}
@Override
@ -666,7 +647,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(MoyoungSampleProvider.SOURCE_STEPS_IDLE);
sample.setBatteryLevel(batteryCmd.level);
// sample.setBatteryLevel(batteryCmd.level);
sample.setSteps(0);
sample.setDistanceMeters(0);
sample.setCaloriesBurnt(0);
@ -763,7 +744,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
sample.setDataSource(daysAgo == 0 ? MoyoungSampleProvider.SOURCE_STEPS_REALTIME : MoyoungSampleProvider.SOURCE_STEPS_SUMMARY);
sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
sample.setSteps(newSteps);
sample.setDistanceMeters(newDistance);
sample.setCaloriesBurnt(newCalories);
@ -868,7 +849,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
prevSegmentSample.setRawKind(prevActivityType);
prevSegmentSample.setDataSource(MoyoungSampleProvider.SOURCE_SLEEP_SUMMARY);
prevSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// prevSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
prevSegmentSample.setSteps(ActivitySample.NOT_MEASURED);
prevSegmentSample.setDistanceMeters(ActivitySample.NOT_MEASURED);
prevSegmentSample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
@ -890,7 +871,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
nextSegmentSample.setRawKind(activityType);
nextSegmentSample.setDataSource(MoyoungSampleProvider.SOURCE_SLEEP_SUMMARY);
nextSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// nextSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
nextSegmentSample.setSteps(ActivitySample.NOT_MEASURED);
nextSegmentSample.setDistanceMeters(ActivitySample.NOT_MEASURED);
nextSegmentSample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);

View File

@ -183,7 +183,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED); // Training type will be taken later from CMD_QUERY_MOVEMENT_HEART_RATE (it's not present in the main data packet)
sample.setDataSource(MoyoungSampleProvider.SOURCE_TRAINING_HEARTRATE);
sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
sample.setSteps(ActivitySample.NOT_MEASURED);
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);