Watchlib - A python module to analyze Apple Watch health data

Posted by Marc Julian Schwarz on Friday, January 14, 2022

watchlib

As I am a long-term user of Apple Watches since 2018, I always enjoyed looking at various stats in Apples Health and Fitness apps. However sometimes I wanted more than that, which is why I am working on the python module watchlib [1]. It enables easy and quick loading, visualizing, animating and analyzing of Apple Watch health data.

Data loading

watchlib [1] features a DataLoader class to load the data from the health export files and brings it into usable formats. Using the CacheHandler you can export the formatted data for faster access when running the application again.

Filtering

With a pipeline based filtering system, you can easily filter filter the data to your likings.

Right now there are three different filters for WorkoutRoutes:

Using the FilterPipeline you can create a sequence of filters. In the following example only routes which have been recorded in Germany, with a diagonal distance of 3km and with a minimum duration time of 10 minutes are left.

cf = CountryFilter(Germany)
df = DiagonalBBoxFilter(3)
tf = TimeFilter(min_duration_sec=60*10)

p = FilterPipeline(cf, df, tf)
filtered_routes = p.filter(routes)

Filter Pipeline Filter Pipeline

Animations

watchlib [1] can animate a WorkoutRoute and ECG using WorkoutAnimation and ECGAnimation. Here are some examples:

The animation can of course be customized. Changing the color_on parameter to one of these values:

will color the route accordingly.

ECG Analysis

With watchlibs [1] ecg_analysis submodule you can quickly analyze a 30sec ECG. It can calculate the average heartbeats per minute by counting spikes in the electrocardiogram.

By calculating the time between every heartbeat an estimation of the heartbeat variability (HRV) can be obtained from an ECG too. While this value is not at all representative of the actual HRV (because the recordings are way too short) it is still cool to see that splitting an ECG at every heartbeat and layering all these actions on top of each other reveals the variability between the heartbeats:

HRV 10 HRV 10 HRV 30 HRV 30

Demonstrator

To showcase the watchlib demonstrator I made a short video: