Skip to content

Conversation

@pvannierop
Copy link
Contributor

Problem

On the CONNECT project we experienced problems with retrieval of Fitbit resting heart rate (RHR) data. The Fitbit connector would every day download the same RHR datum that lies far in the past.

Analysis

As far as I can see there is a problem with determining the date of the next RHR datum. RHR is queried at the resolution of a single day:

    return baseUrl + "/1/user/%s/activities/heart/date/%s/1d.json?timezone=UTC";

The existing logic will take the date of the last successful RHR datum, add one second, round this to days and use the resulting day to query the next RHR datum:

    ZonedDateTime startDate = this.getOffset(user).plus(ONE_SECOND)
        .atZone(UTC)
        .truncatedTo(SECONDS);
    return Stream.of(newRequest(user, new DateRange(startDate, ZonedDateTime.now(UTC)),
        user.getExternalUserId(), DATE_FORMAT.format(startDate)));

This will effectively result in the same day being queried over and over since this will always resolve to the same day offset of the last successfull datum.

Solution

This PR will correct the offset for the next datum by progressing the startDate with one day instead of one second.

@pvannierop pvannierop self-assigned this Dec 9, 2025
Copy link
Member

@yatharthranjan yatharthranjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice sleuthing. I completely overlooked this in the previous fix. Thank you!

Just a minor comment on changing the base branch to dev

Copy link
Member

@mpgxvii mpgxvii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pvannierop, LGTM. Sorry I missed your Slack message but yes we did run into a similar issue with Oura because the data is pulled at daily intervals as well, and we were only adding a very small offset after every successful request. It was updated here: #147. (and later refined to use a 12-hour overlap but one day works for this Fitbit RHR case)

@pvannierop pvannierop force-pushed the fix/resting-heart-rate-offset branch from 4044640 to 2432bb3 Compare December 11, 2025 08:57
@pvannierop pvannierop changed the base branch from master to dev December 11, 2025 08:57
@pvannierop pvannierop force-pushed the fix/resting-heart-rate-offset branch from 2432bb3 to 342519d Compare December 11, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants