Workouts are a bit more special in that they group a collection of samples together and classify what they represent as a whole. For instance when I go running I have my GPS watch, I also have a foot pod and a heart rate monitor. The data points I have from all of that include:
- distance
- duration
- active calories
- activity type
- steps
- heart rate
My watch samples all of this about every 5 seconds so I might go for a one hour run and with 12 of these samples a minute, I end up with 720 samples for the whole hour. Those samples will then all be written to HealthKit across those separate data points and provide a very rich snapshot of my body for that time period.
For Speedo Fit we don’t quite have access to the same level of detail yet, but we log still log the following information as a workout:
- distance
- duration
- active calories
- activity type
When a swim is logged we store a single sample for the active calories which spanned the whole time from the start of the swim to the end.
Active Calories
As an aside, we have added the estimation of swim calories as part of this release. We felt that it was an important addition to make your swims in HealthKit more relevant to other apps.
The generally accepted method for estimating active calorie burn is via metabolic equivalents (METs). Every activity has a MET score reflecting the amount of exertion. An MET is the number of calories burned during an activity per kilogram of bodyweight per hour.
hours x MET x kg
There are lots of charts estimating the METs of all kinds of activities ranging from hoovering to horse riding. For our first version we’ve mapped a range of 6 METs to 12 METs for swims and we scale that based on the time in the pool and the distance swum.
This allows us to add an estimation of calories when recording swims to HealthKit, provided we are either given access to your weight via HealthKit or you provide one manually within the app.
The fact that we can request your weight via HealthKit is another example of its benefit. For example I have Withings WiFi scales at home so my weight is automatically synced whenever I weight myself. This keeps my calorie estimates always as accurate as possible.
Lastly, calorie estimations are not just for HealthKit users! You will still get them if a weight is entered in your profile and you set a start and end time on your swim.
Start times, duration & historical swim data
I think one of the guiding principles of any app contributing to a users HealthKit store is that the timeline must be sacrosanct. What I mean by that is that if the data is not complete enough then it shouldn’t be added.
When swim recording was first added to Speedo Fit, we decided to just set the date of the swim and to not worry about start times or end times so as to make it as quick and easy as possible to record a swim. In Speedo Fit 3.1 we added the ability to set a duration.
Going back to the timeline concept though, this isn’t enough for HealthKit. Without a specific start and end time for each swim in your history, it’s not possible to record them. If we were to pick and arbitrary start and end time for each swim, there’s a high chance they would overlap with other activities and future apps analysing your data would get very confused.
We have therefore made start and end times mandatory when recording a swim when HealthKit is enabled.
My data is in HealthKit, now what?
This is now really up to other app developers. Any time you turn on HealthKit in another app and it requests access to read workouts and active calories, the chances are your swimming data will be contributing in some way to the view of your health data that app is giving you.
Unfortunately Apple’s Health app currently only shows distance for running and walking, not swimming. You will see your swims on the active calories graph, so don’t worry, your data is in there!
Data, Privacy and iCloud
An interesting thing about HealthKit is that the data just lives on your iPhone. Although your HealthKit store is backed up with iCloud backup it is not synced to iCloud. There’s an important distinction there. For example, if you have a work iPhone and a personal iPhone, each iPhone will have its own distinct HealthKit store. However, providing you have iCloud backups turned on, if your phone is lost or stolen or you buy a new one, restoring from an iCloud backup will restore your HealthKit store.
Apple are making quite a big deal about this. The recorded data is of an incredibly private and personal nature and they’re preventing HealthKit stores from being passed over any kind of network except as part of a secure iCloud backup. Part of the App Store submission guidelines specifically prohibits developers from storing HealthKit information in iCloud without user permission and all apps using HealthKit have to have a privacy statement explicitly saying what we do with your data.
I think the fact your phone is the central hub of information there, collecting data from apps and health devices is indicative of Apple’s vision of the future. One where your phone is a mini-portable server and you have an set of satellite devices (Apple Watch!) which you use to send and receive data. The Apple Watch, for starters, has at least two sensors which will be directly feeding into your iPhone - heart rate and accelerometer.