Module: CameronPredictor

Included in:
Calcpace
Defined in:
lib/calcpace/cameron_predictor.rb

Overview

Module for predicting race times using the Cameron formula

An alternative to the Riegel formula (RacePredictor module) that uses an exponential correction to better account for physiological differences across distances. The correction is larger when predicting from shorter races, where anaerobic contribution is greater, and diminishes as the known distance approaches the target distance.

Formula: T2 = T1 × (D2/D1) × [(a + b × e^(-D1/c)) / (a + b × e^(-D2/c))]

Constants (calibrated for distances in km):

a = 0.000495
b = 0.000985
c = 1.4485

Reference: Dave Cameron, “A Critical Examination of Racing Predictions” (1997)

Constant Summary collapse

CAMERON_A =

Cameron formula constants (calibrated for distances in km)

0.000495
CAMERON_B =
0.000985
CAMERON_C =
1.4485

Instance Method Summary collapse

Instance Method Details

#predict_pace_cameron(from_race, from_time, to_race) ⇒ Float

Predicts pace per kilometer using the Cameron formula

Examples:

predict_pace_cameron('5k', '00:20:00', 'marathon')
#=> ~255.1 (approximately 4:15/km)

Parameters:

  • from_race (String, Symbol)

    known race distance

  • from_time (String, Numeric)

    time achieved at known distance

  • to_race (String, Symbol)

    target race distance to predict

Returns:

  • (Float)

    predicted pace in seconds per kilometer



81
82
83
# File 'lib/calcpace/cameron_predictor.rb', line 81

def predict_pace_cameron(from_race, from_time, to_race)
  predict_time_cameron(from_race, from_time, to_race) / race_distance(to_race)
end

#predict_pace_cameron_clock(from_race, from_time, to_race) ⇒ String

Predicts pace per kilometer using the Cameron formula, returned as a clock time string

Examples:

predict_pace_cameron_clock('5k', '00:20:00', 'marathon')
#=> '00:02:32'

Parameters:

  • from_race (String, Symbol)

    known race distance

  • from_time (String, Numeric)

    time achieved at known distance

  • to_race (String, Symbol)

    target race distance to predict

Returns:

  • (String)

    predicted pace in HH:MM:SS format



95
96
97
# File 'lib/calcpace/cameron_predictor.rb', line 95

def predict_pace_cameron_clock(from_race, from_time, to_race)
  convert_to_clocktime(predict_pace_cameron(from_race, from_time, to_race))
end

#predict_time_cameron(from_race, from_time, to_race) ⇒ Float

Predicts race time using the Cameron formula

Examples:

Predict marathon time from 10K

predict_time_cameron('10k', '00:42:00', 'marathon')
#=> ~10,666 seconds (approximately 2:57:46)

Predict 10K time from 5K

predict_time_cameron('5k', '00:20:00', '10k')
#=> ~2,544 seconds (approximately 42:24)

Parameters:

  • from_race (String, Symbol)

    known race distance (‘5k’, ‘10k’, ‘half_marathon’, ‘marathon’, ‘100k’, etc.)

  • from_time (String, Numeric)

    time achieved at known distance (HH:MM:SS or seconds)

  • to_race (String, Symbol)

    target race distance to predict

Returns:

  • (Float)

    predicted time in seconds

Raises:

  • (ArgumentError)

    if races are invalid or distances are the same



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/calcpace/cameron_predictor.rb', line 40

def predict_time_cameron(from_race, from_time, to_race)
  from_distance = race_distance(from_race)
  to_distance   = race_distance(to_race)

  if from_distance == to_distance
    raise ArgumentError,
          "From and to races must be different distances (both are #{from_distance}km)"
  end

  time_seconds = from_time.is_a?(String) ? convert_to_seconds(from_time) : from_time
  check_positive(time_seconds, 'Time')

  # Cameron formula: T2 = T1 × (D2/D1) × [cameron_factor(D1) / cameron_factor(D2)]
  time_seconds * (to_distance / from_distance) *
    (cameron_factor(from_distance) / cameron_factor(to_distance))
end

#predict_time_cameron_clock(from_race, from_time, to_race) ⇒ String

Predicts race time using the Cameron formula, returned as a clock time string

Examples:

predict_time_cameron_clock('10k', '00:42:00', 'marathon')
#=> '02:57:46'

Parameters:

  • from_race (String, Symbol)

    known race distance

  • from_time (String, Numeric)

    time achieved at known distance

  • to_race (String, Symbol)

    target race distance to predict

Returns:

  • (String)

    predicted time in HH:MM:SS format



67
68
69
# File 'lib/calcpace/cameron_predictor.rb', line 67

def predict_time_cameron_clock(from_race, from_time, to_race)
  convert_to_clocktime(predict_time_cameron(from_race, from_time, to_race))
end