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:
parent
53ccae347d
commit
2e6552e3d5
@ -83,7 +83,7 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment<Respir
|
|||||||
if (stepsDayList.isEmpty()) {
|
if (stepsDayList.isEmpty()) {
|
||||||
LOG.error("Failed to get RespiratoryRateDay for {}", day);
|
LOG.error("Failed to get RespiratoryRateDay for {}", day);
|
||||||
List<? extends AbstractRespiratoryRateSample> s = new ArrayList<>();
|
List<? extends AbstractRespiratoryRateSample> s = new ArrayList<>();
|
||||||
RespiratoryRateDay = new RespiratoryRateDay(day, new ArrayList<>(), new ArrayList<>());
|
RespiratoryRateDay = new RespiratoryRateDay(day, new ArrayList<>(), new ArrayList<>(), true);
|
||||||
} else {
|
} else {
|
||||||
RespiratoryRateDay = stepsDayList.get(0);
|
RespiratoryRateDay = stepsDayList.get(0);
|
||||||
}
|
}
|
||||||
@ -92,10 +92,11 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment<Respir
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateChartsnUIThread(RespiratoryRateFragment.RespiratoryRateDay respiratoryRateDay) {
|
protected void updateChartsnUIThread(RespiratoryRateFragment.RespiratoryRateDay respiratoryRateDay) {
|
||||||
awakeAvg.setText(String.format(String.valueOf(respiratoryRateDay.awakeRateAvg)));
|
final String emptyValue = requireContext().getString(R.string.stats_empty_value);
|
||||||
sleepAvg.setText(String.valueOf(respiratoryRateDay.sleepRateAvg));
|
awakeAvg.setText(respiratoryRateDay.awakeRateAvg > 0 ? String.valueOf(respiratoryRateDay.awakeRateAvg) : emptyValue);
|
||||||
lowest.setText(String.valueOf(respiratoryRateDay.rateLowest));
|
sleepAvg.setText(respiratoryRateDay.sleepRateAvg > 0 ? String.valueOf(respiratoryRateDay.sleepRateAvg) : emptyValue);
|
||||||
highest.setText(String.valueOf(respiratoryRateDay.rateHighest));
|
lowest.setText(respiratoryRateDay.rateLowest > 0 ? String.valueOf(respiratoryRateDay.rateLowest) : emptyValue);
|
||||||
|
highest.setText(respiratoryRateDay.rateHighest > 0 ? String.valueOf(respiratoryRateDay.rateHighest) : emptyValue);
|
||||||
|
|
||||||
// Chart
|
// Chart
|
||||||
final List<LegendEntry> legendEntries = new ArrayList<>(1);
|
final List<LegendEntry> legendEntries = new ArrayList<>(1);
|
||||||
|
@ -18,7 +18,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.RespiratoryRateSample;
|
import nodomain.freeyourgadget.gadgetbridge.model.RespiratoryRateSample;
|
||||||
|
|
||||||
abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractChartFragment<T> {
|
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 CHART_TEXT_COLOR;
|
||||||
protected int 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 = (Calendar) day.clone(); // do not modify the caller's argument
|
||||||
day.add(Calendar.DATE, -TOTAL_DAYS + 1);
|
day.add(Calendar.DATE, -TOTAL_DAYS + 1);
|
||||||
|
|
||||||
|
final boolean supportsDayRespiratoryRate = device.getDeviceCoordinator().supportsDayRespiratoryRate();
|
||||||
|
|
||||||
List<RespiratoryRateDay> daysData = new ArrayList<>();;
|
List<RespiratoryRateDay> daysData = new ArrayList<>();;
|
||||||
for (int counter = 0; counter < TOTAL_DAYS; counter++) {
|
for (int counter = 0; counter < TOTAL_DAYS; counter++) {
|
||||||
int startTs;
|
int startTs;
|
||||||
@ -62,7 +64,7 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
|
|||||||
List<SleepAnalysis.SleepSession> sleepSessions = sleepAnalysis.calculateSleepSessions(activitySamples);
|
List<SleepAnalysis.SleepSession> sleepSessions = sleepAnalysis.calculateSleepSessions(activitySamples);
|
||||||
List<? extends AbstractRespiratoryRateSample> samples = getRespiratoryRateSamples(db, device, startTs, endTs);
|
List<? extends AbstractRespiratoryRateSample> samples = getRespiratoryRateSamples(db, device, startTs, endTs);
|
||||||
Calendar d = (Calendar) day.clone();
|
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);
|
day.add(Calendar.DATE, 1);
|
||||||
}
|
}
|
||||||
return daysData;
|
return daysData;
|
||||||
@ -91,7 +93,10 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
|
|||||||
List<? extends AbstractRespiratoryRateSample> respiratoryRateSamples;
|
List<? extends AbstractRespiratoryRateSample> respiratoryRateSamples;
|
||||||
List<SleepAnalysis.SleepSession> sleepSessions;
|
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.day = day;
|
||||||
this.respiratoryRateSamples = respiratoryRateSamples;
|
this.respiratoryRateSamples = respiratoryRateSamples;
|
||||||
this.sleepSessions = sleepSessions;
|
this.sleepSessions = sleepSessions;
|
||||||
@ -103,7 +108,7 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
|
|||||||
float highest = 0;
|
float highest = 0;
|
||||||
if (!this.respiratoryRateSamples.isEmpty()) {
|
if (!this.respiratoryRateSamples.isEmpty()) {
|
||||||
for (AbstractRespiratoryRateSample sample : this.respiratoryRateSamples) {
|
for (AbstractRespiratoryRateSample sample : this.respiratoryRateSamples) {
|
||||||
if (isSleepSample(sample)) {
|
if (isSleepSample(sample, supportsDayRespiratoryRate)) {
|
||||||
sleepRateTotal += sample.getRespiratoryRate();
|
sleepRateTotal += sample.getRespiratoryRate();
|
||||||
sleepCounter++;
|
sleepCounter++;
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +133,11 @@ abstract class RespiratoryRateFragment<T extends ChartsData> extends AbstractCha
|
|||||||
this.rateHighest = (int) highest;
|
this.rateHighest = (int) highest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSleepSample(AbstractRespiratoryRateSample sample) {
|
private boolean isSleepSample(AbstractRespiratoryRateSample sample, boolean supportsDayRespiratoryRate) {
|
||||||
|
if (!supportsDayRespiratoryRate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.sleepSessions.isEmpty()) {
|
if (this.sleepSessions.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -148,8 +148,9 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<Respi
|
|||||||
@Override
|
@Override
|
||||||
protected void updateChartsnUIThread(RespiratoryRateData respiratoryRateData) {
|
protected void updateChartsnUIThread(RespiratoryRateData respiratoryRateData) {
|
||||||
respiratoryRateChart.setData(null);
|
respiratoryRateChart.setData(null);
|
||||||
sleepAvg.setText(String.valueOf(respiratoryRateData.sleepRateAvg));
|
final String emptyValue = requireContext().getString(R.string.stats_empty_value);
|
||||||
awakeAvg.setText(String.valueOf(respiratoryRateData.awakeRateAvg));
|
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> lineAwakeRateAvgEntries = new ArrayList<>();
|
||||||
List<Entry> lineSleepRateEntries = new ArrayList<>();
|
List<Entry> lineSleepRateEntries = new ArrayList<>();
|
||||||
|
@ -559,6 +559,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsDayRespiratoryRate() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsSleepRespiratoryRate() {
|
public boolean supportsSleepRespiratoryRate() {
|
||||||
return supportsRespiratoryRate();
|
return supportsRespiratoryRate();
|
||||||
|
@ -271,6 +271,12 @@ public interface DeviceCoordinator {
|
|||||||
*/
|
*/
|
||||||
boolean supportsRespiratoryRate();
|
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
|
* Returns true if sleep respiratory rate measurement and fetching is supported by
|
||||||
* the device (with this coordinator).
|
* the device (with this coordinator).
|
||||||
|
@ -310,6 +310,11 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsDayRespiratoryRate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsFindDevice() {
|
public boolean supportsFindDevice() {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user