Class: RunbyPace::PaceData

Inherits:
Object
  • Object
show all
Defined in:
lib/runby_pace/pace_data.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(fastest_pace_km, slowest_pace_km, midpoint_radius_divisor) ⇒ PaceData

Returns a new instance of PaceData.



29
30
31
32
33
# File 'lib/runby_pace/pace_data.rb', line 29

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_kmObject (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.


16
17
18
# File 'lib/runby_pace/pace_data.rb', line 16

def fastest_pace_km
  @fastest_pace_km
end

#midpoint_radius_divisorObject (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)


27
28
29
# File 'lib/runby_pace/pace_data.rb', line 27

def midpoint_radius_divisor
  @midpoint_radius_divisor
end

#slowest_pace_kmObject (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.


21
22
23
# File 'lib/runby_pace/pace_data.rb', line 21

def slowest_pace_km
  @slowest_pace_km
end

Instance Method Details

#calc(five_k_time) ⇒ Object

Calculate the prescribed pace for the given 5K time



41
42
43
44
45
# File 'lib/runby_pace/pace_data.rb', line 41

def calc(five_k_time)
  five_k_time = RunbyPace::PaceTime.new(five_k_time)
  x2 = ((five_k_time.total_minutes * 2) - (MIDPOINT_X - 1)) - 1
  RunbyPace::PaceTime.from_minutes(slope * x2 + @fastest_pace_km.total_minutes + curve_minutes(x2))
end

#slopeObject

Calculate the slope of the line between the fastest and slowest paces



36
37
38
# File 'lib/runby_pace/pace_data.rb', line 36

def slope
  (@slowest_pace_km.total_minutes - @fastest_pace_km.total_minutes) / (DATA_POINTS_COUNT - 1)
end