runby_pace 0.6.94 → 0.6.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmNhZWE5YjE0YmI5MzQxZGUxNDBjZjk0MWRiNzRkYmViYTY1ZTJkMg==
4
+ NTRjNzMyZmIwMThhMWViYjIyODYyYzAwMTQ5MjU5OTRjYmYwZDRmNA==
5
5
  data.tar.gz: !binary |-
6
- YmUzY2JjOWQ4YWRlZTlhYWRiMjZiMDU0YTFjNDVmNWExYmQwOTE5MQ==
6
+ MWEwZTc3MzBkMjMwMDUyMjlkOWQ1OTI1ODk2MTdkY2ZmNTczMmNlMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWY1NTBhOGU1M2FiOTA0ZTliM2E5YjUwM2MxZWQwNjgzMGNmYjBjNWM5YzIw
10
- Mjc3NTFiOGM3YzVjYzMzOTg5NmZjNjZmODUxYzIwYWU1NmZkYTkxYTcyNGU1
11
- NWVjMzg3NGZjNGJmMGMxMzMxYjlkYzYwMWRhNjkwZWYxMzVkM2Q=
9
+ MmE2ZDQ5NDAwYzFiMTFkNDA0OTlmNDI4NjE0OThiZDA5MDY1MWQzNWE2YjJl
10
+ YmYzYTYxZmZiNDNhODM4Nzg0ZjI0ZjFmNmVjYTNhYjUxM2IxYjhkOTQyOGQw
11
+ OGUxYmUxN2M5ZDkyNzE4ZTJkNWNmYzhjZGY1NTI0OWU5MTYxNTM=
12
12
  data.tar.gz: !binary |-
13
- MDQ4ZmYwYTU2ZTI3ZGE3YzkxZjlhZGIwNjY5ZGRjNDU4M2FmMWVhNzFhYmI4
14
- YTA0ZTc0ODYwZTBhMDFiMWY0ZjkwZjI1Y2IzMmE3Mzg4NmMxZTU3M2Q4ZDBk
15
- ZjQ3ZTE0NGNiODM4ZDlhM2VkMTIxYmY0NTg2ZjNkZDgzNzA0Y2U=
13
+ MmVjMTU4Y2JjNWUzMGE4MzNiOGMwMjFlYzMzNzZhODI2MzI1Y2RjNmM0ZWNm
14
+ OTVlMTk2YTY5NjI2OTlkNzM2MDcxNjNhZWNmNDA4YTk0N2QxZDRmZDBlYmU3
15
+ ZDAyNjg4ZGY4OTg2YjgwMmFiZjhmMWY3NmUxMjc2MjkxNzc3YmY=
@@ -0,0 +1,48 @@
1
+ module Runby
2
+
3
+ # Maps a set of 5K race times with their pre-calculated pace recommendations.
4
+ # This is useful in testing as well as defining the fastest and slowest supported 5K times.
5
+ # GoldenPaceSet could conceivably be used to pre-compute a large number of recommended paces,
6
+ # thus reducing runtime CPU overhead.
7
+ class GoldenPaceSet
8
+ include Enumerable
9
+
10
+ attr_reader :paces
11
+
12
+ # The fastest 5K time supported by RunbyPace
13
+ @@FASTEST_5K = :'14:00'
14
+
15
+ # The slowest 5K time supported by RunbyPace
16
+ @@SLOWEST_5K = :'42:00'
17
+
18
+ # @param [Hash] paces_hash is a hash mapping 5K time symbols to times, represented as strings.
19
+ # An example paces_hash is {'14:00':'4:00', '15:00':'4:55'}
20
+ def initialize(paces_hash)
21
+ @paces = {}
22
+ paces_hash.each { |five_k_time, recommended_pace| @paces[five_k_time.to_sym] = Pace.new(recommended_pace) }
23
+ end
24
+
25
+ def each(&block)
26
+ @paces.each do |h, v|
27
+ block.call(h, v)
28
+ end
29
+ end
30
+
31
+ # Returns first/fastest recommended pace in the set
32
+ def first
33
+ @paces[@@FASTEST_5K]
34
+ end
35
+ alias :fastest :first
36
+
37
+ # Return the last/slowest recommended pace in the set
38
+ def last
39
+ @paces[@@SLOWEST_5K]
40
+ end
41
+ alias :slowest :last
42
+
43
+ # Creates and returns a new GoldenPaceSet with only two entries
44
+ def self.new_from_endpoints(fastest, slowest)
45
+ GoldenPaceSet.new({@@FASTEST_5K => fastest, @@SLOWEST_5K => slowest})
46
+ end
47
+ end
48
+ end
@@ -25,9 +25,9 @@ module Runby
25
25
  # until it matches that of the data. (See #curve_minutes)
