Class: RunbyPace::PaceData
- Inherits:
-
Object
- Object
- RunbyPace::PaceData
- Defined in:
- lib/runby_pace/pace_data.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) ⇒ Object
Calculate the prescribed pace for the given 5K time.
-
#initialize(fastest_pace_km, slowest_pace_km, midpoint_radius_divisor) ⇒ PaceData
constructor
A new instance of PaceData.
-
#slope ⇒ Object
Calculate the slope of the line between the fastest and slowest paces.
Constructor Details
#initialize(fastest_pace_km, slowest_pace_km, midpoint_radius_divisor) ⇒ PaceData
Returns a new instance of PaceData.
28 29 30 31 32 |
# File 'lib/runby_pace/pace_data.rb', line 28 def initialize(fastest_pace_km, slowest_pace_km, midpoint_radius_divisor) @fastest_pace_km = RunbyPace::PaceTime.new(fastest_pace_km) @slowest_pace_km = RunbyPace::PaceTime.new(slowest_pace_km) @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.
15 16 17 |
# File 'lib/runby_pace/pace_data.rb', line 15 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)
26 27 28 |
# File 'lib/runby_pace/pace_data.rb', line 26 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.
20 21 22 |
# File 'lib/runby_pace/pace_data.rb', line 20 def slowest_pace_km @slowest_pace_km end |
Instance Method Details
#calc(five_k_time, distance_units = :km) ⇒ Object
Calculate the prescribed pace for the given 5K time
40 41 42 43 44 45 46 |
# File 'lib/runby_pace/pace_data.rb', line 40 def calc(five_k_time, distance_units = :km) five_k_time = RunbyPace::PaceTime.new(five_k_time) x2 = ((five_k_time.total_minutes * 2) - (MIDPOINT_X - 1)) - 1 minutes_per_km = slope * x2 + @fastest_pace_km.total_minutes + curve_minutes(x2) minutes_per_unit = minutes_per_km * RunbyPace::PaceUnits.distance_conversion_factor(distance_units) RunbyPace::PaceTime.from_minutes(minutes_per_unit) end |
#slope ⇒ Object
Calculate the slope of the line between the fastest and slowest paces
35 36 37 |
# File 'lib/runby_pace/pace_data.rb', line 35 def slope (@slowest_pace_km.total_minutes - @fastest_pace_km.total_minutes) / (DATA_POINTS_COUNT - 1) end |