“Anyone can look for fashion in a boutique or history in a museum. The creative explorer looks for history in a hardware store and fashion in an airport” — Robert Wieder
As much as I like Medium for it’s ability to reach an audience I prefer the customization afforded by github.io. If you want to see a far-fancier version of this post please visit this page instead.
Project Inspiration
You may, or may not, have heard of the term gamification but chances are you’ve experienced it.
Gamification is the application of game-design elements, and game principles, in non-game contexts. The idea is, if you use elements of games, like linking rules and rewards into a feedback system, you can make (almost) any activity motivating and fun.
Gamification is the concept behind eLearning. In elementary school I remember all the students wanted to play The Oregon Trail in computer class. I also remember another game where you had to solve math problems before something hit the floor. Okay, maybe it wasn’t the most thrilling introduction to gamification but I remember it nonetheless.
At some point in my career, I got tired of using nano and decided to I wanted to try to learn Vim.
It was then that I discovered two very enjoyable examples of gamification:
Vim Adventures is kind of like Zelda for Gameboy where you have to move through the environment and solve riddles - except with Vim commands! You can watch it being played on Twitch here.
shortcutFoo teaches you shortcuts for Vim, Emacs, Command Line, Regex etc. via interval training, which is essentially spaced repetition. This helps you memorize shortcuts more efficiently.
Today, I enjoy eLearning-gamification on platforms like DuoLingo, and DataCamp.
I’ve also recently started to participate in a Kaggle competition, “PUBG Finish Placement Prediction”. Kaggle is a Google owned hangout for data science enthusiasts where they can use machine learning to solve predictive analytics problems for cash and clout. Similar to chess there are so-called Kaggle Grandmasters.
The Quest
Our laboratory studies perinatal influences on the biological embedding of early adversity of mental health outcomes. We combine genetic, epigenetic and epidemiological approaches to identify pregnant women who’s offspring may potentially be at risk for adverse mental health outcomes.
My supervisor approached me with a challenge; how feasible would it be to access biometric data from 200 Fitbits?
So I bought myself a Fitbit Charge2 fitness tracker and hit the gym!
At some point I think we both realized that this project was going to be a big undertaking. Perhaps R isn’t really intended to do large scale real-time data management from API services. It’s great for static files, or static endpoints, but if you’re working with multiple participants a dedicated solution like Fitabase may work the best - or so they claim.
Nonetheless, I wanted to try out a bunch of cool new things in R like making a personal website using blogdown, using gganimate with Rokemon, accessing the fitbit API with httr as well as adding a background image with some custom CSS/HTML. Is there possibly a better way to possibly gamify my leaRning curve - I think not.
The following was my attempt at e-learning gamification for R.
I used the blogdown package to allow me to write blog posts as R Markdown documents, knitting everything to a nice neat static website that I can push online. It was a nice opportunity to learn a bit about pandoc, Hugo, CSS/HTML lurking beneath the server side code. I decided to go with the Academic theme for Hugo, pull in as much data as I could from the Fitbit API, clean it up, and then perform some exploratory data analysis. In the process, I generated some cool animated sprites and use video game inspired visualizations.
Setting up a Fitbit Developer Account
Fitbit uses OAuth 2.0 Access Token for making HTTP request to the Fitbit API. You need to set up an account to use the API and include your token in R. Instead of reading the FITBIT DEV HELP section I would direct the reader to better more-concise instructions here.
Now that you have an account we’re ready to do stuff in R.
Set your token up:
# You Found A Secret Area!token = &quot;yourToken&quot;
Using the fitbitr package
I had never made an HTTP request before and although the process is officially documented here it can be a tad overwhelming. Therefore, I initially resorted to using an R package built to access the R API, under-the-hood, called fitbitr.
Unfortunately this would limit me to only accessing some basic user information, heart rate and step count data.
Getting Basic User Info
The first function in this package sends a GET request to the Get Profile resource URL.
# Extracting Resources
# Get userInfouser_info =80', 0.80, 1.00) %__% mutate(my_hr_low = floor(meps_max(30) * hr_lo), my_hr_hi = ceiling(meps_max(30) * hr_hi))my_MEPS
## # A tibble: 4 x 6## MEPS hr_range hr_lo hr_hi my_hr_low my_hr_hi## ## 1 1 50-59% 0.5 0.59 93 110## 2 2 60-69% 0.6 0.69 111 129## 3 3 70-79% 0.7 0.79 130 147## 4 4 __=80 0.8 1 148 186
With the equation now defined let’s calculate my total MEPS:
# Checkpoint!
mep = 146 ~ 4, value __= 128 ~ 3, value __= 109 ~ 2, value __= 91 ~ 1, TRUE ~ 0)) %__% summarise(&quot;Total MEPS&quot; = sum(meps))
Wow it’s 216!
I’m not sure what that exactly means but apparently the maximum possible MEPS in a 42-minute workout is 168 and since I ran this 10Km in 54:35 I guess that’s good?
I’d like to post sub 50 minutes on my next 10Km run but I’m not sure if I should be aiming to shoot for a greater percentage of peak heart rate minutes or not - guess I will need to look into this.
Minute-by-minute sleep data for one night
Let’s examine my sleep patterns last night.
# Resting at Campfire
get_sleep