Reading min and max HR from a watch face

Hi gents,

I'm currently trying to retrieve the max/min HR for the last 24 hrs. I used this forum and the CIQ documentation to write the following:

function findMaxMinHR( dc ) {

var hrMaxValue = 0;
var hrMinValue = 255;

if( ActivityMonitor has :HeartRateIterator ) {

var oneDay = new Time.Duration(86400);
var sensorIter = ActivityMonitor.getHeartRateHistory( oneDay, true );

if( sensorIter != null ) {

hrMinValue = sensorIter.getMin();
hrMaxValue = sensorIter.getMax();

...



I'm currently testing this on a Fenix 5x plus and the results are not the same as the ones that can be found in the connect iq iphone app. Both Min and Max are lower? Also, after removing the watch for a few hours to sleep, both values were set to 255 ( yes, 255 -> invalid). I was expecting that I would be seeing at least the max value from the night before (from a run).

Am I doing it wrong or just missing something?

Any pointers would be appreciated.
  • History period is limited for certain period of time, and it’s different for different devices.
    Make iteration of full history length not through “data” but though “when” and compare first “when” with last one,
    to get maximum history time period, available for your device in seconds. (Use sample from API documentation).
  • Last time I spent time looking at this, it seemed common that the max range of getHeartRateHistory was about 4 hours, and the number of samples was actually based on the width of the display, so the time between samples varied based on that. Why width of the display? Because this data is used for the standard HR widget, and at 1 pixel/reading, that's all the data it could use, and it could be less than the actual width on round/semi-round displays. If I recall, with a vahr, it was 148 samples, each 94 seconds apart (at least last I checked) for example.

    So given that, you can build 24hrs worth of data.

    When it comes to max/min it gets a bit interesting, as you have to trim off data >24hrs old (which may include the min or max, but may not be the only data with that min or max), so you pretty much have to scan all the data looking for the current min/max when data gets trimmed.

    The other thing, is the watch face won't always be running (swipe to a widget, record an activity, etc), so you also want to save off the 24hrs of data in Application.Storage, so you don't just start with 4hrs of data when you swipe to a widget and come back...

    And with the readings being 1-2 minutes apart, it may have missed the actual min/max for the user.

    What may be easier is to think "today's min/max". Reset at midnight, then just maintain the min/max throughout the day, either by way of getHeartRateHistory, or Activity.Info.currentHeartRate. When the watch face is running, you could actually check Activity.Info every second in onPartialUpdate and minimize the chance of missing a high/low during the 1-2 minute gap in history
  • Hi all,

    Thank you both for taking the time to answer my question.

    For my current design, I think 4 hrs would be enough. I'm currently looking to support only 240x240 devices for this one and I was hoping that the I could use the getMin/getMax methods to retrieve the same values as the ones displayed in the HR widget. This will avoid a lot of emails questioning about that difference. I can explain the difference in the watch face description but most users are not reading it...

    I tried with both using the width ( dc.getWidth() ) and using a time duration of 4 hours ( Time.Duration(14400); ) but with no luck.

    Does someone know how to retrieve the same values as the HR Widget?
  • Try something like
    //use defaults
    getHeartRateHistory({});
    //or
    getHeartRateHistory ({:period=>width,:order=>true});