mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 20:06:52 +01:00
Moyoung: Persist received data in new tables
This commit is contained in:
parent
5fb78514a8
commit
5e411b8f81
@ -26,11 +26,13 @@ import androidx.annotation.NonNull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
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.MoyoungActivitySampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungSpo2SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumDeviceVersion;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumMetricSystem;
|
||||
@ -46,6 +48,10 @@ import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSett
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSettingUserInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungBloodPressureSampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungSpo2SampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
|
||||
@ -76,7 +82,17 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractDeviceCoo
|
||||
|
||||
@Override
|
||||
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||
// TODO: remove device specific data
|
||||
Long deviceId = device.getId();
|
||||
QueryBuilder<?> qb;
|
||||
|
||||
qb = session.getMoyoungActivitySampleDao().queryBuilder();
|
||||
qb.where(MoyoungActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||
qb = session.getMoyoungHeartRateSampleDao().queryBuilder();
|
||||
qb.where(MoyoungHeartRateSampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||
qb = session.getMoyoungSpo2SampleDao().queryBuilder();
|
||||
qb.where(MoyoungSpo2SampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||
qb = session.getMoyoungBloodPressureSampleDao().queryBuilder();
|
||||
qb.where(MoyoungBloodPressureSampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -91,7 +107,7 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractDeviceCoo
|
||||
|
||||
@Override
|
||||
public SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
||||
return new MoyoungSampleProvider(device, session);
|
||||
return new MoyoungActivitySampleProvider(device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,14 +14,20 @@
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.moyoung;
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import de.greenrobot.dao.Property;
|
||||
@ -29,15 +35,19 @@ import de.greenrobot.dao.internal.SqlUtils;
|
||||
import de.greenrobot.dao.query.WhereCondition;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
public class MoyoungSampleProvider extends AbstractSampleProvider<MoyoungActivitySample> {
|
||||
public class MoyoungActivitySampleProvider extends AbstractSampleProvider<MoyoungActivitySample> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MoyoungActivitySampleProvider.class);
|
||||
|
||||
public static final int SOURCE_NOT_MEASURED = -1;
|
||||
public static final int SOURCE_STEPS_REALTIME = 1; // steps gathered at realtime from the steps characteristic
|
||||
public static final int SOURCE_STEPS_SUMMARY = 2; // steps gathered from the daily summary
|
||||
@ -65,7 +75,7 @@ public class MoyoungSampleProvider extends AbstractSampleProvider<MoyoungActivit
|
||||
public static final int ACTIVITY_SLEEP_START = 18;
|
||||
public static final int ACTIVITY_SLEEP_END = 19;
|
||||
|
||||
public MoyoungSampleProvider(GBDevice device, DaoSession session) {
|
||||
public MoyoungActivitySampleProvider(GBDevice device, DaoSession session) {
|
||||
super(device, session);
|
||||
}
|
||||
|
||||
@ -146,6 +156,66 @@ public class MoyoungSampleProvider extends AbstractSampleProvider<MoyoungActivit
|
||||
return rawIntensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<MoyoungActivitySample> getGBActivitySamples(final int timestamp_from, final int timestamp_to) {
|
||||
LOG.trace(
|
||||
"Getting Moyoung activity samples between {} and {}",
|
||||
timestamp_from,
|
||||
timestamp_to
|
||||
);
|
||||
final long nanoStart = System.nanoTime();
|
||||
|
||||
final List<MoyoungActivitySample> samples = super.getGBActivitySamples(timestamp_from, timestamp_to);
|
||||
final Map<Integer, MoyoungActivitySample> sampleByTs = new HashMap<>();
|
||||
for (final MoyoungActivitySample sample : samples) {
|
||||
sampleByTs.put(sample.getTimestamp(), sample);
|
||||
}
|
||||
|
||||
overlayHeartRate(sampleByTs, timestamp_from, timestamp_to);
|
||||
// overlaySleep(sampleByTs, timestamp_from, timestamp_to);
|
||||
|
||||
// Add empty dummy samples every 5 min to make sure the charts and stats aren't too malformed
|
||||
// This is necessary due to the Colmi rings just reporting steps/calories/distance aggregates per hour
|
||||
// for (int i=timestamp_from; i<=timestamp_to; i+=300) {
|
||||
// MoyoungActivitySample sample = sampleByTs.get(i);
|
||||
// if (sample == null) {
|
||||
// sample = new MoyoungActivitySample();
|
||||
// sample.setTimestamp(i);
|
||||
// sample.setProvider(this);
|
||||
// sample.setRawKind(ActivitySample.NOT_MEASURED);
|
||||
// sampleByTs.put(i, sample);
|
||||
// }
|
||||
// }
|
||||
|
||||
final List<MoyoungActivitySample> finalSamples = new ArrayList<>(sampleByTs.values());
|
||||
Collections.sort(finalSamples, (a, b) -> Integer.compare(a.getTimestamp(), b.getTimestamp()));
|
||||
|
||||
final long nanoEnd = System.nanoTime();
|
||||
final long executionTime = (nanoEnd - nanoStart) / 1000000;
|
||||
LOG.trace("Getting Moyoung samples took {}ms", executionTime);
|
||||
|
||||
return finalSamples;
|
||||
}
|
||||
|
||||
private void overlayHeartRate(final Map<Integer, MoyoungActivitySample> sampleByTs, final int timestamp_from, final int timestamp_to) {
|
||||
final MoyoungHeartRateSampleProvider heartRateSampleProvider = new MoyoungHeartRateSampleProvider(getDevice(), getSession());
|
||||
final List<MoyoungHeartRateSample> hrSamples = heartRateSampleProvider.getAllSamples(timestamp_from * 1000L, timestamp_to * 1000L);
|
||||
|
||||
for (final MoyoungHeartRateSample hrSample : hrSamples) {
|
||||
// round to the nearest minute, we don't need per-second granularity
|
||||
final int tsSeconds = (int) ((hrSample.getTimestamp() / 1000) / 60) * 60;
|
||||
MoyoungActivitySample sample = sampleByTs.get(tsSeconds);
|
||||
if (sample == null) {
|
||||
sample = new MoyoungActivitySample();
|
||||
sample.setTimestamp(tsSeconds);
|
||||
sample.setProvider(this);
|
||||
sampleByTs.put(tsSeconds, sample);
|
||||
}
|
||||
|
||||
sample.setHeartRate(hrSample.getHeartRate());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the activity kind from NOT_MEASURED to new_raw_activity_kind on the given range
|
||||
* @param timestamp_from the start timestamp
|
@ -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.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungBloodPressureSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungBloodPressureSampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public class MoyoungBloodPressureSampleProvider extends AbstractTimeSampleProvider<MoyoungBloodPressureSample> {
|
||||
public MoyoungBloodPressureSampleProvider(final GBDevice device, final DaoSession session) {
|
||||
super(device, session);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AbstractDao<MoyoungBloodPressureSample, ?> getSampleDao() {
|
||||
return getSession().getMoyoungBloodPressureSampleDao();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Property getTimestampSampleProperty() {
|
||||
return MoyoungBloodPressureSampleDao.Properties.Timestamp;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Property getDeviceIdentifierSampleProperty() {
|
||||
return MoyoungBloodPressureSampleDao.Properties.DeviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoyoungBloodPressureSample createSample() {
|
||||
return new MoyoungBloodPressureSample();
|
||||
}
|
||||
}
|
@ -59,9 +59,12 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicContr
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.AbstractMoyoungDeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungWeatherForecast;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungWeatherToday;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungActivitySampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungBloodPressureSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungHeartRateSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungSpo2SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumDeviceVersion;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumLanguage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumTimeSystem;
|
||||
@ -73,6 +76,9 @@ import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungBloodPressureSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungSpo2Sample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
@ -102,7 +108,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
|
||||
public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MoyoungDeviceSupport.class);
|
||||
private static final long IDLE_STEPS_INTERVAL = 5 * 60 * 1000;
|
||||
|
||||
@ -237,24 +242,22 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int heartRate = payload[0];
|
||||
Log.i("XXXXXXXX", "Measure heart rate finished: " + heartRate + " BPM");
|
||||
|
||||
MoyoungActivitySample sample = new MoyoungActivitySample();
|
||||
sample.setTimestamp((int) (System.currentTimeMillis() / 1000));
|
||||
|
||||
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
|
||||
|
||||
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
sample.setSteps(ActivitySample.NOT_MEASURED);
|
||||
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
|
||||
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
MoyoungHeartRateSampleProvider sampleProvider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||
|
||||
MoyoungHeartRateSample sample = new MoyoungHeartRateSample();
|
||||
sample.setTimestamp(System.currentTimeMillis());
|
||||
sample.setHeartRate(heartRate);
|
||||
// sample.setBloodPressureSystolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
sample.setDeviceId(deviceId);
|
||||
sample.setUserId(userId);
|
||||
|
||||
addGBActivitySample(sample);
|
||||
broadcastSample(sample);
|
||||
sampleProvider.addSample(sample);
|
||||
// broadcastSample(sample);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error acquiring database for recording heart rate samples", e);
|
||||
}
|
||||
|
||||
if (realTimeHeartRate)
|
||||
onHeartRateTest();
|
||||
@ -266,24 +269,22 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int percent = payload[0];
|
||||
Log.i("XXXXXXXX", "Measure blood oxygen finished: " + percent + "%");
|
||||
|
||||
MoyoungActivitySample sample = new MoyoungActivitySample();
|
||||
sample.setTimestamp((int) (System.currentTimeMillis() / 1000));
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
MoyoungSpo2SampleProvider sampleProvider = new MoyoungSpo2SampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||
|
||||
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
|
||||
MoyoungSpo2Sample sample = new MoyoungSpo2Sample();
|
||||
sample.setTimestamp(System.currentTimeMillis());
|
||||
sample.setSpo2(percent);
|
||||
sample.setDeviceId(deviceId);
|
||||
sample.setUserId(userId);
|
||||
|
||||
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
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(percent);
|
||||
|
||||
addGBActivitySample(sample);
|
||||
broadcastSample(sample);
|
||||
sampleProvider.addSample(sample);
|
||||
// broadcastSample(sample);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error acquiring database for recording SpO2 samples", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -294,25 +295,23 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int data2 = payload[2];
|
||||
Log.i("XXXXXXXX", "Measure blood pressure finished: " + data1 + "/" + data2 + " (" + dataUnknown + ")");
|
||||
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
MoyoungBloodPressureSampleProvider sampleProvider = new MoyoungBloodPressureSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||
|
||||
MoyoungActivitySample sample = new MoyoungActivitySample();
|
||||
sample.setTimestamp((int) (System.currentTimeMillis() / 1000));
|
||||
MoyoungBloodPressureSample sample = new MoyoungBloodPressureSample();
|
||||
sample.setTimestamp(System.currentTimeMillis());
|
||||
sample.setBpSystolic(data1);
|
||||
sample.setBpSystolic(data2);
|
||||
sample.setDeviceId(deviceId);
|
||||
sample.setUserId(userId);
|
||||
|
||||
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(MoyoungSampleProvider.SOURCE_SINGLE_MEASURE);
|
||||
|
||||
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
sample.setSteps(ActivitySample.NOT_MEASURED);
|
||||
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
|
||||
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
|
||||
|
||||
sample.setHeartRate(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureSystolic(data1);
|
||||
// sample.setBloodPressureDiastolic(data2);
|
||||
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
addGBActivitySample(sample);
|
||||
broadcastSample(sample);
|
||||
sampleProvider.addSample(sample);
|
||||
// broadcastSample(sample);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error acquiring database for recording blood pressure samples", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -404,7 +403,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungActivitySampleProvider provider = new MoyoungActivitySampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
for (MoyoungActivitySample sample : samples) {
|
||||
sample.setDevice(device);
|
||||
@ -634,7 +633,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungActivitySampleProvider provider = new MoyoungActivitySampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
int currentSampleTimestamp = (int)(Calendar.getInstance().getTimeInMillis() / 1000);
|
||||
|
||||
@ -644,21 +643,17 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sample.setProvider(provider);
|
||||
sample.setTimestamp(currentSampleTimestamp);
|
||||
|
||||
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(MoyoungSampleProvider.SOURCE_STEPS_IDLE);
|
||||
sample.setRawKind(MoyoungActivitySampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(MoyoungActivitySampleProvider.SOURCE_STEPS_IDLE);
|
||||
|
||||
// sample.setBatteryLevel(batteryCmd.level);
|
||||
sample.setSteps(0);
|
||||
sample.setDistanceMeters(0);
|
||||
sample.setCaloriesBurnt(0);
|
||||
|
||||
sample.setHeartRate(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureSystolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
provider.addGBActivitySample(sample);
|
||||
broadcastSample(sample);
|
||||
// provider.addGBActivitySample(sample);
|
||||
// broadcastSample(sample);
|
||||
|
||||
LOG.info("Adding an idle sample: " + sample.toString());
|
||||
} catch (Exception ex) {
|
||||
@ -687,7 +682,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungActivitySampleProvider provider = new MoyoungActivitySampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
Calendar thisSample = Calendar.getInstance();
|
||||
if (daysAgo != 0)
|
||||
@ -741,19 +736,12 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sample.setProvider(provider);
|
||||
sample.setTimestamp(thisSampleTimestamp);
|
||||
|
||||
sample.setRawKind(MoyoungSampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(daysAgo == 0 ? MoyoungSampleProvider.SOURCE_STEPS_REALTIME : MoyoungSampleProvider.SOURCE_STEPS_SUMMARY);
|
||||
|
||||
// sample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
// sample.setRawKind(MoyoungActivitySampleProvider.ACTIVITY_NOT_MEASURED);
|
||||
sample.setDataSource(daysAgo == 0 ? MoyoungActivitySampleProvider.SOURCE_STEPS_REALTIME : MoyoungActivitySampleProvider.SOURCE_STEPS_SUMMARY);
|
||||
sample.setSteps(newSteps);
|
||||
sample.setDistanceMeters(newDistance);
|
||||
sample.setCaloriesBurnt(newCalories);
|
||||
|
||||
sample.setHeartRate(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureSystolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
provider.addGBActivitySample(sample);
|
||||
if (isRealtime)
|
||||
{
|
||||
@ -776,7 +764,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (data.length % 3 != 0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
int prevActivityType = MoyoungSampleProvider.ACTIVITY_SLEEP_START;
|
||||
int prevActivityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_START;
|
||||
int prevSampleTimestamp = -1;
|
||||
|
||||
for(int i = 0; i < data.length / 3; i++)
|
||||
@ -816,7 +804,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungActivitySampleProvider provider = new MoyoungActivitySampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
Calendar thisSample = Calendar.getInstance();
|
||||
thisSample.add(Calendar.HOUR_OF_DAY, 4); // the clock assumes the sleep day changes at 20:00, so move the time forward to make the day correct
|
||||
@ -831,11 +819,11 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
int activityType;
|
||||
if (type == MoyoungConstants.SLEEP_SOBER)
|
||||
activityType = MoyoungSampleProvider.ACTIVITY_SLEEP_END;
|
||||
activityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_END;
|
||||
else if (type == MoyoungConstants.SLEEP_LIGHT)
|
||||
activityType = MoyoungSampleProvider.ACTIVITY_SLEEP_LIGHT;
|
||||
activityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_LIGHT;
|
||||
else if (type == MoyoungConstants.SLEEP_RESTFUL)
|
||||
activityType = MoyoungSampleProvider.ACTIVITY_SLEEP_RESTFUL;
|
||||
activityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_RESTFUL;
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid sleep type");
|
||||
|
||||
@ -847,7 +835,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
prevSegmentSample.setTimestamp(thisSampleTimestamp - 1);
|
||||
|
||||
prevSegmentSample.setRawKind(prevActivityType);
|
||||
prevSegmentSample.setDataSource(MoyoungSampleProvider.SOURCE_SLEEP_SUMMARY);
|
||||
prevSegmentSample.setDataSource(MoyoungActivitySampleProvider.SOURCE_SLEEP_SUMMARY);
|
||||
|
||||
// prevSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
prevSegmentSample.setSteps(ActivitySample.NOT_MEASURED);
|
||||
@ -859,7 +847,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// prevSegmentSample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// prevSegmentSample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
addGBActivitySampleIfNotExists(provider, prevSegmentSample);
|
||||
// addGBActivitySampleIfNotExists(provider, prevSegmentSample);
|
||||
|
||||
// Insert the start of new segment sample
|
||||
MoyoungActivitySample nextSegmentSample = new MoyoungActivitySample();
|
||||
@ -869,7 +857,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
nextSegmentSample.setTimestamp(thisSampleTimestamp);
|
||||
|
||||
nextSegmentSample.setRawKind(activityType);
|
||||
nextSegmentSample.setDataSource(MoyoungSampleProvider.SOURCE_SLEEP_SUMMARY);
|
||||
nextSegmentSample.setDataSource(MoyoungActivitySampleProvider.SOURCE_SLEEP_SUMMARY);
|
||||
|
||||
// nextSegmentSample.setBatteryLevel(ActivitySample.NOT_MEASURED);
|
||||
nextSegmentSample.setSteps(ActivitySample.NOT_MEASURED);
|
||||
@ -881,15 +869,15 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// nextSegmentSample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// nextSegmentSample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
addGBActivitySampleIfNotExists(provider, nextSegmentSample);
|
||||
// addGBActivitySampleIfNotExists(provider, nextSegmentSample);
|
||||
|
||||
// Set the activity type on all samples in this time period
|
||||
if (prevActivityType != MoyoungSampleProvider.ACTIVITY_SLEEP_START)
|
||||
provider.updateActivityInRange(prevSampleTimestamp, thisSampleTimestamp, prevActivityType);
|
||||
if (prevActivityType != MoyoungActivitySampleProvider.ACTIVITY_SLEEP_START)
|
||||
// provider.updateActivityInRange(prevSampleTimestamp, thisSampleTimestamp, prevActivityType);
|
||||
|
||||
prevActivityType = activityType;
|
||||
if (prevActivityType == MoyoungSampleProvider.ACTIVITY_SLEEP_END)
|
||||
prevActivityType = MoyoungSampleProvider.ACTIVITY_SLEEP_START;
|
||||
if (prevActivityType == MoyoungActivitySampleProvider.ACTIVITY_SLEEP_END)
|
||||
prevActivityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_START;
|
||||
prevSampleTimestamp = thisSampleTimestamp;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@ -930,7 +918,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungActivitySampleProvider provider = new MoyoungActivitySampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
BaseActivitySummaryDao summaryDao = provider.getSession().getBaseActivitySummaryDao();
|
||||
|
||||
QueryBuilder<BaseActivitySummary> qb = summaryDao.queryBuilder();
|
||||
@ -952,21 +940,21 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
ActivityKind gbType = provider.normalizeType(type);
|
||||
String name;
|
||||
if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_ROPE)
|
||||
if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_ROPE)
|
||||
name = "Rope";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_BADMINTON)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_BADMINTON)
|
||||
name = "Badminton";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_BASKETBALL)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_BASKETBALL)
|
||||
name = "Basketball";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_FOOTBALL)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_FOOTBALL)
|
||||
name = "Football";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_MOUNTAINEERING)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_MOUNTAINEERING)
|
||||
name = "Mountaineering";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_TENNIS)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_TENNIS)
|
||||
name = "Tennis";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_RUGBY)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_RUGBY)
|
||||
name = "Rugby";
|
||||
else if (type == MoyoungSampleProvider.ACTIVITY_TRAINING_GOLF)
|
||||
else if (type == MoyoungActivitySampleProvider.ACTIVITY_TRAINING_GOLF)
|
||||
name = "Golf";
|
||||
else
|
||||
name = gbType.name();
|
||||
@ -989,7 +977,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void addGBActivitySampleIfNotExists(MoyoungSampleProvider provider, MoyoungActivitySample sample)
|
||||
private void addGBActivitySampleIfNotExists(MoyoungActivitySampleProvider provider, MoyoungActivitySample sample)
|
||||
{
|
||||
boolean alreadyHaveThisSample = false;
|
||||
for (MoyoungActivitySample sample2 : provider.getAllActivitySamples(sample.getTimestamp() - 1, sample.getTimestamp() + 1))
|
||||
|
@ -38,9 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungHeartRateSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungHeartRateSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
|
||||
@ -163,7 +163,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
|
||||
User user = DBHelper.getUser(dbHandler.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
MoyoungSampleProvider provider = new MoyoungSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
MoyoungHeartRateSampleProvider provider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
|
||||
Log.i("START DATE", dateRecorded.getTime().toString());
|
||||
while (dataBuffer.hasRemaining())
|
||||
@ -174,26 +174,13 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
|
||||
|
||||
Log.i("MEASUREMENT", "at " + dateRecorded.getTime().toString() + " was " + measurement);
|
||||
|
||||
MoyoungActivitySample sample = new MoyoungActivitySample();
|
||||
MoyoungHeartRateSample sample = new MoyoungHeartRateSample();
|
||||
sample.setDevice(device);
|
||||
sample.setUser(user);
|
||||
sample.setProvider(provider);
|
||||
sample.setTimestamp((int)(dateRecorded.getTimeInMillis() / 1000));
|
||||
|
||||
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.setSteps(ActivitySample.NOT_MEASURED);
|
||||
sample.setDistanceMeters(ActivitySample.NOT_MEASURED);
|
||||
sample.setCaloriesBurnt(ActivitySample.NOT_MEASURED);
|
||||
|
||||
sample.setHeartRate(measurement != 0 ? measurement : ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureSystolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodPressureDiastolic(ActivitySample.NOT_MEASURED);
|
||||
// sample.setBloodOxidation(ActivitySample.NOT_MEASURED);
|
||||
|
||||
provider.addGBActivitySample(sample);
|
||||
provider.addSample(sample);
|
||||
LOG.info("Adding a training sample: " + sample.toString());
|
||||
|
||||
dateRecorded.add(Calendar.MINUTE, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user