Niraj Juneja, Charles de Lassence
Fitcoach : Fitbit R API and Recommendation Engine for Fitbit
We are glad to submit the fitcoach package. As part of the project we have been able to accomplish the following:
Connect R to Fitbit API and expose an individual’s Fitbit data as a Dataframe for further analysis.
- DataLoader.R does this. Example 1 shows how to do this
- DataLoader enables getting both the Daily time-series data and Intra-day time-series data at 15 min breaks for the individual.
- Note : intra-day data will require the user to create a new app on Fitbit website and is only available for app owner. i.e User A cannot access Intra-day data from User B. This is a Fitbit restriction
Created FitAnalyzer R6 class that provides an opinionated but focussed implementation for analyzing Fitbit Data. It is likely that this workflow might not work for all. In this situation, the user can directly use Fitbit functions provided in FitUtil.R and create a customized analysis flow.
We were able to build the following.
- Ability to set goals and find the most significant variables that are enabling meeting the goals. The Example 2 and Example 3 here demonstrates this flow.
- Ability to call a function and provide recommendations for the rest of the day. The Example 2 and 3 demonstrate this flow. This is implemented for both daily and intra-day scenarios.
- Provide advanced charts in ggplot2. The Example 2 and Example 3 here demonstrate the graphs.
- Package Design Philosophy
- DataLoader.R is an R6 class because it encapsulates a unique OAuth2.0 based flow for accessing Fitbit API. The goal of this class is to orchestrate the Fitbit connection flow and download daily or intraday json files into a folder so that the json files can be analyzed further.
- FitAnalyzer.R is an R6 class with a opinioned workflow for analysis. The class maintains state related to goal, analysis type among other things. It does not store the data.frame used for analysis to avoid memory issues. The user is expected to hold on to the data.frame
- FitUtil.R is a utility file that has functions for Fitbit analysis.
- We are using GLM for daily file and GBM for intraday file analysis. intra-day file analysis has a lot more data points and hence GBM works well here.For daily file, we have 1 datapoint per day. Hence, we decided to use GLM because we do not expect a lot of data in this file.
Please refer to the detailed Example to understand the usage of the package