A common interface for (currently) two decoders:
- zwo files (xml format)
- fit files (binary format)
that allow to create a common model of a workout. See Sources/WorkoutDecoderBase/WorkoutDecoding.swift
for model definitions.
Models are easy to use:
- intervals are flattened
- messages' time offset are normalized with respect to the beginning of the training
To use the decoders in your project, add this Swift Package in your project. You can choose individual decoders, or a common facade WorkoutDecoders
.
See tests for example of decoding workouts. Workout definitions may be using both absolute and FTP relative values, but for simplicity workouts are decoded to contain only FTP relative values. That's why FTP is needed for FIT file decoding.
let decoder = WorkoutDecoder(userFtp: 200)
let file = Bundle.module.url(forResource: "workout", withExtension: "fit")!
do {
let data = try Data(contentsOf: file)
let workout = try decoder.decodeWorkout(fileFormat: "fit", data: data)
// use workout
} catch {
// handle decoding errors
}
- Need to add a test for FIT file decoding. Will need to find a file that I can publish, or find a tool to create one.
- Potential support for FIT notes as messages.
For an app I am developing, ZWO and FIT file support is enough. MRC, ERG or other file support could be added if needed, but preferably by providing a PR :)
Workout model could be extended if there is also a need for that.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.