26
26
  attr_reader :midpoint_radius_divisor
27
27
 
28
- def initialize(fastest_pace_km, slowest_pace_km, midpoint_radius_divisor)
29
- @fastest_pace_km = Pace.new(fastest_pace_km)
30
- @slowest_pace_km = Pace.new(slowest_pace_km)
28
+ def initialize(golden_pace_set, midpoint_radius_divisor)
29
+ @fastest_pace_km = golden_pace_set.fastest
30
+ @slowest_pace_km = golden_pace_set.slowest
31
31
  @midpoint_radius_divisor = midpoint_radius_divisor
32
32
  end
33
33
 
@@ -10,8 +10,8 @@ module Runby
10
10
  end
11
11
 
12
12
  def initialize
13
- @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast[:'14:00'], GoldenPaces.fast[:'42:00'], 3.675)
14
- @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow[:'14:00'], GoldenPaces.slow[:'42:00'], 2.175)
13
+ @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast, 3.675)
14
+ @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow, 2.175)
15
15
  end
16
16
 
17
17
  def lookup_pace(five_k_time, distance_units = :km)
@@ -23,11 +23,11 @@ module Runby
23
23
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
24
24
  class GoldenPaces
25
25
  def self.fast
26
- { '14:00': '03:44', '15:00': '03:58', '20:00': '05:09', '25:00': '06:18', '30:00': '07:24', '35:00': '08:29', '40:00': '09:33', '42:00': '09:58' }
26
+ GoldenPaceSet.new({ '14:00': '03:44', '15:00': '03:58', '20:00': '05:09', '25:00': '06:18', '30:00': '07:24', '35:00': '08:29', '40:00': '09:33', '42:00': '09:58' })
27
27
  end
28
28
 
29
29
  def self.slow
30
- { '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:42', '42:00': '11:10' }
30
+ GoldenPaceSet.new({ '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:42', '42:00': '11:10' })
31
31
  end
32
32
  end
33
33
  end
@@ -9,8 +9,8 @@ module Runby
9
9
  end
10
10
 
11
11
  def initialize
12
- @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast[:'14:00'], GoldenPaces.fast[:'42:00'], 1.99)
13
- @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow[:'14:00'], GoldenPaces.slow[:'42:00'], 1.35)
12
+ @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast, 1.99)
13
+ @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow, 1.35)
14
14
  end
15
15
 
16
16
  def lookup_pace(five_k_time, distance_units = :km)
@@ -22,11 +22,11 @@ module Runby
22
22
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
23
23
  class GoldenPaces
24
24
  def self.fast
25
- { '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:41', '42:00': '11:08' }
25
+ GoldenPaceSet.new({ '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:41', '42:00': '11:08' })
26
26
  end
27
27
 
28
28
  def self.slow
29
- { '14:00': '05:01', '15:00': '05:20', '20:00': '06:51', '25:00': '08:17', '30:00': '09:38', '35:00': '10:56', '40:00': '12:10', '42:00': '12:39' }
29
+ GoldenPaceSet.new({ '14:00': '05:01', '15:00': '05:20', '20:00': '06:51', '25:00': '08:17', '30:00': '09:38', '35:00': '10:56', '40:00': '12:10', '42:00': '12:39' })
30
30
  end
31
31
  end
32
32
  end
@@ -8,22 +8,20 @@ module Runby
8
8
  # This method, #find_divisor, accepts a hash of "golden paces" for a run type along with
9
9
  # the number of seconds of allowable deviation from the golden pace. Then it proceeds
10
10
  # to brute force the divisor.
11
- # @param [Hash] golden_paces
11
+ # @param [GoldenPaceSet] golden_pace_set
12
12
  # @param [String] allowable_deviation
13
13
  # @return [decimal]
14
- def self.find_divisor(golden_paces, allowable_deviation = '00:01')
15
- _, first_pace = golden_paces.first
16
- last_pace = golden_paces[:'42:00']
14
+ def self.find_divisor(golden_pace_set, allowable_deviation = '00:01')
17
15
  viable_divisors = []
18
16
 
19
17
  (1.0..5.0).step(0.025) do |candidate_divisor|
20
18
  viable_divisor = nil
21
19
 
22
- golden_paces.each do |five_k, golden_pace|
20
+ golden_pace_set.each do |five_k, golden_pace|
23
21
  five_k_time = Runby::RunbyTime.new(five_k.to_s)
24
- pace_data = Runby::PaceCalculator.new(first_pace, last_pace, candidate_divisor)
22
+ pace_data = Runby::PaceCalculator.new(golden_pace_set, candidate_divisor)
25
23
  calculated_pace = pace_data.calc(five_k_time)
