Module: Joule::Calculator::MarkerCalculator

Included in:
Base::Parser
Defined in:
lib/joule/calculator/marker_calculator.rb

Instance Method Summary collapse

Instance Method Details

#calculate_marker_averages(marker) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/joule/calculator/marker_calculator.rb', line 5

def calculate_marker_averages(marker)
  marker.average_power = Joule::Calculator::PowerCalculator::average(
    @workout.data_points[marker.start..marker.end].collect() {|v| v.power})

  marker.average_speed = Joule::Calculator::PowerCalculator::average(
    @workout.data_points[marker.start..marker.end].collect() {|v| v.speed})

  marker.average_cadence = Joule::Calculator::PowerCalculator::average(
    @workout.data_points[marker.start..marker.end].collect() {|v| v.cadence})

  marker.average_heartrate = Joule::Calculator::PowerCalculator::average(
    @workout.data_points[marker.start..marker.end].collect() {|v| v.heartrate})
end

#calculate_marker_maximums(marker) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/joule/calculator/marker_calculator.rb', line 19

def calculate_marker_maximums(marker)
  marker.maximum_power = Joule::Calculator::PowerCalculator::maximum(
     @workout.data_points[marker.start..marker.end].collect() {|value| value.power})

   marker.maximum_speed = Joule::Calculator::PowerCalculator::maximum(
     @workout.data_points[marker.start..marker.end].collect() {|value| value.speed})

   marker.maximum_cadence = Joule::Calculator::PowerCalculator::maximum(
     @workout.data_points[marker.start..marker.end].collect() {|value| value.cadence})

   marker.maximum_heartrate = Joule::Calculator::PowerCalculator::maximum(
     @workout.data_points[marker.start..marker.end].collect() {|value| value.heartrate})
end

#calculate_marker_totals(marker, index) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/joule/calculator/marker_calculator.rb', line 39

def calculate_marker_totals(marker, index)
  if(index == 0)
    marker.distance = @workout.data_points.last.distance
    marker.duration_seconds = @workout.data_points.last.time
  else
    if(marker.start == 0)
      marker.distance = @workout.data_points[marker.end].distance - @workout.data_points[marker.start].distance
      marker.duration_seconds = @workout.data_points[marker.end].time - @workout.data_points[marker.start].time
    else
      marker.distance = @workout.data_points[marker.end].distance - @workout.data_points[marker.start - 1].distance
      marker.duration_seconds = @workout.data_points[marker.end].time - @workout.data_points[marker.start - 1].time
    end 
  end
  
  marker.energy = (marker.average_power.round * marker.duration_seconds)/1000        
end

#calculate_marker_training_metrics(marker) ⇒ Object



33
34
35
36
# File 'lib/joule/calculator/marker_calculator.rb', line 33

def calculate_marker_training_metrics(marker)
  marker.normalized_power = Joule::Calculator::PowerCalculator::normalized_power( 
    @workout.data_points[marker.start..marker.end].collect() {|value| value.power}, @workout.properties.record_interval)
end

#calculate_marker_values(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/joule/calculator/marker_calculator.rb', line 56

def calculate_marker_values(options = {})
  @workout.markers.each_with_index { |marker, i|
    calculate_marker_averages marker      
    calculate_marker_maximums marker
    calculate_marker_training_metrics marker
    calculate_marker_totals marker, i  
  }
end