Class: Fit4Ruby::Session
- Inherits:
-
Object
- Object
- Fit4Ruby::Session
- Includes:
- Converters
- Defined in:
- lib/fit4ruby/Session.rb
Instance Attribute Summary collapse
-
#ascend ⇒ Object
readonly
Returns the value of attribute ascend.
-
#avg_heart_rate ⇒ Object
readonly
Returns the value of attribute avg_heart_rate.
-
#avg_running_cadence ⇒ Object
readonly
Returns the value of attribute avg_running_cadence.
-
#avg_speed ⇒ Object
readonly
Returns the value of attribute avg_speed.
-
#avg_stance_time ⇒ Object
readonly
Returns the value of attribute avg_stance_time.
-
#avg_vertical_oscillation ⇒ Object
readonly
Returns the value of attribute avg_vertical_oscillation.
-
#calories ⇒ Object
readonly
Returns the value of attribute calories.
-
#descent ⇒ Object
readonly
Returns the value of attribute descent.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#first_lap_index ⇒ Object
readonly
Returns the value of attribute first_lap_index.
-
#max_heart_rate ⇒ Object
readonly
Returns the value of attribute max_heart_rate.
-
#num_laps ⇒ Object
readonly
Returns the value of attribute num_laps.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#strides ⇒ Object
readonly
Returns the value of attribute strides.
-
#training_effect ⇒ Object
readonly
Returns the value of attribute training_effect.
Instance Method Summary collapse
- #avg_stride_length ⇒ Object
- #check(activity) ⇒ Object
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #set(field, value) ⇒ Object
- #to_s ⇒ Object
Methods included from Converters
#fit_time_to_time, #secsToDHMS, #secsToHMS, #speedToPace, #time_to_fit_time
Constructor Details
#initialize ⇒ Session
27 28 29 |
# File 'lib/fit4ruby/Session.rb', line 27 def initialize @laps = [] end |
Instance Attribute Details
#ascend ⇒ Object (readonly)
Returns the value of attribute ascend.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def ascend @ascend end |
#avg_heart_rate ⇒ Object (readonly)
Returns the value of attribute avg_heart_rate.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def avg_heart_rate @avg_heart_rate end |
#avg_running_cadence ⇒ Object (readonly)
Returns the value of attribute avg_running_cadence.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def avg_running_cadence @avg_running_cadence end |
#avg_speed ⇒ Object (readonly)
Returns the value of attribute avg_speed.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def avg_speed @avg_speed end |
#avg_stance_time ⇒ Object (readonly)
Returns the value of attribute avg_stance_time.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def avg_stance_time @avg_stance_time end |
#avg_vertical_oscillation ⇒ Object (readonly)
Returns the value of attribute avg_vertical_oscillation.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def avg_vertical_oscillation @avg_vertical_oscillation end |
#calories ⇒ Object (readonly)
Returns the value of attribute calories.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def calories @calories end |
#descent ⇒ Object (readonly)
Returns the value of attribute descent.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def descent @descent end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def distance @distance end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def duration @duration end |
#first_lap_index ⇒ Object (readonly)
Returns the value of attribute first_lap_index.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def first_lap_index @first_lap_index end |
#max_heart_rate ⇒ Object (readonly)
Returns the value of attribute max_heart_rate.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def max_heart_rate @max_heart_rate end |
#num_laps ⇒ Object (readonly)
Returns the value of attribute num_laps.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def num_laps @num_laps end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def start_time @start_time end |
#strides ⇒ Object (readonly)
Returns the value of attribute strides.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def strides @strides end |
#training_effect ⇒ Object (readonly)
Returns the value of attribute training_effect.
21 22 23 |
# File 'lib/fit4ruby/Session.rb', line 21 def training_effect @training_effect end |
Instance Method Details
#avg_stride_length ⇒ Object
84 85 86 |
# File 'lib/fit4ruby/Session.rb', line 84 def avg_stride_length @distance / @strides end |
#check(activity) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fit4ruby/Session.rb', line 31 def check(activity) @first_lap_index.upto(@first_lap_index - @num_laps) do |i| if (lap = activity.lap[i]) @laps << lap else Log.error "Session references lap #{i} which is not contained in " "the FIT file." end end end |
#set(field, value) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fit4ruby/Session.rb', line 42 def set(field, value) return unless value case field when 'start_time' @start_time = value when 'total_timer_time' @duration = value when 'total_distance' @distance = value when 'total_strides' @strides = value when 'total_ascent' @ascend = value when 'total_descent' @descent = value when 'total_calories' @calories = value when 'avg_speed' @avg_speed = value when 'avg_heart_rate' @avg_heart_rate = value when 'max_heart_rate' @max_heart_rate = value when 'avg_vertical_oscillation' @avg_vertical_oscillation = value when 'avg_stance_time' @avg_stance_time = value when 'avg_running_cadence' @avg_running_cadence = 2 * value when 'avg_fraction_cadence' @avg_running_cadence += 2 * value when 'total_training_effect' @training_effect = value when 'first_lap_index' @first_lap_index = value when 'num_laps' @num_laps = value else end end |
#to_s ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fit4ruby/Session.rb', line 88 def to_s "Date: \#{@start_time}\nDistance: \#{'%.2f' % (@distance / 1000.0)} km\nTime: \#{secsToHMS(@duration)}\nAvg Pace: \#{speedToPace(@avg_speed)} min/km\nTotal Ascend: \#{@ascend} m\nTotal Descend: \#{@descent} m\nCalories: \#{@calories} kCal\nAvg HR: \#{@avg_heart_rate} bpm\nMax HR: \#{@max_heart_rate} bpm\nTraining Effect: \#{@training_effect}\nAvg Run Cadence: \#{@avg_running_cadence.round} spm\nAvg Vertical Oscillation: \#{'%.1f' % (@avg_vertical_oscillation / 10)} cm\nAvg Ground Contact Time: \#{@avg_stance_time.round} ms\nAvg Stride Length: \#{'%.2f' % (avg_stride_length / 2)} m\n" end |