Sha256: a49c233220dc2999365a8f59ea5755d76ecf62b38a14a1edf47e8997f6da5c71
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
module HRMParser class Workout attr_accessor :duration, :distance, :time, :name, :file_name, :trackpoints attr_reader :average_hr, :data, :average_speed, :altitude_gain def initialize(opts = {:duration => nil, :distance => nil, :time => Time.now, :name => nil, :file_name => nil}) @duration = opts[:duration] @name = opts[:name] @time = opts[:time] @distance = opts[:distance] @file_name = opts[:file_name] @data = nil @trackpoints = {} end def calc_average_hr! ahr = heart_rates.compact.aaverage @average_hr = ahr == 0.0 ? nil : ahr end def calc_average_speed! aspeed = speeds.compact.aaverage @average_speed = aspeed == 0.0 ? nil : aspeed end def calc_altitude_gain! gain = 0 smoothed_altitude = altitudes.smoothed(10) start = smoothed_altitude.first smoothed_altitude.each do |alt| diff = alt - start if (diff > 0) gain += diff end start = alt end @altitude_gain = gain == 0.0 ? nil : gain end ## Some helper functions that return specific files from trackpoint as array def heart_rates @trackpoints.map {|tp| tp.hr } end def speeds @trackpoints.map {|tp| tp.speed } end def altitudes @trackpoints.map { |tp| tp.altitude } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
teich-hrmparser-0.4.5 | lib/hrmparser/workout.rb |