Chapter 2. Quantifying Yourself

“If you cannot measure it, you cannot improve it.”

Lord Kelvin

Data is a powerful tool for changing behavior. The act of simply tracking changes one’s perception of that activity. Summarizing the data over time provides a yardstick by which to measure, and the act of tracking activity over time uncovers patterns in behavior and provides definitive answers to self-experimentation questions. The structured data in HealthVault provides such an opportunity. Moreover, the HealthVault ecosystem offers a variety of applications and devices to assist in this endeavor.

In this chapter we will explore how a consumer can use various devices to track critical health measures. We will also use common tools to explore the data stored by devices in Microsoft HealthVault. We’ll capture and view some data, then use a PowerShell plug-in to extract selected data to a CSV format and manipulate the data in that format.

Fitbit is being used in this chapter just to illustrate the ways you can use data from all kinds of devices, so long as they provide a gateway to HealthVault. If you’re not using Fitbit, I encourage you to download the sample Fitbit sleep data included as part of this book’s examples, and follow along.

How Fitbit Tracks Sleep

Fitbit is a pedometer on steroids that enables you to monitor a number of aspects of daily living. This chapter concentrates on sleep because Fitbit has been very popular with users trying to understand and change their sleep patterns. Fitbit provides an arm band (Figure 2-1) that tracks whether you’re awake or asleep based on your activity level. Alternatively, users can select an on/off mode to indicate whether they’re asleep.

Fitbit being used to track sleep

Figure 2-1. Fitbit being used to track sleep

Fitbit also provides a base station that wirelessly uploads information from the device to the Fitbit web service. Not having to worry about uploading information is a great value-add provided by this product.

Sending Data to HealthVault

Fitbit enables users to sync their data automatically with HealthVault. Once you have a Fitbit account, you can choose the “Share stats” page (Figure 2-2), which becomes available after clicking on the account settings.

The “Share stats” page, among other services, enables a link to HealthVault (Figure 2-3).

Any application connecting to HealthVault has to get consent from the user for the kinds of data it will be reading from or writing to Microsoft HealthVault. The user control is a two-step process. In the first step, the user chooses the context of the record being authorized (Figure 2-4). As Figure 2-4 shows, in my case I have the option of using the application for my record or my mother’s. In the second step, the user grants access to the specific health data being shared with the application (Figure 2-5). As Figure 2-5 shows, the Fitbit application wants to access to my Exercise, Sleep Session, and other health information. We will learn in more detail about the user authentication and authorization system in Chapter 3.

Clicking on the “Information that Fitbit needs to be able to access to work as intended,” you will notice that Fitbit wants to access a user’s Custom Data, Fitness, Measurements, and Personal Profile, as shown in Figure 2-6. In the line below the heading you will notice Application-Specific Information, Exercise, Sleep Session, Personal Contact Information, and Personal Demographic Information, which are granular HealthVault data types. HealthVault has about 80+ granular data types that form the building blocks for various kinds of health information (Fitness, Measurement, etc.). The data types are optimized to work with different devices and health systems. We will learn more about HealthVault data types and vocabularies in Chapter 4.

Fitbit “Share stats” feature

Figure 2-2. Fitbit “Share stats” feature

Connecting Fitbit with Microsoft HealthVault

Figure 2-3. Connecting Fitbit with Microsoft HealthVault

Choosing the context of a HealthVault record to work with an application

Figure 2-4. Choosing the context of a HealthVault record to work with an application

Understanding the Data Model

Fitbit collects pedometer and sleep data. When the device syncs its data to HealthVault’s granular types, it stores data as detailed in Table 2-1.

Table 2-1. Fitbit HealthVault data mapping

Fitbit data

HealthVault data type

HealthVault field name

Calories Burned

Exercise

Calories burned

Steps Taken

Exercise

Number of steps

Daily Distance

Exercise

Distance

Got in to bed

Sleep Session

Bed Time

Got out of bed

Sleep Session

Wake Time

Slept for

Sleep Session

Sleep Minutes

Fell asleep in

Sleep Session

Settling Minutes

Wake State

Sleep Session

Wake State

As a user, we are interested in tracking all the information about sleep as collected by Fitbit. As you will note from Table 2-1, we should look at the HealthVault Sleep Session data type for tracking sleep and the HealthVault Exercise data type for tracking Fitbit pedometer data.

Authorizing an application to access a user’s health data

Figure 2-5. Authorizing an application to access a user’s health data

Granular details of the HealthVault data accessed by Fitbit

Figure 2-6. Granular details of the HealthVault data accessed by Fitbit

Exploring the HealthVault Data

You can look at the data stored from Fitbit in the HealthVault user interface (sometimes referred to as the HealthVault Shell), as shown in Figure 2-7.

Sleep session in HealthVault

Figure 2-7. Sleep session in HealthVault

