From 600629e7ed15f63a05164a5fa348e7173675cf3a Mon Sep 17 00:00:00 2001 From: "Martin.JM" Date: Sun, 8 Dec 2024 11:09:41 +0100 Subject: [PATCH] Switch from kcal to cal in samples This allows for higher precision in devices that support it. --- .../gadgetbridge/daogen/GBDaoGenerator.java | 2 +- .../activities/charts/CaloriesDailyFragment.java | 2 ++ .../devices/garmin/GarminActivitySampleProvider.java | 10 ++++++++++ .../gadgetbridge/model/ActivitySample.java | 2 +- .../gadgetbridge/util/DashboardUtils.java | 3 ++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 18cb1641c..66af8f3ae 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -1363,7 +1363,7 @@ public class GBDaoGenerator { activitySample.addIntProperty("calories").notNull().codeBeforeGetter( "@Override\n" + " public int getActiveCalories() {\n" + - " return getCalories() == HuaweiActivitySample.NOT_MEASURED ? HuaweiActivitySample.NOT_MEASURED : Math.round(getCalories() / 1000f);\n" + + " return getCalories();\n" + " }\n" ); activitySample.addIntProperty("distance").notNull().codeBeforeGetter( diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CaloriesDailyFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CaloriesDailyFragment.java index 097abaa10..3184d4038 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CaloriesDailyFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CaloriesDailyFragment.java @@ -172,6 +172,8 @@ public class CaloriesDailyFragment extends AbstractChartFragment samples) { + for (GarminActivitySample sample : samples) { + sample.setActiveCalories(sample.getActiveCalories() * 1000); + } + } + public void overlaySleep(final List samples, final int timestamp_from, final int timestamp_to) { // The samples provided by Garmin are upper-bound timestamps of the sleep stage final RangeMap stagesMap = new RangeMap<>(RangeMap.Mode.UPPER_BOUND); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java index b5c6d76dd..df8e94e71 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java @@ -78,7 +78,7 @@ public interface ActivitySample extends TimeStamped { int getDistanceCm(); /** - * Returns the calories burned during the period of this sample, in kcal. -1 if unknown. + * Returns the calories burned during the period of this sample, in calories. -1 if unknown. */ int getActiveCalories(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DashboardUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DashboardUtils.java index 89d7617da..650712ee4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DashboardUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DashboardUtils.java @@ -75,7 +75,8 @@ public class DashboardUtils { } catch (Exception e) { LOG.warn("Could not calculate total amount of active calories: ", e); } - return totalActiveCalories; + // Convert calories to kcal + return totalActiveCalories / 1000; } public static int getRestingCaloriesTotal(DashboardFragment.DashboardData dashboardData) {