brainstorming: how to deal with low HR alert at the beginning of activity

I'd like to add low/high HR alert to my datafield. I have it working, except that it alerts when the activity starts because the HR is still low. For example the user set that he wants to run in zones 2-3, and obviously at the beginning he's not even in zone 1.

I'm looking for an idea how to deal with it - maybe more from the user's point of view.

The only idea I could come up with was to not to fire low HR alert until 1 minute after the beginning of the activity (onTimerStart() for sure, but maybe also onTimerResume()?)

Do you have any better idea?
  • this feature is built in watch (in f6p anyway), so there is no sense to duplicate and waste bytes 

  • Alerts are independent of DF rather on type activity but usually hr, time is always.

  • Another approach would be to only fire the low HR alert if the HR has already been observed to be above the low HR threshold. In other words, you're no longer alerting the user that the HR is simply below the low threshold, you're alerting them that the HR has crossed the low threshold (on the way down.)

    That may not be what your users want, though.

  • Ah, how stupid am I! Thanks! The thing is that I already do this: only alert when it crosses the threshold: was higher and became lower. The only "bug" I had was the initial value of the mLastHr. Because first I only implemented High HR alert I started it with 0, which worked in case of high alert. The problem is that any time I start the DF it immediately starts with a low alert. But now that I saw what you suggested I understood, that simply I need to either have a separate variable used for the same functionality but in the context of the low HR alert it would start from 255 instead of 0 and it'll fix the issue. Or I could have a boolean to indicate that I already reached the interval that's between the low and high threshold (though this is more complicated since the user can set only low, only high or both alerts)

    But your last sentence is also true: it's a nice feature to get an alert after enough time even when I did not reach the min HR, like the built-in algorithm does.

  • The only "bug" I had was the initial value of the mLastHr.
    I need to either have a separate variable used for the same functionality but in the context of the low HR alert it would start from 255 instead of 0 and it'll fix the issue. Or I could have a boolean to indicate that I already reached the interval that's between the low and high threshold (though this is more complicated since the user can set only low, only high or both alerts)

    Wouldn't the following code also work, without any of those changes?

    var currentHr = ...;

    if (mLastHr >= lowThreshold && currentHr < lowThreshold) {
        // low alert
    }

    if (mLastHr <= highThreshold && currentHr > highThreshold) {
        // high alert
    }

    mLastHr = currentHr;

    If that isn't sufficient for some reason, you could initialize mLastHr to null, but then that makes your logic slightly more complicated.

  • I came up with something that is slightly more complex but it also alerts after 5 minutes if you haven't reach the lowThreshold and I also tried to optimize it for memory (thus I hold timestamp as Number and not as Moment) but also ordered the expressions in the if in such a way that the minimum amount of them should be executed:

        function alertHr(heartRate) {
            var alertHighHR = mAlertHighHeartRate;
            var alertLowHR = mAlertLowHeartRate;
            var activityStartedAt = mActivityStartedAtTimestamp; // need to set in onTimerStart() and maybe in onTimerResume()
            var lastHeartRate = mLastHeartRate;
            if ((alertHighHR != null && alertHighHR <= heartRate && lastHeartRate < alertHighHR)
                || (alertLowHR != null && activityStartedAt != null && alertLowHR > heartRate && lastHeartRate >= alertLowHR
                    && (activityStartedAt == LOW_HR_ALERT_ENABLED || activityStartedAt + LOW_HR_ALERT_DELAY_SEC < Time.now().value()))) {
                alert();
                mActivityStartedAtTimestamp = LOW_HR_ALERT_ENABLED;
            }
            mLastHeartRate = heartRate;
        }
    

  • I think you're missing the fact that this is for his CIQ data field app which connects directly to an ANT+ HR monitor, so he can't use the built-in alerts. (The point of the app is to allow the user to connect to 2 HR monitors - one natively and one through the app.)