Skip to content

intraday_time_series does not correctly retrieve the data #137

Description

@sefyas

We want to obtain intraday step data and what we get is different from Fitbit dashboard. We have cases where we see zero steps for a particular date but the dashboard shows +3K steps. Or, dates where the total number of steps is different from what we see in dashboard.

This code illustrates the main steps of obtaining intra-day data and processing it (e.g. obtaining the daily counts)

# user_id, client_secret, _access_token_, _refresh_token_, start_date, and end_date are passed in as input

fitbit_auth = Fitbit(
                user_id, 
                client_secret,
                oauth2=True,
                access_token=_access_token_],
                refresh_token=_refresh_token_])

current_date = start_date;
date_increment = datetime.timedelta(days=1)
while(current_date < end_date):
   
   current_date_str = current_date.strftime("%Y-%m-%d")
   
   data = fitbit_auth.intraday_time_series(
                      'activities/steps',
                      base_date = current_date_str,
                      detail_level = '1min',
                      start_time   = '0:00',
                      end_time     = '23:59')
   
   daily_steps = 0;

   data = data['activities-steps-intraday']['dataset']
   for item in data:
       daily_steps += item['value’]  
       # other processing …

   print(f’{daily_steps} steps on {current_date_str}’)
   
   current_date += date_increment

The differences between the data we get and Fitbit dashboard do not seem to follow any pattern and appear in between dates where there is a complete match. So, I don’t think there is an issue with our calls given what we retrieve matches the dashboard some of the time; it can be an issue on the Fitbit side. Any thoughts / comment are much appreciated.

Activity

  1. changed the title [-]intraday_time_series does not currently retrieve the data[/-] [+]intraday_time_series does not correctly retrieve the data[/+] on Jun 20, 2018
  2. justin-f-perez commented on Oct 5, 2018

    @justin-f-perez

    @sefyas This is a problem on Fitbit's side. You can prove this to yourself by using a program like Postman to make the API request directly for a date where the values don't match the dashboard, then compare the daily summary to the sum of the intraday values. Fitbit admits (somewhere on their forums a few years ago) the following conditions can cause a disparity between intraday values and daily summaries:

    • User didn't sync for more than 7 days
    • User's battery got too low
    • User's timezone changed
    • Firmware update occurred

    In my experience, even a user with a charged battery that sync everyday and doesn't change timezones or update firmware can still experience this problem.

  3. HawkingsRainbow commented on Oct 30, 2018

    @HawkingsRainbow

    I wonder if there has been any update on this issue?

    I'm unable to retrieve any intraday heartrate values, using the following code:
    (Based on the great Medium tutorial by Stephen Hsu at https://towardsdatascience.com/collect-your-own-fitbit-data-with-python-ff145fa10873)

    import fitbit
    import gather_keys_oauth2 as Oauth2
    import pandas as pd 
    import datetime
    CLIENT_ID = '***'
    CLIENT_SECRET = '***'
    
    server = Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET)
    server.browser_authorize()
    ACCESS_TOKEN = str(server.fitbit.client.session.token['access_token'])
    REFRESH_TOKEN = str(server.fitbit.client.session.token['refresh_token'])
    auth2_client = fitbit.Fitbit(CLIENT_ID, CLIENT_SECRET, oauth2=True, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
    

    [Browser-based authorization]

    yesterday = str((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y%m%d"))
    yesterday2 = str((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d"))
    today = str(datetime.datetime.now().strftime("%Y%m%d"))
    
    fit_statsHR = auth2_client.intraday_time_series('activities/heart', base_date=yesterday2, detail_level='1sec')
    

    fit_statsHR contains only an 'activities-heart-rate' key. 'activities-heart-intraday' seems to be missing.

    The complete contents of fit_statsHR are as follows:

    In [44]: fit_statsHR
    Out[44]:
    {'activities-heart': [{'dateTime': '2018-10-29',
       'value': {'customHeartRateZones': [],
        'heartRateZones': [{'caloriesOut': 1316.40702,
          'max': 96,
          'min': 30,
          'minutes': 911,
          'name': 'Out of Range'},
         {'caloriesOut': 393.42948,
          'max': 135,
          'min': 96,
          'minutes': 60,
          'name': 'Fat Burn'},
         {'caloriesOut': 0,
          'max': 164,
          'min': 135,
          'minutes': 0,
          'name': 'Cardio'},
         {'caloriesOut': 0, 'max': 220, 'min': 164, 'minutes': 0, 'name': 'Peak'}],
        'restingHeartRate': 51}}]}
    

    Setting 'base_date = "today" ' yields the same result.

    At the moment, I'm testing with iPython, in a Python 3 Miniconda+Windows 10 environment.

    Thanks a lot in advance for any help and/or commiseration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions