Monday, April 30, 2012

Activity Logging

Avocado Activity Classifier has now been published in Google Play. It uses the handset accelerometers to classify activities by type and quantify aerobic intensity in MET. Data is uploaded live to Google Fusion Tables.
Activity logging can be used to:-
  • Provide information on total exercise, health and activity levels.
  • Automate exercise tracking.
  • Infer further lifestyle information by combining with other information sources, for example location data.

How Much Time Do I Spend In Each Activity?

Using the Activities_Summary Fusion Table we can discover what proportion of time is spent on each activity. First we aggregate by activity and sum the time, then visualise the data with a pie chart, get the embeddable code and paste it into a web page or blog to give Figure 1.
Figure 1 Activity distribution for all time, updated every time the page is viewed.

Figure 1 is a live SVG graph which changes as the underlying data changes. It is nicely interactive but will not display on most Android web browers so it can be also be turned into the static image of figure 2 which will not update.
Figure 2 Activity distribution up to 26 April 2012 as a static image.
To get useful data, phone activities need to be separated from user activities. A large portion of the day the phone is charging, mostly overnight when I'm asleep. On average several hours a day the handset is detected as uncarried, mostly when I'm at home. As I'm not carrying it, the handset provides no information on my activities during this time but they would be mostly sedentary. Figure 2 is influenced by me being sick for a week so over time it should deviate from Figure 1.  A depressingly small amount of my average day is spent running but I do commute by bike. At the moment this is classified as walking so is included in my walking figure. This will change in the future. I try to walk every day and this is reflected in the data. The rest of the average day I'm stationary which includes standing and sitting but in my case is mostly sitting.

Activity Distribution For A Particular Period

The aggregated data can be filtered for a particular period as shown in figure 3.
Figure 3 Activity distribution 14th - 16th of April when I was healthy.

This period is included in Figure 2 but I managed more walking and running in these few days than the average. These are reasonable activity levels to aspire to.

Activity Distribution For The Last 'n' Days

Until now the query for the data to be plotted was built by selecting options in the fusion table interface and the embeddable html this generated was pasted into this page. This hasn't required any programming but by adding a little JavaScript we can make the data to be plotted user configurable. As an example, take the embeddable code generated in the fusion table interface for the particular period shown in figure 3 and change the date filter value from a constant to a variable. Then provide a text box to capture user input. The JavaScript updates the query variable with the user input and sends the query to recreate the graph. The result, an activity distribution for the previous user chosen, number of days, is shown in figure 4. The JavaScript can be seen and copied from the page source beginning at //Example begins here// and ending at
This is where a graph goes.
Previous days to include: Days:
Figure 4 Distribution of activities from today for a user configurable number of days.
//Example ends here//

Using figure 4 I can check if I am currently achieving the average daily walking times to which I aspire, shown in figure 3 .

Average MET For Each Activity

Sitting on the couch watching the TV gives a MET of 1 in contrast to, say, jogging which can require 7 times more energy.  Step counting with a pedometer is often used to quantify exercise levels as the sensors are cheap and everyone understands steps, but MET  is a better standard for quantifying aerobic effort. Metabolic Equivalent of Task (MET), or simply metabolic equivalent, is a measure of the intensity of aerobic exercise.
Aggregating by activity, excluding running, averaging MET and viewing as a line graph gives the result in figure 5.
Figure 5 Average MET for each activity excluding running for all time. All "Uncarried" activities are handset rather than human activities and MET is recorded as 1 because there is no information to show the human is not sedentary.
MET can be measured from accelerometer data quite accurately in most situations but not all. For example, accelerometers will measure the increase in MET with increasing speed but are insensitive to change of grade. It's superior to step counting though, as step count is unaffected by both pace and grade. I like to walk up mountains and try to do so daily so some of my walking will be at a higher than measured MET. My running sample is too small for the MET to be meaningful.

When Does Walking Happen?

You can plot duration versus time for a particular activity. Most of my physical activity is walking so filtering on walking and visualising the result as a zoomable line chart shows when I do it as illustrated in figure 6. Try zooming these graphs or sliding the graph window with the control in the lower window. It is very nice.
Figure 6 Minutes walking versus time shows what time of the day long walks take place

Doing the same thing for MET gives the result in figure 7.

Figure 7 MET while walking versus time.

Comparing figure 6 and figure 7 shows that I get the majority of my aerobic exercise during the long walks. My MET during these walks is double the overall average shown in figure 5 even though it is underestimated when climbing mountains.

Fusion Tables

As demonstrated in the above examples Fusion tables provide a great opportunity to play with your activity data and fine control over what you publish or share with friends. The examples above have links to the graph definitions that can be copied for your own data. Avocado Activity Classifier creates two Fusion Tables; the Activities table which contains a lot of detail and the Activities_Summary which is a subset of the first and intended to be shared.

Battery Consumption

Avocado Activity Classifier runs intermittently in the background whenever the phone is on and will be too inconvenient to use if it consumes significant battery power. The accelerometer, a BMA150, in many handsets is a low power device. If it was configured to transfer data periodically using interupts, battery consumption while activity monitoring could be significantly reduced and somebody will probably sell an Android sports phone one day that does it. Currently AvocadoAC has a 20% duty cycle, sampling 6 seconds out of every 30. Consequently it already draws less from your battery than pedometer apps but we are still searching for the sweet spot. In the test shown in figure 8, power consumption is lower than Cell standby and Phone idle which hopefully is low enough to satisfy most users.
Figure 8 After over 10 hours the battery is still at 80%. Battery consumption in this test is lower than Cell Standby and Phone idle. WiFi was on but not connected and consumed double the power of AvocadoAC.

The effect on battery life for any particular user is highly dependant on use patterns. I usually get through a day OK and recharge every night. Battery consumption is low enough in this case so as not to be noticed. If you don't get through a day on a single charge the battery will fail slightly earlier but it's not likely to be noticed because other things, most likely the display, will be dominating consumption. If you normally go 3-4 days between charging then very little battery is being consumed and you are likely to notice the additional load from Avocado Activity Classifier.

Where Does This Work Fit?

Our overall goal with this work is to monitor exercise and training and make lifestyle, training and tactical race decisions based on data rather than guesswork. The data that could be recorded is almost infinite and the effort to acquire it can easily be greater than the value of the information that it provides. Therefore, data acquisition must require as little human intervention as possible. This requires; methods to detect what data is appropriate for any particular situation, acquiring the minimum necessary, summarising the data as it is recorded and storing the summary in a useful form.  Avocado Activity Classifier is intended to provide a record of exercise and activity data during the course of a day and when a training activity is detected invoke other applications suitable for monitoring specific training activities all without user intervention.

A non market version which uploaded activity data to a centralised repository was made available when the conference paper  Activity Classification With Smart Phones For Sports Activities was published. Since then, the classification algorithm has been changed from K-Nearest Neighbour (KNN) to a Naive Bayes classifier and Activity data is now uploaded to Google Docs Fusion Tables rather than our own repository.


Ken Taylor, U. A. Abdulla, R. J. N. Helmer, J. Lee, and I. Blanchonette. Activity classification with smart phones for sports activities. In APCST 2011: 5th Asia-Pacific Congress on Sports Technology, Procedia Engineering. RMIT University, Elsevier, August  2011. 162k View Download