Skip to content

Calculating average steps through health_service_sum_averaged returns 0, while in old app returns average steps #220

@PingPongLee

Description

@PingPongLee

I have a watchface, that shows if current steps are over or below an average. The average is calculated like below:

#if defined(PBL_HEALTH)
static void health_handler(HealthEventType event, void *context) {
	HealthServiceTimeScope scope = HealthServiceTimeScopeDailyWeekdayOrWeekend;
	HealthMetric metric = HealthMetricStepCount;
	time_t start = time_start_of_today();
	time_t end = time(NULL);
	HealthServiceAccessibilityMask mask = health_service_metric_accessible(metric, start, end);
	HealthServiceAccessibilityMask mask_avg = health_service_metric_averaged_accessible(metric, start, end, scope);
	if (mask & HealthServiceAccessibilityMaskAvailable) {
		// Data is available!
		HealthValue today = health_service_sum_today(metric);
		HealthValue average = (HealthValue)0;
		if (mask_avg & HealthServiceAccessibilityMaskAvailable) {
			// Average is available, read it
			average = health_service_sum_averaged(metric, start, end, scope);
		}
		APP_LOG(APP_LOG_LEVEL_INFO, "average = %d", (int)average);
		if (mask_avg & HealthServiceAccessibilityMaskAvailable) {
			if ((int)today > (int) average) health_higher_lower_than_avg =  1;
			if ((int)today < (int) average) health_higher_lower_than_avg = -1;
		}
	}
}
#endif

In the new Pebble app this returns 0, while the same code returns an average (e.g. 1872), on the old app, which in turn messes up the watchface's ability to show if you are above or below the average step count.

I've tested this on two Pebble Time Steel watches, where one ran on the old app and the other ran on the new app and the issue seems to follow the new app

I dont know if it has anything to do with this, but it is worth noting that on the health screen of the pebble watch it self, the yellow "typical" box is empty for the watch running through the new app, while having steps shown for the watch running on the old app. To test this i have been using both watches for more than a week to ensure they would have something to fill in.

Also both watches run the firmware: v4.4.3-rbl

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions