tormoder / fit

A Go package for decoding and encoding Garmin FIT files
MIT License
243 stars 42 forks source link

activity: structured activity file type #18

Open ktye opened 8 years ago

ktye commented 8 years ago

Currently, after decoding you basically get a flat activity file. This closly represents the fit file protocol. But an application might be more interested in a tree-structure of the activity, e.g.

type StructuredActivityFile {
  Sessions []StructuredSession
}
type StructuredSession{
  Lap []*StructuredLap
}
type StructuredLap {
  LapMsg // Copy or reference of original lap for summary information
  Records []*RecordMsg // Contains only data records which were during this lap.
 // maybe also others, such as events, ...
}

This could be calculated in a post-processing step as a method of ActivityFile by

 func (a *ActivityFile) StructuredActivity() StructuredActivity {...}

I guess it's only neccessary to compare timestamps to build the tree.

What do you think of this? Or is the scope of the package to represent the fit protocol closly, leaving all higher level functionality for other packages?

tormoder commented 8 years ago

Yes, I agree this could be useful, and the method signature looks about right. Maybe it should also be possible to specify if the Activity should be "cloned", or to just keep the references to the original ActivityFile, so that any changes are reflected for both structures.

I would like to have this as a post-processing step. I already have an earlier draft of some other post-processing functionality (determining time zones based for local timestamps based on GPS-coordinates). I will put this in a separate package because it uses an external dependency, and I don´t want the core fitpackage to have any external deps. I don`t think your suggestion needs any external dependencies, so it may be possible to place it in the core package.