Skip to content
A ruby gem for running, cycling, and swimming calculations - pace, mph, projected times, etc.
Ruby JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
build
html
lib
spec
test
.gitignore
.rvmrc
Gemfile
Gemfile.lock
LICENSE
README.rdoc
m26.gemspec
rakefile.rb

README.rdoc

M26

version 1.0.1, released 2014-10-17

A ruby gem for running, cycling, and swimming calculations - pace, mph, projected times, UOM conversions, etc.

The name refers to mile 26, the approximate length of a marathon.

Install

gem install m26

Synopsis

# Units of Measure for Distances
  miles = 'm', kilometers = 'k', yards = 'y'

# Distance objects
  d = M26::Distance.new(6.20)  # same as the following; defaults to miles
  d = M26::Distance.new(6.20, 'm')
  d = M26::Distance.new(10.0, 'k')
  d = M26::Distance.new(1800, 'y')
  d.get_miles      -> 1.0227272727272727
  d.get_kilometers -> 1.6495601173020529
  d.get_yards      -> 1800.0

# ElapsedTime objects - can be constructed from a 'hh:mm:ss' String value
  et = M26::ElapsedTime.new('3:58:33')  # works for average marathoners
  et.as_hours -> 3.9758333333333336     # translates to a Float
  et.as_hhmmss -> 03:58:33.00           # defaults to two decimal positions for the seconds

  et = M26::ElapsedTime.new('3:58:33.789')
  et.as_hours -> 3.9760525
  et.as_hhmmss -> 03:58:33.79

  et = M26::ElapsedTime.new('0:9.58')   # works for Usain Bolt, too
  et.as_hours  -> 0.002661111111111111

# ElapsedTime objects - alternatively constructed from a number of total seconds
  et = M26::ElapsedTime.new(3661.12345)
  et.as_hours -> 1.0169787361111111
  et.as_hhmmss -> 01:01:01.12           # defaults to two decimal positions for the seconds
  et.as_hhmmss(5) -> 01:01:01.12345     # you can specify the number of decimal positions for the seconds

# Speed objects - constructed from a Distance and ElapsedTime
  d  = M26::Distance.new(26.20)
  et = M26::ElapsedTime.new('3:58:33')
  s  = M26::Speed.new(d, et)
  s.get_mph -> 6.58981345629847         # miles per hour
  s.get_kph -> 10.628731381149947       # kilometers per hour
  s.get_yph -> 11598.071683085307       # yards per hour
  s.pace_per_mile -> 9:06.29            # pace per mile

# Speed objects - alternatively constructed from a pace-per-mile 'mm:ss' String value
  s = M26::Speed.from_pace_per_mile('06:00')
  s.get_mph -> 10.0
  s.get_kph -> 16.1290322581
  s.get_yph -> 17600.0
  s.pace_per_mile -> 6:00.0

# Projecting a Speed, with simple extrapolation/interpolation

d1 = M26::Distance.new(26.2)
d2 = M26::Distance.new(20.0)
t  = M26::ElapsedTime.new('03:47:30')
s  = M26::Speed.new(d1, t)
s.projected_time(d2) -> 02:53:39.85

# Projecting a Speed, with pete riegel exponential formula

d1 = M26::Distance.new(26.2)
d2 = M26::Distance.new(20.0)
t  = M26::ElapsedTime.new('03:47:30')
s  = M26::Speed.new(d1, t)
s.projected_time(d2, 'riegel') -> 02:50:52.39

# Averaging two Speeds, such as for Run-Walk calculations

s1  = M26::Speed.from_pace_per_mile('06:00')
t1  = M26::ElapsedTime.new('00:04:00')
s2  = M26::Speed.from_pace_per_mile('18:00')
t2  = M26::ElapsedTime.new('00:04:00')
avg = M26::Speed.calculate_average_speed(s1, s2, t1, t2)
avg.get_mph -> 5.0
avg.pace_per_mile -> 12:00.0

# Age-grading a time to another age

et = M26::ElapsedTime.new('04:08:55')
ag = M26::AgeGrade.new(57.123, 41.789)
ag.calculate(et) -> 03:47:29.93

# Ultramarathon calculations - run and walk and rest/stopped segments

rp  = M26::ElapsedTime.new('00:08:00')  # running pace-per-mile
rt  = M26::ElapsedTime.new('00:04:00')  # running segment time
wp  = M26::ElapsedTime.new('00:16:00')  # walking pace-per-mile
wt  = M26::ElapsedTime.new('00:04:00')  # walking segment time
sth = M26::ElapsedTime.new('00:03:00')  # rest/stopped time per hour
u   = M26::Ultra.new(rp, rt, wp, wt, sth)
u.moving_speed.get_mph  -> 5.970149253731343  # A M26::Speed object is returned reflecting the run & walk
u.overall_speed.get_mph -> 5.671641791044776  # A M26::Speed object is returned reflecting the run & walk & stops

Copyright and License

Copyright 2014, Chris Joakim, JoakimSoftware LLC, <christopher.joakim@gmail.com>.

GNU General Public License (GPLv3) license. See www.gnu.org/copyleft/gpl.html

Something went wrong with that request. Please try again.