26
- unless calculated_pace.time.almost_equals?(golden_pace, allowable_deviation)
24
+ unless calculated_pace.time.almost_equals?(golden_pace.time, allowable_deviation)
27
25
  viable_divisor = nil
28
26
  break
29
27
  end
@@ -10,8 +10,8 @@ module Runby
10
10
  end
11
11
 
12
12
  def initialize
13
- @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast[:'14:00'], GoldenPaces.fast[:'42:00'], 2.125)
14
- @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow[:'14:00'], GoldenPaces.slow[:'42:00'], 1.55)
13
+ @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast, 2.125)
14
+ @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow, 1.55)
15
15
  end
16
16
 
17
17
  def lookup_pace(five_k_time, distance_units = :km)
@@ -23,11 +23,11 @@ module Runby
23
23
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
24
24
  class GoldenPaces
25
25
  def self.fast
26
- { '14:00': '04:00', '15:00': '04:16', '20:00': '05:31', '25:00': '06:44', '30:00': '07:54', '35:00': '09:01', '40:00': '10:07', '42:00': '10:32' }
26
+ GoldenPaceSet.new({ '14:00': '04:00', '15:00': '04:16', '20:00': '05:31', '25:00': '06:44', '30:00': '07:54', '35:00': '09:01', '40:00': '10:07', '42:00': '10:32' })
27
27
  end
28
28
 
29
29
  def self.slow
30
- { '14:00': '04:39', '15:00': '04:57', '20:00': '06:22', '25:00': '07:43', '30:00': '09:00', '35:00': '10:15', '40:00': '11:26', '42:00': '11:53' }
30
+ GoldenPaceSet.new({ '14:00': '04:39', '15:00': '04:57', '20:00': '06:22', '25:00': '07:43', '30:00': '09:00', '35:00': '10:15', '40:00': '11:26', '42:00': '11:53' })
31
31
  end
32
32
  end
33
33
  end
@@ -9,8 +9,8 @@ module Runby
9
9
  end
10
10
 
11
11
  def initialize
12
- @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast[:'14:00'], GoldenPaces.fast[:'42:00'], 4.025)
13
- @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow[:'14:00'], GoldenPaces.slow[:'42:00'], 3.725)
12
+ @fast_pace_calculator = PaceCalculator.new(GoldenPaces.fast, 4.025)
13
+ @slow_pace_calculator = PaceCalculator.new(GoldenPaces.slow, 3.725)
14
14
  end
15
15
 
16
16
  def lookup_pace(five_k_time, distance_units = :km)
@@ -22,11 +22,11 @@ module Runby
22
22
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
23
23
  class GoldenPaces
24
24
  def self.fast
25
- { '14:00': '03:07', '15:00': '03:20', '20:00': '04:21', '25:00': '05:20', '30:00': '06:19', '35:00': '07:16', '40:00': '08:12', '42:00': '08:35' }
25
+ GoldenPaceSet.new({ '14:00': '03:07', '15:00': '03:20', '20:00': '04:21', '25:00': '05:20', '30:00': '06:19', '35:00': '07:16', '40:00': '08:12', '42:00': '08:35' })
26
26
  end
27
27
 
28
28
  def self.slow
29
- { '14:00': '03:18', '15:00': '03:31', '20:00': '04:35', '25:00': '05:37', '30:00': '06:38', '35:00': '07:38', '40:00': '08:36', '42:00': '08:59' }
29
+ GoldenPaceSet.new({ '14:00': '03:18', '15:00': '03:31', '20:00': '04:35', '25:00': '05:37', '30:00': '06:38', '35:00': '07:38', '40:00': '08:36', '42:00': '08:59' })
30
30
  end
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runby_pace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.94
4
+ version: 0.6.97
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ty Walls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ files:
75
75
  - lib/runby_pace.rb
76
76
  - lib/runby_pace/distance.rb
77
77
  - lib/runby_pace/distance_unit.rb
78
+ - lib/runby_pace/golden_pace_set.rb
78
79
  - lib/runby_pace/pace.rb
79
80
  - lib/runby_pace/pace_calculator.rb
80
81
  - lib/runby_pace/pace_range.rb
@@ -99,7 +100,7 @@ homepage: https://github.com/tygerbytes/runby-pace
99
100
  licenses:
100
101
  - MIT
101
102
  metadata:
102
- commit-hash: 4801763d3e46a9ae2f309aa80b8c1d9d7a074e15
103
+ commit-hash: 5e1379080b4314c7009d6c63015cc05c607c3aa7
103
104
  post_install_message:
104
105
  rdoc_options: []
105
106
  require_paths: