-
Notifications
You must be signed in to change notification settings - Fork 9
Home
Workout is able to export any workout saved in the Health app to a CSV file with date and time of the workout, heart rate, distance, speed and pace (if available) and a minute-by-minute break up of the data for supported workouts.
Refer to this guide to add other workout types
The following workout types currently support minute-by-minute details with specified data:
- Running & Walking: pace, heart rate, step count
- Swimming: speed, heart rate, stroke count (only on iOS 10 and later)
Workout can load data in both metric and imperial units by specifying the appropriate pair of units, however for distances data must be loaded using meters but different units for display can be chosen: if a workout type needs units different from kilometers/miles (the default) create a dedicated subclass as specified here following only point 3.i., 4. and 5.
Besides general data and minute-by-minute details, each instance of Workout
can process the same or additional data in other ways thanks to instances of the AdditionalDataProcessor
protocol and present it with instances of the AdditionalDataProvider
protocol.
Instances of the AdditionalDataProcessor
protocol must declare with wantData(for:_)
if they wants/needs to process data with the given HKQuantityTypeIdentifier
. This data is the one loaded as requested with the addQuery(_)
method of Workout
and will be provided, sorted by increasing start date, with the process(data:_)
method, there is no guarantee for the order in which different data types will be provided.
Instances of the AdditionalDataProvider
protocol added to a Workout
are granted a section in the table view and must take care of managing its rows. For now data displayed can only be arbitrary or loaded with a AdditionalDataProcessor
(the same class can implement both of this protocols), but this is a good point to provide additional non-HKSampleQuery
queries that the load(quickLoad:_)
method of a Workout
will execute if the need ever arises in the future. Instances must implement a simplified subset of the methods of UITableViewDataSource
and export capabilities (if appropriate for the data).
Additional data processors and providers can be added to a Workout
using the methods addAdditionalDataProcessors(_)
and addAdditionalDataProviders(_)
respectively. The order in which providers are added is reflected in the order their data appears. Minute-by-minute details use this approach to present the data with the MinuteByMinuteBreakdown
class that has to be added as both a data processor and provider, the addAdditionalDataProcessorsAndProviders(_)
method is available for this purpose.
Health data is loaded from all sources but since both Apple Watch and iPhone record steps simultaneously you have to specify one of these, or a custom source, as the single source for step data, if steps are not available make sure you selected the correct source.
The app behaviour can be changed by configuring global and static variables:
- File
Main.swift
:-
healthReadData
: List of type to be read in order to display data correctly for workouts. -
maxPace
: No longer available, configure each workout subclass individually.
-
- Class
RunningHeartZones
:-
defaultZones
: The default heart zones, the numbers (at least two) are the lower thresholds of the zones, the same you can edit from the settings inside the app. -
maxInterval
: The maximum interval between two data point for heart rate for them to be considered valid. A time interval lower or equal than this will be included in the appropriate heart zone, any higher and it will be discarded.
-