class Fit4Ruby::Session

The Session objects correspond to the session FIT messages. They hold accumlated data for a set of Lap objects.

Attributes

laps[R]
records[R]

Public Class Methods

new(laps, first_lap_index, field_values) click to toggle source

Create a new Session object. @param laps [Array of Laps] Laps to associate with the Session. @param first_lap_index [Fixnum] Index of the first Lap in this Session. @param field_values [Hash] Hash that provides initial values for certain

fields.
Calls superclass method Fit4Ruby::FitDataRecord::new
# 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.timestamp
    if @records.last
      @total_elapsed_time = @records.last.timestamp - @start_time
    end
  end

  set_field_values(field_values)
end

Public Instance Methods

avg_stride_length() click to toggle source

Compute the average stride length for this Session.

# 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) click to toggle source

Perform some basic consistency and logical checks on the object. Errors are reported via the Log object.

# 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?() click to toggle source

Return true if the session contains geographical location data.

# File lib/fit4ruby/Session.rb, line 73
def has_geo_data?
  @swc_long && @swc_lat && @nec_long && nec_lat
end