Active calories

Hi,

the watchface infoCal can show active calories. Active calories are not given directly in the activity.info class. It (the feature) is titled in the settings as experimental so the developer found probably a way to reverse calculate it from some other fields.

Any hints how? 

I tried to use active daily minutes to get a ratio of minutes gone on a day to that active daily minutes and apply this ratio to the calories. But it don't currently works. The reverse formula was:

active calories = calories * active daily minutes / minutes of the day

Today I have at 9:30 am 9 active calories yet, but active daily minutes is 0. But my step count is at 436. By observation the active daily minutes is obviously not the only factor for active calories.

Another formula try could be:

active calories = calories * active daily minutes / minutes of the day + step count / 50

What do you think?

  • I'm going to start using the first one as it seems closest to what Garmin use, so calculating the active calories as (total calories - resting calories) should also be closest.

    The 2nd & 3rd ones are "standard" BMR formulae, but don't quite match what Garmin shows. I'm guessing Garmin have their own data (maybe from a group of athletes/active people rather than average population?) and have calculated their own formula - but never published it anywhere.

  • The female version seems to turn out very similar. So these are the ones I'll use now to match Garmin:

    • Garmin 24 hour resting calories (male) = 5 - 6.12*age + 7.63*height + 12.2*weight
    • Garmin 24 hour resting calories (female) = -198 - 6.12*age + 7.63*height + 12.2*weight
    • Age in whole years, height in cm, weight in kg

    If I can calculate more accurate versions I'll update here Slight smile

  • Thanks for your work . This will help our apps and users of them out there. 

  • Increased the precision a bit more and these seem more accurate - fitting more of the data points I have (though still some +-1 as get towards midnight):

    • Garmin 24 hour resting calories (male) = 5.2 - 6.116*age + 7.628*height + 12.2*weight
    • Garmin 24 hour resting calories (female) = -197.6 - 6.116*age + 7.628*height + 12.2*weight
  • Thanks again, I would like to have your go to integrate that in my apps.

  • One can use following code to get the active calories:

    		var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);		
    	
    		var profile = UserProfile.getProfile();
    		var age    = today.year - profile.birthYear;
    		var weight = profile.weight / 1000.0;
    		
    
    		// female
    		restCalories = -197.6 - 6.116*age + 7.628*profile.height + 12.2*weight;
    		if (profile.gender == UserProfile.GENDER_MALE) {
    			restCalories = 5.2 - 6.116*age + 7.628*profile.height + 12.2*weight;
    		}
    		restCalories   = (today.hour*60+today.min) / 1440 * restCalories;
    		activeCalories = curCalories - restCalories;
    

  • Nice Slight smile

    The only thing I would recommend is to make sure that restCalories is rounded to the nearest integer - as that's how I calculated the constants to best fit the Garmin values. So any one of these:

    • activeCalories = curCalories - Math.round(restCalories)
    • activeCalories = curCalories - Math.floor(restCalories + 0.5)
    • activeCalories = curCalories - (restCalories + 0.5).toNumber()
  • OK, I rewrote the code a bit:

    		var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);		
    		var profile = UserProfile.getProfile();
    		var age    = today.year - profile.birthYear;
    		var weight = profile.weight / 1000.0;
    
    		if (profile.gender == UserProfile.GENDER_MALE) {
    			restCalories = 5.2 - 6.116*age + 7.628*profile.height + 12.2*weight;
    		} else {// female
    			restCalories = -197.6 - 6.116*age + 7.628*profile.height + 12.2*weight;
    		}
    		restCalories   = Math.round((today.hour*60+today.min) * restCalories / 1440 ).toNumber();
    		activeCalories = curCalories - restCalories;
    

    Hope this helps users to integrate it into their code.

  • Awesome work, and thank you both and !

    If there are no objections, I'd love to use this as a base for providing active calories in some of my watch faces.

  • Sure, the more that use it the better Slight smile

    Still hoping that Garmin will eventually release an official function at some point + for other values like body battery etc.