Class: Runby::PaceCalculator
- Inherits:
-
Object
- Object
- Runby::PaceCalculator
- Defined in:
- lib/runby_pace/pace_calculator.rb
Overview
Encapsulates the algorithms used to calculate target paces.
Constant Summary collapse
- DATA_POINTS_COUNT =
The number of data points plotted on our line of 5K times.
We take 5K times from 14:00 to 42:00 with a sample rate of 30 seconds, and out pops 57.
57
- MIDPOINT_X =
The midpoint along the X axis of our pace data “graph”
28
Instance Attribute Summary collapse
-
#fastest_pace_km ⇒ Object
readonly
The fastest pace within the run type data set.
-
#midpoint_radius_divisor ⇒ Object
readonly
For maximum flexibility, we assume the radius of the curve of the pace data to be equal to the X axis midpoint, a perfect circle.
-
#slowest_pace_km ⇒ Object
readonly
The slowest pace for the run type data set.
Instance Method Summary collapse
-
#calc(five_k_time, distance_units = :km) ⇒ Pace
Calculate the prescribed pace for the given 5K time.
-
#initialize(golden_pace_set, midpoint_radius_divisor) ⇒ PaceCalculator
constructor
A new instance of PaceCalculator.
-
#slope ⇒ Object
Calculate the slope of the line between the fastest and slowest paces.
Constructor Details
#initialize(golden_pace_set, midpoint_radius_divisor) ⇒ PaceCalculator
Returns a new instance of PaceCalculator.
30 31 32 33 34 |
# File 'lib/runby_pace/pace_calculator.rb', line 30 def initialize(golden_pace_set, midpoint_radius_divisor) @fastest_pace_km = golden_pace_set.fastest @slowest_pace_km = golden_pace_set.slowest @midpoint_radius_divisor = midpoint_radius_divisor end |
Instance Attribute Details
#fastest_pace_km ⇒ Object (readonly)
The fastest pace within the run type data set.
Given a personal record of 14 minutes for a 5K race,
this is the prescribed pace for this run type.
17 18 19 |
# File 'lib/runby_pace/pace_calculator.rb', line 17 def fastest_pace_km @fastest_pace_km end |
#midpoint_radius_divisor ⇒ Object (readonly)
For maximum flexibility, we assume the radius of the curve
of the pace data to be equal to the X axis midpoint, a perfect circle.
Use the midpoint_radius_divisor to reduce the height of the curve
until it matches that of the data. (See #curve_minutes)
28 29 30 |
# File 'lib/runby_pace/pace_calculator.rb', line 28 def midpoint_radius_divisor @midpoint_radius_divisor end |
#slowest_pace_km ⇒ Object (readonly)
The slowest pace for the run type data set.
Given a personal record of 42 minutes for a 5K race,
this is the prescribed pace for this run type.
22 23 24 |
# File 'lib/runby_pace/pace_calculator.rb', line 22 def slowest_pace_km @slowest_pace_km end |
Instance Method Details
#calc(five_k_time, distance_units = :km) ⇒ Pace
Calculate the prescribed pace for the given 5K time
43 44 45 46 47 48 49 |
# File 'lib/runby_pace/pace_calculator.rb', line 43 def calc(five_k_time, distance_units = :km) five_k_time = Runby.sanitize(five_k_time).as(RunbyTime) distance_units = Runby.sanitize(distance_units).as(DistanceUnit) minutes_per_unit = calculate_minutes_per_unit(distance_units, five_k_time) build_pace minutes_per_unit, distance_units end |
#slope ⇒ Object
Calculate the slope of the line between the fastest and slowest paces
37 38 39 |
# File 'lib/runby_pace/pace_calculator.rb', line 37 def slope (@slowest_pace_km.time.total_minutes - @fastest_pace_km.time.total_minutes) / (DATA_POINTS_COUNT - 1) end |