FitKit
Not production ready yet.
fit_kit is a small ruby gem wraps Rust's crate fitparse-rs to provide effecient and fast Garmin fit files parsing.
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add fit_kit
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install fit_kit
Usage
test_fit_file = File.join(Dir.pwd, "example.fit")
fit_data_records = ::FitKit.parse_fit_file(test_fit_file)
# { record: [{...}, {...}], session: [{...}], lap: [..], activity: [...] }Features
There are couple of more built-in features can simplify the consuming of the data significantly:
-
records_hash- All records in a ruby hash format -
avg_for- Average of a given field -
elevation_gain- Elevation gain. Calculate the overall elevation gain. Also allow to pass in a field. -
calculate_partition_indices- Calculate the partition indices for a given field -
partition_stats_for_fields- Calculate the partition stats for a given field. Useful for calculating splits data. -
sample_series_for_records- Sample series for a given field, useful for plotting -
zone_time_for- Heart Rate Zones data
Performance
Here is the performance parsing 4090 fit files on my M1 Mac Mini (16G, 8 Cores) took 6 seconds (in parallel):
❯ ruby app.rb
Parsing 4090 fit files...
user system total real
0.129862 0.102642 45.192900 ( 6.121117)Code to parse a given folder (contains 4090 fit files) in parallel:
require 'fit_kit'
require 'benchmark'
require 'parallel'
def parse_concurrently
puts "Parsing all fit files here"
fit_files = Dir.glob("/Users/mikeli/docs/HealthFit/*.{fit,FIT}")
puts "Parsing #{fit_files.size} fit files..."
# Determine the number of processors
num_processors = Parallel.processor_count
# Parse files concurrently
Parallel.each(fit_files, in_processes: num_processors) do |file|
begin
FitKit.parse_fit_file(file)
rescue => e
puts "Error parsing #{file}: #{e.message}"
end
end
end
Benchmark.bm do |x|
x.report do
parse_concurrently
end
endContributing
Bug reports and pull requests are welcome on GitHub at https://github.com/29decibel/fit_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the FitKit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.