1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

Garmin: add heart rate zones support

This commit is contained in:
a0z 2024-09-30 21:02:08 +02:00 committed by José Rebelo
parent 3e327e2924
commit 2a3d2f08e2
4 changed files with 23 additions and 10 deletions

View File

@ -10,11 +10,13 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
@ -194,14 +196,19 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
for (final FitTimeInZone fitTimeInZone : timesInZone) {
// Find the first time in zone for the session (assumes single-session)
if (fitTimeInZone.getReferenceMessage() != null && fitTimeInZone.getReferenceMessage() == 18) {
final Double[] timeInZone = fitTimeInZone.getTimeInZone();
if (timeInZone != null && timeInZone.length == 6) {
summaryData.add(HR_ZONE_NA, timeInZone[0].floatValue(), UNIT_SECONDS);
summaryData.add(HR_ZONE_WARM_UP, timeInZone[1].floatValue(), UNIT_SECONDS);
summaryData.add(HR_ZONE_FAT_BURN, timeInZone[2].floatValue(), UNIT_SECONDS);
summaryData.add(HR_ZONE_AEROBIC, timeInZone[3].floatValue(), UNIT_SECONDS);
summaryData.add(HR_ZONE_ANAEROBIC, timeInZone[4].floatValue(), UNIT_SECONDS);
summaryData.add(HR_ZONE_EXTREME, timeInZone[5].floatValue(), UNIT_SECONDS);
final Double[] timeInZones = fitTimeInZone.getTimeInZone();
final double totalTime = Arrays.stream(timeInZones).mapToInt(Double::intValue).sum();
final List<String> zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_EASY, HR_ZONE_AEROBIC, HR_ZONE_THRESHOLD, HR_ZONE_MAXIMUM);
for (int i = 1; i < zoneOrder.size(); i++) {
double timeInZone = timeInZones[i] != null ? Math.rint(timeInZones[i]) : 0;
summaryData.add(
zoneOrder.get(i),
new ActivitySummaryProgressEntry(
timeInZone,
UNIT_SECONDS,
(int) (100 * timeInZone / totalTime)
)
);
}
break;
}

View File

@ -69,10 +69,13 @@ public class ActivitySummaryEntries {
public static final String HR_MIN = "minHR";
public static final String HR_ZONE_NA = "hrZoneNa";
public static final String HR_ZONE_WARM_UP = "hrZoneWarmUp";
public static final String HR_ZONE_EASY = "hrZoneEasy";
public static final String HR_ZONE_FAT_BURN = "hrZoneFatBurn";
public static final String HR_ZONE_AEROBIC = "hrZoneAerobic";
public static final String HR_ZONE_ANAEROBIC = "hrZoneAnaerobic";
public static final String HR_ZONE_THRESHOLD = "hrZoneThreshold";
public static final String HR_ZONE_EXTREME = "hrZoneExtreme";
public static final String HR_ZONE_MAXIMUM = "hrZoneMaximum";
public static final String LANE_LENGTH = "laneLength";
public static final String LAPS = "laps";

View File

@ -177,8 +177,8 @@ public class ActivitySummaryJsonSummary {
DESCENT_DISTANCE, FLAT_DISTANCE, ELEVATION_GAIN, ELEVATION_LOSS
));
put(GROUP_HEART_RATE_ZONES, Arrays.asList(
HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC,
HR_ZONE_EXTREME
HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_EASY, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC,
HR_ZONE_THRESHOLD, HR_ZONE_EXTREME, HR_ZONE_MAXIMUM
));
put(GROUP_STROKES, Arrays.asList(
STROKE_DISTANCE_AVG, STROKE_AVG_PER_SECOND, STROKES,

View File

@ -2173,9 +2173,12 @@
<string name="hrZoneNa">N/A</string>
<string name="hrZoneWarmUp">Warm-Up</string>
<string name="hrZoneFatBurn">Fat Burn</string>
<string name="hrZoneEasy">Easy</string>
<string name="hrZoneAerobic">Aerobic</string>
<string name="hrZoneAnaerobic">Anaerobic</string>
<string name="hrZoneThreshold">Threshold</string>
<string name="hrZoneExtreme">Extreme</string>
<string name="hrZoneMaximum">Maximum</string>
<string name="TrainingEffect">Training Effect</string>
<string name="aerobicTrainingEffect">Aerobic Effect</string>
<string name="anaerobicTrainingEffect">Anaerobic Effect</string>