Case Study - Steps Competition

In this app, teams of participants compete with other teams in a weekly steps challenge. Participants are assigned teams at the beginning of the study, then randomly matched up against other teams each week throughout the study. Each time a participant opens MyDataHelps, they are able to see how their team matches up against their opponent in average daily steps for the week.

Architecture

At a high level, there are three major components to this app:

  • MyDataHelps Server - Passively collects steps data from wearable devices (e.g. Fitbit and Apple Watch) and stores competition results.
  • MyDataHelps App - Supports MyDataHelps in collecting steps from participant devices, and displays current competition results using a custom application.
  • Amazon Web Services (AWS) - Interacts with the MyDataHelps API to implement the competition logic: assigning participants to teams, setting up competitions, and determining competition results.

On the AWS side, there are actually several different cloud services working together to implement the competition logic. Here each matchup (team A vs. team B) is essentially treated as its own independent competition.

  1. An AWS CloudWatch event is configured to run on a set schedule several times a week.
  2. The scheduled event kicks off the “competition producer”, an AWS Lambda that coordinates everything. At the beginning of the week, the producer determines the team matchups and sets up the competitions. During the week, it triggers standings updates. At the end of the week, it triggers the final results.
  3. A separate AWS Lambda, the “competition calculator”, interfaces with MyDataHelps to obtain the participant/steps data, calculate the results, and update the standings. There is a separate calculator for each competition. All are triggered through AWS Simple Queue Service (SQS) events from the producer.
  4. While the competition results are saved to MyDataHelps (so they can be displayed to participants in MyDataHelps), the producer stores its own internal data (such as the competition schedule) in an AWS DynamoDB database.

Using the API

The competition calculator leverages the MyDataHelps Participants API to obtain participants for a given team, and the Device Data API to get their steps information through FitBit and/or Apple HealthKit.

Competition results are saved to MyDataHelps as custom device data points, also using the Device Data API. Even though this is not technically “device data”, projects can use the “project” namespace to save custom project data for a given participant.

The calculator also must authenticate in order to access the APIs.

This sequence is illustrated in the diagram below:

Project Setup

For all of this to work, several things need to be configured in the MyDataHelps project:

  • Enable the desired device and sensor data in the project settings.
  • Set up a service account for API access.
  • Set up a custom field to store which team a participant is assigned to and initialize it during enrollment.