Class: Joule::Calculator::PowerCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/joule/calculator/power_calculator.rb

Class Method Summary collapse

Class Method Details

.average(values) ⇒ Object



4
5
6
# File 'lib/joule/calculator/power_calculator.rb', line 4

def self.average(values)
  values.average
end

.intensity_factor(normalized_power, threshold_power) ⇒ Object



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

def self.intensity_factor(normalized_power, threshold_power)
  if(threshold_power > 0)
    normalized_power/threshold_power
  end
end

.maximum(values) ⇒ Object



8
9
10
# File 'lib/joule/calculator/power_calculator.rb', line 8

def self.maximum(values)
  values.maximum
end

.normalized_power(values, record_interval) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/joule/calculator/power_calculator.rb', line 38

def self.normalized_power(values, record_interval)
  thirty_second_record_count = 30 / record_interval
  thirty_second_rolling_power = Array.new
  if(values.length > thirty_second_record_count)
    values.slice(thirty_second_record_count..-1).each_slice(thirty_second_record_count) { |s|
      thirty_second_rolling_power << s.average ** 4
    }
    thirty_second_rolling_power.average ** 0.25
  else
    0
  end
end

.peak_power(array, duration, size) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/joule/calculator/power_calculator.rb', line 16

def self.peak_power(array, duration, size)
  average_maximum = array.average_maximum size
  peak_power = PeakPower.new(duration)
  peak_power.start = average_maximum[:start]
  peak_power.value = average_maximum[:value]
  peak_power
end

.total(values) ⇒ Object



12
13
14
# File 'lib/joule/calculator/power_calculator.rb', line 12

def self.total(values)
  values.sum
end

.training_stress_score(duration_seconds, normalized_power, threshold_power) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/joule/calculator/power_calculator.rb', line 24

def self.training_stress_score(duration_seconds, normalized_power, threshold_power)
  if(threshold_power > 0)
    normalized_work = normalized_power * duration_seconds
    raw_training_stress_score = normalized_work * intensity_factor(normalized_power, threshold_power)
    (raw_training_stress_score/(threshold_power * 3600)) * 100
  end
end