Class: Fit4Ruby::Session
- Inherits:
-
FitDataRecord
- Object
- FitDataRecord
- Fit4Ruby::Session
- Includes:
- RecordAggregator
- Defined in:
- lib/fit4ruby/Session.rb
Overview
The Session objects correspond to the session FIT messages. They hold accumlated data for a set of Lap objects.
Constant Summary
Constants inherited from FitDataRecord
Constants included from BDFieldNameTranslator
BDFieldNameTranslator::BD_DICT
Instance Attribute Summary collapse
-
#laps ⇒ Object
readonly
Returns the value of attribute laps.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Attributes inherited from FitDataRecord
Instance Method Summary collapse
-
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
-
#check(activity) ⇒ Object
Perform some basic consistency and logical checks on the object.
-
#has_geo_data? ⇒ Boolean
Return true if the session contains geographical location data.
-
#initialize(laps, first_lap_index, field_values) ⇒ Session
constructor
Create a new Session object.
Methods included from RecordAggregator
#aggregate, #aggregate_ascent_descent, #aggregate_geo_region, #aggregate_heart_rate, #aggregate_speed_distance, #aggregate_stance_time, #aggregate_strides, #aggregate_vertical_oscillation
Methods inherited from FitDataRecord
#<=>, #==, #export, #get, #get_as, #get_unit_by_name, #set, #set_field_values, #write
Methods included from BDFieldNameTranslator
Methods included from Converters
#conversion_factor, #fit_time_to_time, #secsToDHMS, #secsToHM, #secsToHMS, #speedToPace, #time_to_fit_time
Constructor Details
#initialize(laps, first_lap_index, field_values) ⇒ Session
Create a new Session object.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fit4ruby/Session.rb', line 33 def initialize(laps, first_lap_index, field_values) super('session') @meta_field_units['avg_stride_length'] = 'm' @laps = laps @records = [] @laps.each { |lap| @records += lap.records } @first_lap_index = first_lap_index @num_laps = @laps.length if @records.first # Or to the timestamp of the first record. @start_time = @records.first. if @records.last @total_elapsed_time = @records.last. - @start_time end end set_field_values(field_values) end |
Instance Attribute Details
#laps ⇒ Object (readonly)
Returns the value of attribute laps.
26 27 28 |
# File 'lib/fit4ruby/Session.rb', line 26 def laps @laps end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
26 27 28 |
# File 'lib/fit4ruby/Session.rb', line 26 def records @records end |
Instance Method Details
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
78 79 80 81 82 |
# File 'lib/fit4ruby/Session.rb', line 78 def avg_stride_length return nil unless @total_strides @total_distance / (@total_strides * 2.0) end |
#check(activity) ⇒ Object
Perform some basic consistency and logical checks on the object. Errors are reported via the Log object.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fit4ruby/Session.rb', line 55 def check(activity) unless @first_lap_index Log.fatal 'first_lap_index is not set' end unless @num_laps Log.fatal 'num_laps is not set' end @first_lap_index.upto(@first_lap_index - @num_laps) do |i| if (lap = activity.lap[i]) @laps << lap else Log.fatal "Session references lap #{i} which is not contained in " "the FIT file." end end end |
#has_geo_data? ⇒ Boolean
Return true if the session contains geographical location data.
73 74 75 |
# File 'lib/fit4ruby/Session.rb', line 73 def has_geo_data? @swc_long && @swc_lat && @nec_long && nec_lat end |