Viewing information through the HealthVault user interface is convenient, but a user cannot retrieve the entire information by exporting the data. As a power user and a quantifier, I would like the data to be available to me to do some data-noodling. For that purpose, I would get this data in command-line format using the HealthVault PowerShell plug-in (HvPosh). You can find the details of installing and extending this plug-in at https://github.com/vaibhavb/HvPosh. PowerShell can export data to a standard CSV format that can be consumed by a variety of other tools, simple or advanced, that let you do calculations and generate charts.

Once you have installed PowerShell, load HealthVault’s plug-in into Windows PowerShell using:

Powershell> import-module HvPosh

Then, grant access to HealthVault PowerShell interface using the following command line. Note that this command will walk you through the same record-picking interface and authentication and authorization interface as we used earlier for the Fitbit application:

Powershell> Grant-HVPermission

Once you have access to HealthVault within PowerShell, you can start using the utility from the command line and extract information pertinent to Sleep Session:

Powershell> Get-Things -item Sleep-Session | format-table

The results for my sample data are shown in Figure 2-8.

Structured data from Sleep Session as retrieved by PowerShell

Figure 2-8. Structured data from Sleep Session as retrieved by PowerShell

If you don’t have a Fitbit and want to follow along, you can import data from the file Sleep-Data.xml available in the code associated with Chapter 3. Following is the command to import this data:

Powershell> Import-HvDataXml -File Sleep-Data.xml

You can understand the data further by exploring the individual properties. Figure 2-9 shows how you can select particular properties of a HealthVault data type using the PowerShell select-object command:

Powershell> get-things sleep | select-object When, Bedtime, WakeTime | format-table
Three columns of structured data from Sleep Session as retrieved by PowerShell

Figure 2-9. Three columns of structured data from Sleep Session as retrieved by PowerShell

In fact, I want to be able to explore details of awakenings. This is particularly relevant for learning about patterns of sleep disturbances. Figure 2-10 shows the output from the following command:

Powershell> get-things sleep | select-object -expandproperty Awakenings | format-table
Understanding the pattern of Awakenings

Figure 2-10. Understanding the pattern of Awakenings

Now you can enable some data crunching by exporting this data to a CSV file and switching the data analysis to Microsoft Excel or Google Spreadsheets:

Powershell> get-things sleep | select-object When, SleepMinutes, SettlingMinutes | export-csv SleepData.csv

This creates the file SleepData.csv with the selected data.

Analyzing the HealthVault Data

Once you have all the data in CSV file, you can open it in Excel (Figure 2-11) and analyze sleep patterns. You will notice that the spreadsheet has data for each sleep session specifying when that session occurred, the total sleep time in minutes, and the time it took to get to bed, termed as SettlingMinutes. I want to understand this data better, so I create a sleep pattern X-Y scatter plot for this information (Figure 2-14).

Sleep session data in an Excel spreadsheet

Figure 2-11. Sleep session data in an Excel spreadsheet

As Figure 2-12 reveals, for the duration of this week the median sleep has been around 400 minutes (i.e., around 6.5 hours), and as the data clearly shows, for the days when it took the longest to get to sleep, the duration of sleep has been lower. So a good indicator of not been able to get to sleep in 10 minutes is a lower and poorer quality of sleep.

Sleep Pattern analysis

Figure 2-12. Sleep Pattern analysis

In fact, for this duration I also want to understand the patterns around awakenings. So using PowerShell we generate another CSV file that focuses on awakenings:

Powershell> get-things sleep | select-object effectivedate -expandproperty awakenings |
Export-Csv d:sleep-date-aw.csv

We can open the file in Excel and visualize how the awakenings are triggered. It’s very obvious that most awakenings are for a duration of 10 minutes around 3 a.m, as shown in Figure 2-13. I know that this is because the workshop in my neighborhood is doing an early project and the noise around that time wakes me up.

Awakenings pattern analysis

Figure 2-13. Awakenings pattern analysis

We can even take it a step further and correlate the sleep information with other types of data. Fitbit also contains activity data, and we can try to associate the pedometer information with the existing sleep data.

Using the PowerShell HealthVault plug-in, we can grab the appropriate fitness data from HealthVault:

Powershell> Get-Things exercise | where-object {$_.Activity.Name -eq "walk"} | 
    select-object
-expandproperty Activity | export-csv pedometer.csv

Adding the pedometer data to what we obtained in Figure 2-12 gives us a way to correlate physical activity to sleep, as shown in Figure 2-14.

Correlating sleep with walking exercise

Figure 2-14. Correlating sleep with walking exercise

Note that we scaled the steps information from the pedometer by dividing it by 100, so it would play nice on the graph . Using this information, one can say it’s possible that the days on which you got less sleep were due to lack of exercise—but on the other hand, the settling time was high on those days as well. So maybe as a behavioral change, one can resolve to walk at least 5,000 steps to ensure a good sleep.

This might change in the long run, but that is the joy of learning from data and motivating a behavior shift! This book’s associated website, http://enablingprogrammableself.com, has a repository of spreadsheets that can inspire additional self-experimentation scenarios. You are invited to participate in the community and contribute self-tracking spreadsheets that you have found useful.

In upcoming chapters, we will learn how we can automate some of the work we have done in this chapter with the HealthVault application programming interface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.46