Google Watch Fitbit data ETL and visualization

The Google Watch and Fitbit devices actually record a lot of detailed data that you may never see on the Fitbit app. For example, while the Fitbit app shows only a single average SpO2 value for a night’s sleep, SpO2, along with HRV and heart rate are recorded every few seconds. In order to see the SpO2, HRV and heart rate measurements recorded at seconds intervals you need to get the data from the Fitbit Web API. The code referenced below does just that.

Code used is in this Github repository

https://github.com/sitrucp/fitbit_data_viz

This Github repo contains Python code that connects to and retrieves the Fitbit Web API data as json files and then inserts these into a MongoDB database.  The repo also contains HTML, Node.js and Plotly.js code to connect to the MongoDB data and visualize the data. Some of these visualizations screenshots are provided below. The code gets the most common and useful Fitbit web API endpoints.

Transformation of the data occurs as part of the process that loads the data into MongoDB using Python, and some of it occurs when the data is retrieved from MongoDB using Node.js javascript code and HTML page Javascript.

A key feature of the code is that it includes a process to authenticate connections to the Fitbit Web API as well as persistent saving and refreshing authentication tokens for subsequent connections.

Technical highlights:

  • PyCherry used to pop Fitbit authentication login browser window.
  • Fitbit authentication token is saved locally as json file (auth_tokens.json).
  • Uses refresh token to get new tokens automatically.
  • Response log (response_log.json) records the last API call response date for each API endpoints.
  • Activity log (activity_log.json) records retrieval activity including response errors and messages.

Some of the visualizations screenshots are provided below:

Menu of individual detailed visualizations

A list of the visualizations is provided in the home page menu screenshot below.

 

Previous night’s sleep detail

This page contains a set of visualizations of the previous night’s detailed sleep activity including SpO2, heart rate and HRV.

 

Today’s summary snapshot

Another page displays a summary of the most recent day’s activity.

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top