Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

The Gamification Of Fitbit: How an API Provided the Next Level of tRaining


(This article was first published on Stories by Matt.0 on Medium , and kindly contributed toR-bloggers)

“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” ― RobertWieder

The Gamification Of Fitbit: How an API Provided the Next Level of tRaining

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 pageinstead .

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 andfun.

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 learnVim.

The Gamification Of Fitbit: How an API Provided the Next Level of tRaining

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 Twitchhere .
The Gamification Of Fitbit: How an API Provided the Next Level of tRaining
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.
The Gamification Of Fitbit: How an API Provided the Next Level of tRaining

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 200Fitbits?

So I bought myself a Fitbit Charge2 fitness tracker and hit thegym!

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 theyclaim.

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 thinknot.

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.

The Gamification Of Fitbit: How an API Provided the Next Level of tRaining
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 inR.

Set your tokenup:

# You Found A Secret Area! token = "yourToken" Using the fitbitrpackage

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, calledfitbitr.

Unfortunately this would limit me to only accessing some basic user information, heart rate and step countdata.

Getting Basic UserInfo

The first function in this package sends a GET request to the Get Profile resourceURL .

# Extracting Resources # Get userInfo user_info <- fitbitr::getUserInfo(token) # Hailing a Chocobo!

Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles

Latest Images