Class: Fit4Ruby::Session

Inherits:
FitDataRecord show all
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

FitDataRecord::RecordOrder

Constants included from BDFieldNameTranslator

BDFieldNameTranslator::BD_DICT

Instance Attribute Summary collapse

Attributes inherited from FitDataRecord

#message, #timestamp

Instance Method Summary collapse

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

#to_bd_field_name

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.

Parameters:

  • laps (Array of Laps)

    Laps to associate with the Session.

  • first_lap_index (Fixnum)

    Index of the first Lap in this Session.

  • field_values (Hash)

    Hash that provides initial values for certain fields.



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.timestamp
    if @records.last
      @total_elapsed_time = @records.last.timestamp - @start_time
    end
  end

  set_field_values(field_values)
end

Instance Attribute Details

#lapsObject (readonly)

Returns the value of attribute laps.



26
27
28
# File 'lib/fit4ruby/Session.rb', line 26

def laps
  @laps
end

#recordsObject (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_lengthObject

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.

Returns:

  • (Boolean)


73
74
75
# File 'lib/fit4ruby/Session.rb', line 73

def has_geo_data?
  @swc_long && @swc_lat && @nec_long && nec_lat
end