mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Dashboard: Do not sum resting calories across devices
In theory, all devices should report the same amount of resting calories. Since that will likely not be the case, and it also does not make sense to sum them, average the resting calories across all devices that provide them.
This commit is contained in:
@@ -82,16 +82,24 @@ public class DashboardUtils {
|
||||
public static int getRestingCaloriesTotal(DashboardFragment.DashboardData dashboardData) {
|
||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
|
||||
int totalRestingCalories = 0;
|
||||
int totalRestingCaloriesDevices = 0;
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
for (GBDevice dev : devices) {
|
||||
if ((dashboardData.showAllDevices || dashboardData.showDeviceList.contains(dev.getAddress())) && dev.getDeviceCoordinator().supportsActiveCalories()) {
|
||||
totalRestingCalories += (int) getDailyTotals(dev, dbHandler, dashboardData.timeTo).getRestingCalories();
|
||||
final int restingCalories = (int) getDailyTotals(dev, dbHandler, dashboardData.timeTo).getRestingCalories();
|
||||
if (restingCalories > 0) {
|
||||
totalRestingCalories += restingCalories;
|
||||
totalRestingCaloriesDevices++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Could not calculate total amount of resting calories: ", e);
|
||||
}
|
||||
return totalRestingCalories;
|
||||
if (totalRestingCaloriesDevices == 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.round(totalRestingCalories / (float) totalRestingCaloriesDevices);
|
||||
}
|
||||
|
||||
public static float getStepsGoalFactor(DashboardFragment.DashboardData dashboardData) {
|
||||
|
||||
Reference in New Issue
Block a user