class TcxRb::Lap
Attributes
calories[RW]
distance[RW]
intensity[RW]
start_time[RW]
total_time[RW]
trackpoints[RW]
trigger_method[RW]
Public Class Methods
new(args = {})
click to toggle source
# File lib/tcx_rb/lap.rb, line 7 def initialize(args = {}) @start_time = args[:start_time].to_s @total_time = args[:total_time].to_f @distance = args[:distance].to_f @calories = args[:calories].to_i @intensity = args[:intensity] @trigger_method = args[:trigger_method] @trackpoints = args[:trackpoints] end
Public Instance Methods
active_time()
click to toggle source
# File lib/tcx_rb/lap.rb, line 84 def active_time # aggregation of time spent moving active = 0.0 @trackpoints.each_with_index do |tp, i| next if i.zero? || tp.distance.zero? prev_tp = @trackpoints[i - 1] d_t = Time.parse(tp.time) - Time.parse(prev_tp.time) active += d_t end active end
avg_altitude()
click to toggle source
# File lib/tcx_rb/lap.rb, line 40 def avg_altitude tot = @trackpoints.inject(0.0) { |sum, el| sum + el.altitude } tot / @trackpoints.size end
avg_heart_rate()
click to toggle source
# File lib/tcx_rb/lap.rb, line 27 def avg_heart_rate tot = @trackpoints.inject(0.0) { |sum, el| sum + el.heart_rate } tot / @trackpoints.size end
avg_pace()
click to toggle source
# File lib/tcx_rb/lap.rb, line 97 def avg_pace distance / active_time end
max_altitude()
click to toggle source
# File lib/tcx_rb/lap.rb, line 32 def max_altitude @trackpoints.map(&:altitude).max end
max_heart_rate()
click to toggle source
# File lib/tcx_rb/lap.rb, line 19 def max_heart_rate @trackpoints.map(&:heart_rate).max end
max_pace()
click to toggle source
# File lib/tcx_rb/lap.rb, line 45 def max_pace max = 0.0 @trackpoints.each_with_index do |tp, i| # skip first cause we need to refrence previous # and if the current trackpoint is 0.0 in distance, # we will skip it because that means we're stopped next if i.zero? || tp.distance.zero? prev_tp = @trackpoints[i - 1] # also skip to the next one if i isn't 1 and the previous is 0 # because we could get a ridiculously high pace. next if i != 1 && prev_tp.distance.zero? # now we can perform the calculation d_dist = tp.distance - prev_tp.distance d_t = Time.parse(tp.time) - Time.parse(prev_tp.time) pace = d_dist / d_t max = pace if pace > max end max end
min_altitude()
click to toggle source
# File lib/tcx_rb/lap.rb, line 36 def min_altitude @trackpoints.map(&:altitude).min end
min_heart_rate()
click to toggle source
# File lib/tcx_rb/lap.rb, line 23 def min_heart_rate @trackpoints.map(&:heart_rate).min end
min_pace()
click to toggle source
# File lib/tcx_rb/lap.rb, line 68 def min_pace min = Float::INFINITY @trackpoints.each_with_index do |tp, i| next if i.zero? || tp.distance.zero? prev_tp = @trackpoints[i - 1] next if i != 1 && prev_tp.distance.zero? d_dist = tp.distance - prev_tp.distance d_t = Time.parse(tp.time) - Time.parse(prev_tp.time) pace = d_dist / d_t min = pace if pace < min end min end