1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Standardize and hide fake sleep movement intensity

This commit is contained in:
José Rebelo 2024-09-27 20:32:47 +01:00
parent 8ae8898a89
commit 05c707bdfb
6 changed files with 43 additions and 41 deletions

View File

@ -210,7 +210,34 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
ActivitySample sample = samples.get(i);
ActivityKind type = sample.getKind();
int ts = tsTranslation.shorten(sample.getTimestamp());
float value = type != ActivityKind.NOT_WORN ? sample.getIntensity() : Y_VALUE_DEEP_SLEEP;
final float value;
if (type != ActivityKind.NOT_WORN) {
if (ActivityKind.isSleep(type) && sample.getIntensity() <= 0) {
switch (type) {
case SLEEP_ANY:
case AWAKE_SLEEP:
value = 0.50f;
break;
case DEEP_SLEEP:
value = 0.20f;
break;
case LIGHT_SLEEP:
value = 0.30f;
break;
case REM_SLEEP:
value = 0.40f;
break;
default:
value = Y_VALUE_DEEP_SLEEP;
break;
}
} else {
value = sample.getIntensity();
}
} else {
value = Y_VALUE_DEEP_SLEEP;
}
// do not interpolate NOT_WORN on any side
boolean interpolate = !(last_type == ActivityKind.NOT_WORN || type == ActivityKind.NOT_WORN);
float interpolation_value = interpolate ? value : last_value;

View File

@ -75,6 +75,8 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
private TextView lowestHrText;
private TextView highestHrText;
private TextView movementIntensityText;
private LinearLayout movementIntensityTextWrapper;
private LinearLayout dummyTile;
private TextView sleepDateText;
private int heartRateMin = 0;
private int heartRateMax = 0;
@ -254,7 +256,9 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
intensityTotal = mcd.getIntensityTotal();
lowestHrText.setText(String.valueOf(heartRateMin != 0 ? heartRateMin : "-"));
highestHrText.setText(String.valueOf(heartRateMax != 0 ? heartRateMax : "-"));
movementIntensityText.setText(intensityTotal != 0 ? new DecimalFormat("###.#").format(intensityTotal) : "-");
movementIntensityText.setText(intensityTotal > 0 ? new DecimalFormat("###.#").format(intensityTotal) : "-");
movementIntensityTextWrapper.setVisibility(intensityTotal > 0 ? View.VISIBLE : View.GONE);
dummyTile.setVisibility(intensityTotal > 0 ? View.VISIBLE : View.GONE);
mSleepAmountChart.setHoleRadius(85);
mSleepAmountChart.setDrawEntryLabels(false);
@ -385,6 +389,8 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
lowestHrText = rootView.findViewById(R.id.sleep_hr_lowest);
highestHrText = rootView.findViewById(R.id.sleep_hr_highest);
movementIntensityText = rootView.findViewById(R.id.sleep_movement_intensity);
movementIntensityTextWrapper = rootView.findViewById(R.id.sleep_chart_legend_movement_intensity_wrapper);
dummyTile = rootView.findViewById(R.id.sleep_chart_legend_dummy_tile);
sleepDateText = rootView.findViewById(R.id.sleep_date);
mSleepchartInfo.setMaxLines(sleepLinesLimit);

View File

@ -40,6 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.CmfSleepStageSample;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
public class CmfActivitySampleProvider extends AbstractSampleProvider<CmfActivitySample> {
private static final Logger LOG = LoggerFactory.getLogger(CmfActivitySampleProvider.class);
@ -166,18 +167,7 @@ public class CmfActivitySampleProvider extends AbstractSampleProvider<CmfActivit
final ActivityKind sleepRawKind = sleepStageToActivityKind(sleepStageSample.getStage());
sample.setRawKind(sleepRawKind.getCode());
switch (sleepRawKind) {
case DEEP_SLEEP:
sample.setRawIntensity(20);
break;
case LIGHT_SLEEP:
sample.setRawIntensity(30);
break;
case REM_SLEEP:
sample.setRawIntensity(40);
break;
}
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
}
}
}

View File

@ -34,6 +34,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.GarminEventSample;
import nodomain.freeyourgadget.gadgetbridge.entities.GarminSleepStageSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.fieldDefinitions.FieldDefinitionSleepStage;
import nodomain.freeyourgadget.gadgetbridge.util.RangeMap;
@ -177,21 +178,7 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider<GarminA
final ActivityKind sleepType = stagesMap.get(ts);
if (sleepType != null && !sleepType.equals(ActivityKind.UNKNOWN)) {
sample.setRawKind(sleepType.getCode());
switch (sleepType) {
case AWAKE_SLEEP:
sample.setRawIntensity(50);
break;
case DEEP_SLEEP:
sample.setRawIntensity(20);
break;
case LIGHT_SLEEP:
sample.setRawIntensity(30);
break;
case REM_SLEEP:
sample.setRawIntensity(40);
break;
}
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
}
}
}

View File

@ -34,6 +34,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiSleepStageSample;
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiSleepTimeSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.RangeMap;
public class XiaomiSampleProvider extends AbstractSampleProvider<XiaomiActivitySample> {
@ -191,18 +192,7 @@ public class XiaomiSampleProvider extends AbstractSampleProvider<XiaomiActivityS
final ActivityKind sleepType = stagesMap.get(ts);
if (sleepType != null && !sleepType.equals(ActivityKind.UNKNOWN)) {
sample.setRawKind(sleepType.getCode());
switch (sleepType) {
case DEEP_SLEEP:
sample.setRawIntensity(20);
break;
case LIGHT_SLEEP:
sample.setRawIntensity(30);
break;
case REM_SLEEP:
sample.setRawIntensity(40);
break;
}
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
}
}
}

View File

@ -214,6 +214,7 @@
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/sleep_chart_legend_movement_intensity_wrapper"
android:layout_marginBottom="2dp"
android:layout_marginEnd="1dp"
style="@style/GridTile"
@ -233,6 +234,7 @@
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/sleep_chart_legend_dummy_tile"
android:layout_marginBottom="2dp"
android:layout_marginStart="1dp"
style="@style/GridTile"