Method of calculating the step goal streak (because I don’t think we can access that on a watchface)

When I hit my steps goal for the day my Venu (and VA3 before that) shows a nifty little animation showing the count of days -“43” or whatever days my step goal streak is at.

(actually today it was “6” but I have seen higher numbers in the past when I had extended streaks)

HOWEVER it seems like this value  is not available for apps/watch faces to accces. -  I would love to be wrong here which would make the rest of this post irrelevant!)  

I would really like to have that number displayed on a watchface that I have started coding and thought I would share an outline of the method I have come up with and see if anyone has any comments.

My understanding is that

A)  Watchfaces can “see” todays steps vs goals and the history for the previous 7 days.

B)Watchfaces can store values in persistent storage

Method

  1. Look at available history if there is a day where goal has not been met then the day after (the most recent missed day)  becomes the start of a streak.
  2. If there is no missed goals in the last 7 days then assume the streak started 7 days ago.
  3. Store this value of the date in persistent memory.
  4. Now that there is a value there - use this date - UNTIL we detect a day where the goal is missed - (between yesterday and 7 days ago) if that happens reset the stored value.
  5. Display the number of days as a calculated value (Stored value - yesterday) (+ 1 if we have met goal ‘today”)

The weekness I can see with this is if this watchface is turned off,  you miss your goal (and more than 8 days later) the watchface is turned back on then the watchface would not see that miss as it would be aged out of history while it was disabled.

One possible enhancement would be a setting for start date could be passed to populate the persistent storage once - and then the watchface could remove that setting and revert to the method above.  That way if you started using this on day 43 of your streak you could make that happen.

Another possible enhancement would be to only run this calculation occasionally so that we don’t repeatedly check these things.

I’m starting to code the above-  wondering if anyone has tried anything similar?

Thanks to those who have shared source code etc - Im getting close to a watchface that does exactly what I want it to which is exciting.

  • It might be worthwhile to look at Background.registerForGoalEvennt(Application.GOAL_TYPE_STEPS) and AppBase.getGoalView() so that you know when the steps goal has been triggered.

    If you use these functions, the system would call AppBase.getGoalView() if your watch face is currently running and the goal is reached. If the user is running another application, the ServiceDelegate.onGoalReached() method will get called as soon as the system is able to. You won't necessarily get called when the goal is reached, but you could use the steps and stepsGoal values to determine if the step goal was reached today or yesterday.

  • Thanks.   Given that I’m displaying steps va goal for today I know whether the goal is met for today (not exactly when it happened but whether it has happened   ).   

  • I think Travis's way is the way to go, and I can think of a couple things to consider.

    1) you could hit the step goal twice in the same day.  Let's say you start with a goal of 5000, hit it, then you change to 7500 and hit that later in the day.

    2) resetting the running count - you missed your goal.  The time to detect that is the flowing day.  Let's say it's Thursday - you want to reset if you missed the goal on Wednesday.

    Both these can be handled with a timestamp for when you last hit your goal.  So in addition to a running count, you'll want that timestamp saved in persistent storage

    Using the background, you may want to generate the timestamp there, so you know when the goal was actually hit, and not when it was seen in onBackgroundData in the main app.

  • Thanks - this is helping me think this through.

    I'm thinking of storing and looking for any (most recent)  date where the day goal was NOT hit and calculating from there.
    I can only do this for Yesterday and prior because  a goal is not missed until the day is over  -
    (Todays goal can be made - but cannot be missed until midnight and today becomes yesterday.)

    if I didn't make the goal yesterday the streak is reset to 0. 
    (If there are any days in ActivityMonitor.getHistory[0-6].steps <  stepgoal then that date becomes the missed date)

    Jan 1 -  Missed (lazy - hungover!)
    Jan 2 - Made Goal
    Jan 3 - Made Goal 
    Made goal every day through the end of the month......
    Jan 31 Made goal at 4pm 

    So on Jan 31 at 3pm  I have a stored "last miss" date of Jan 1 -  that is 29 complete days where I have made my goal (exclude the stored date itself and dont count today because I have not made today's goal yet.)

    At 4:01pm after  I make my goal  (ActivityMonitor.getInfo().steps > ActivityMonitor.getInfo().stepGoal)
    I just display 29+1 (30) because I'm adding today to the displayed value.  No change to the stored value - the streak started after the same Missed day on Jan 1st.

    From 1st Feb morning -  the same calculation applies-  I have not made today goal but that stored "1st Jan" has slid back one further day into the past so Streak =30 at the start of the day.

    I'm getting this coded up - Ill try it as a beta application and see if it seems to work.

    Thanks 

    [edit for clarity - hopefully]