Class: Fit4Ruby::Lap

Inherits:
FitDataRecord show all
Includes:
RecordAggregator
Defined in:
lib/fit4ruby/Lap.rb

Instance Attribute Summary collapse

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

#<=>, #==, #get, #get_as, #inspect, #set, #set_field_values, #write

Methods included from Converters

#conversion_factor, #fit_time_to_time, #secsToDHMS, #secsToHMS, #speedToPace, #time_to_fit_time

Constructor Details

#initialize(records, previous_lap, field_values) ⇒ Lap



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fit4ruby/Lap.rb', line 24

def initialize(records, previous_lap, field_values)
  super('lap')
  @meta_field_units['avg_stride_length'] = 'm'
  @records = records
  @previous_lap = previous_lap

  if previous_lap && previous_lap.records && previous_lap.records.last
    # Set the start time of the new lap to the timestamp of the last record
    # of the previous lap.
    @start_time = previous_lap.records.last.timestamp
  elsif records.first
    # Or to the timestamp of the first record.
    @start_time = records.first.timestamp
  end

  if records.last
    @total_elapsed_time = records.last.timestamp - @start_time
  end

  set_field_values(field_values)
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



22
23
24
# File 'lib/fit4ruby/Lap.rb', line 22

def records
  @records
end

Instance Method Details

#avg_stride_lengthObject

Compute the average stride length for this Session.



65
66
67
68
69
# File 'lib/fit4ruby/Lap.rb', line 65

def avg_stride_length
  return nil unless @total_distance && @total_strides

  @total_distance / (@total_strides * 2.0)
end

#checkObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fit4ruby/Lap.rb', line 46

def check
  ts = Time.parse('1989-12-31')
  distance = nil
  @records.each do |r|
    Log.error "Record has no timestamp" unless r.timestamp
    if r.timestamp < ts
      Log.error "Record has earlier timestamp than previous record"
    end
    if r.distance
      if distance && r.distance < distance
        Log.error "Record has smaller distance than previous record"
      end
      distance = r.distance
    end
    ts = r.timestamp
  end
end