1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-11 18:35:49 +01:00

Zepp OS: Fix respiratory rate being detected as awake

This commit is contained in:
José Rebelo 2024-11-27 21:38:47 +00:00
parent 53ccae347d
commit 2e6552e3d5
6 changed files with 39 additions and 12 deletions

View File

@ -83,7 +83,7 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment<Respir
if (stepsDayList.isEmpty()) {
LOG.error("Failed to get RespiratoryRateDay for {}", day);
List<? extends AbstractRespiratoryRateSample> s = new ArrayList<>();
RespiratoryRateDay = new RespiratoryRateDay(day, new ArrayList<>(), new ArrayList<>());
RespiratoryRateDay = new RespiratoryRateDay(day, new ArrayList<>(), new ArrayList<>(), true);
} else {
RespiratoryRateDay = stepsDayList.get(0);
}
@ -92,10 +92,11 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment<Respir
@Override
protected void updateChartsnUIThread(RespiratoryRateFragment.RespiratoryRateDay respiratoryRateDay) {
awakeAvg.setText(String.format(String.valueOf(respiratoryRateDay.awakeRateAvg)));
sleepAvg.setText(String.valueOf(respiratoryRateDay.sleepRateAvg));
lowest.setText(String.valueOf(respiratoryRateDay.rateLowest));
highest.setText(String.valueOf(respiratoryRateDay.rateHighest));
final String emptyValue = requireContext().getString(R.string.stats_empty_value);
awakeAvg.setText(respiratoryRateDay.awakeRateAvg > 0 ? String.valueOf(respiratoryRateDay.awakeRateAvg) : emptyValue);
sleepAvg.setText(respiratoryRateDay.sleepRateAvg > 0 ? String.valueOf(respiratoryRateDay.sleepRateAvg) : emptyValue);
lowest.setText(respiratoryRateDay.rateLowest > 0 ? String.valueOf(respiratoryRateDay.rateLowest) : emptyValue);
highest.setText(respiratoryRateDay.rateHighest > 0 ? String.valueOf(respiratoryRateDay.rateHighest) : emptyValue);
// Chart
final List<LegendEntry> legendEntries = new ArrayList<>(1);

View File

@ -18,7 +18,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.RespiratoryRateSample;
abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractChartFragment<T> {
protected static final Logger LOG = LoggerFactory.getLogger(StepsDailyFragment.class);
protected static final Logger LOG = LoggerFactory.getLogger(RespiratoryRateFragment.class);
protected int CHART_TEXT_COLOR;
protected int TEXT_COLOR;
@ -46,6 +46,8 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
day = (Calendar) day.clone(); // do not modify the caller's argument
day.add(Calendar.DATE, -TOTAL_DAYS + 1);
final boolean supportsDayRespiratoryRate = device.getDeviceCoordinator().supportsDayRespiratoryRate();
List<RespiratoryRateDay> daysData = new ArrayList<>();;
for (int counter = 0; counter < TOTAL_DAYS; counter++) {
int startTs;
@ -62,7 +64,7 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
List<SleepAnalysis.SleepSession> sleepSessions = sleepAnalysis.calculateSleepSessions(activitySamples);
List<? extends AbstractRespiratoryRateSample> samples = getRespiratoryRateSamples(db, device, startTs, endTs);
Calendar d = (Calendar) day.clone();
daysData.add(new RespiratoryRateDay(d, samples, sleepSessions));
daysData.add(new RespiratoryRateDay(d, samples, sleepSessions, supportsDayRespiratoryRate));
day.add(Calendar.DATE, 1);
}
return daysData;
@ -91,7 +93,10 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
List<? extends AbstractRespiratoryRateSample> respiratoryRateSamples;
List<SleepAnalysis.SleepSession> sleepSessions;
protected RespiratoryRateDay(Calendar day, List<? extends AbstractRespiratoryRateSample> respiratoryRateSamples, List<SleepAnalysis.SleepSession> sleepSessions) {
protected RespiratoryRateDay(Calendar day,
List<? extends AbstractRespiratoryRateSample> respiratoryRateSamples,
List<SleepAnalysis.SleepSession> sleepSessions,
boolean supportsDayRespiratoryRate) {
this.day = day;
this.respiratoryRateSamples = respiratoryRateSamples;
this.sleepSessions = sleepSessions;
@ -103,7 +108,7 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
float highest = 0;
if (!this.respiratoryRateSamples.isEmpty()) {
for (AbstractRespiratoryRateSample sample : this.respiratoryRateSamples) {
if (isSleepSample(sample)) {
if (isSleepSample(sample, supportsDayRespiratoryRate)) {
sleepRateTotal += sample.getRespiratoryRate();
sleepCounter++;
} else {
@ -128,7 +133,11 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
this.rateHighest = (int) highest;
}
private boolean isSleepSample(AbstractRespiratoryRateSample sample) {
private boolean isSleepSample(AbstractRespiratoryRateSample sample, boolean supportsDayRespiratoryRate) {
if (!supportsDayRespiratoryRate) {
return true;
}
if (this.sleepSessions.isEmpty()) {
return true;
}

View File

@ -148,8 +148,9 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<Respi
@Override
protected void updateChartsnUIThread(RespiratoryRateData respiratoryRateData) {
respiratoryRateChart.setData(null);
sleepAvg.setText(String.valueOf(respiratoryRateData.sleepRateAvg));
awakeAvg.setText(String.valueOf(respiratoryRateData.awakeRateAvg));
final String emptyValue = requireContext().getString(R.string.stats_empty_value);
sleepAvg.setText(respiratoryRateData.sleepRateAvg > 0 ? String.valueOf(respiratoryRateData.sleepRateAvg) : emptyValue);
awakeAvg.setText(respiratoryRateData.awakeRateAvg > 0 ? String.valueOf(respiratoryRateData.awakeRateAvg) : emptyValue);
List<Entry> lineAwakeRateAvgEntries = new ArrayList<>();
List<Entry> lineSleepRateEntries = new ArrayList<>();

View File

@ -559,6 +559,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return false;
}
@Override
public boolean supportsDayRespiratoryRate() {
return false;
}
@Override
public boolean supportsSleepRespiratoryRate() {
return supportsRespiratoryRate();

View File

@ -271,6 +271,12 @@ public interface DeviceCoordinator {
*/
boolean supportsRespiratoryRate();
/**
* Indicates whether the device tracks respiratory rate during the day, will be false
* if only during the night.
*/
boolean supportsDayRespiratoryRate();
/**
* Returns true if sleep respiratory rate measurement and fetching is supported by
* the device (with this coordinator).

View File

@ -310,6 +310,11 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator {
return true;
}
@Override
public boolean supportsDayRespiratoryRate() {
return true;
}
@Override
public boolean supportsFindDevice() {
return true;