runby_pace 0.6.146 → 0.6.147
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 +4 -4
- data/lib/runby_pace/distance_unit.rb +1 -0
- data/lib/runby_pace/pace.rb +1 -1
- data/lib/runby_pace/pace_calculator.rb +15 -8
- data/lib/runby_pace/parameter_sanitizer.rb +26 -0
- data/lib/runby_pace/run_math.rb +3 -3
- data/lib/runby_pace/speed_range.rb +1 -1
- data/lib/runby_pace/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23743b3322eb2563d9bacaf2d940fb3dd3ba7e4
|
4
|
+
data.tar.gz: a3185adb6de60b111f7dc12727f3407638f94cf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 426b99ff4fc2dfac2252bfc7b99f5f6ce720686f28cd7196f4fdcf236d147c406d5d287594ad7839296ffa5990a7f2d0eb7db973b719bb4e58c753caafd4e487
|
7
|
+
data.tar.gz: 9e39d983f87a91430e0d04aee92200f3208810e5752bdf638791527830b2445d4fee1ab04c7b42b67a1c16657fd12c5344fecdb4f12b3482d41a333238c49384
|
data/lib/runby_pace/pace.rb
CHANGED
@@ -117,7 +117,7 @@ module Runby
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def distance_covered_over_time(time)
|
120
|
-
time =
|
120
|
+
time = sanitize_arg(time).as(RunbyTime)
|
121
121
|
if time.total_minutes.zero? || @distance.multiplier.zero?
|
122
122
|
return Runby::Distance.new(@distance.uom, 0)
|
123
123
|
end
|
@@ -41,19 +41,26 @@ module Runby
|
|
41
41
|
# Calculate the prescribed pace for the given 5K time
|
42
42
|
# @return [Pace]
|
43
43
|
def calc(five_k_time, distance_units = :km)
|
44
|
-
five_k_time =
|
45
|
-
distance_units =
|
46
|
-
|
47
|
-
|
48
|
-
minutes_per_unit
|
44
|
+
five_k_time = sanitize_arg(five_k_time).as(RunbyTime)
|
45
|
+
distance_units = sanitize_arg(distance_units).as(DistanceUnit)
|
46
|
+
|
47
|
+
minutes_per_unit = calculate_minutes_per_unit(distance_units, five_k_time)
|
48
|
+
build_pace minutes_per_unit, distance_units
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
49
52
|
|
50
|
-
|
53
|
+
def build_pace(minutes_per_unit, distance_units)
|
51
54
|
time = RunbyTime.from_minutes(minutes_per_unit)
|
52
55
|
distance = Distance.new distance_units, 1
|
53
56
|
Pace.new time, distance
|
54
57
|
end
|
55
58
|
|
56
|
-
|
59
|
+
def calculate_minutes_per_unit(distance_units, five_k_time)
|
60
|
+
x2 = ((five_k_time.total_minutes * 2) - (MIDPOINT_X - 1)) - 1
|
61
|
+
minutes_per_km = slope * x2 + @fastest_pace_km.time.total_minutes + curve_minutes(x2)
|
62
|
+
minutes_per_km * distance_units.conversion_factor
|
63
|
+
end
|
57
64
|
|
58
65
|
# Since the paces for each 5K time do not progress in a straight line
|
59
66
|
# when plotted on a graph, but rather a curve with its highest point near
|
@@ -69,7 +76,7 @@ module Runby
|
|
69
76
|
midpoint = MIDPOINT_X
|
70
77
|
if midpoint_reduction > midpoint
|
71
78
|
midpoint_reduction = midpoint - (midpoint_reduction - midpoint)
|
72
|
-
midpoint_reduction = 0 if midpoint_reduction
|
79
|
+
midpoint_reduction = 0 if midpoint_reduction.negative?
|
73
80
|
end
|
74
81
|
# TODO: Use an actual curve instead of a triangle to calculate the number of minutes to add.
|
75
82
|
midpoint_reduction / @midpoint_radius_divisor / 60
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def sanitize_arg(parameter)
|
4
|
+
Runby::ParameterSanitizer.sanitize(parameter)
|
5
|
+
end
|
6
|
+
|
7
|
+
module Runby
|
8
|
+
# Sanitizes method parameters
|
9
|
+
class ParameterSanitizer
|
10
|
+
attr_reader :parameter
|
11
|
+
|
12
|
+
def initialize(parameter)
|
13
|
+
@parameter = parameter
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.sanitize(parameter)
|
17
|
+
ParameterSanitizer.new parameter
|
18
|
+
end
|
19
|
+
|
20
|
+
def as(type)
|
21
|
+
return @parameter if @parameter.is_a?(type)
|
22
|
+
raise "Unable to sanitize parameter of type #{type}. Missing 'parse' method." unless type.respond_to? :parse
|
23
|
+
type.parse(@parameter)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/runby_pace/run_math.rb
CHANGED
@@ -4,9 +4,9 @@ module Runby
|
|
4
4
|
# An assortment of mathematical functions related to running.
|
5
5
|
class RunMath
|
6
6
|
def self.predict_race_time(race1_distance, race1_time, target_distance)
|
7
|
-
race1_distance =
|
8
|
-
race1_time =
|
9
|
-
target_distance =
|
7
|
+
race1_distance = sanitize_arg(race1_distance).as(Distance)
|
8
|
+
race1_time = sanitize_arg(race1_time).as(RunbyTime)
|
9
|
+
target_distance = sanitize_arg(target_distance).as(Distance)
|
10
10
|
|
11
11
|
race1_time * (target_distance / race1_distance)**1.06
|
12
12
|
end
|
@@ -23,7 +23,7 @@ module Runby
|
|
23
23
|
else
|
24
24
|
fast_multiplier = format('%g', @fast.distance.multiplier.round(2))
|
25
25
|
slow_multiplier = format('%g', @slow.distance.multiplier.round(2))
|
26
|
-
@fast.to_s(format: format).sub(
|
26
|
+
@fast.to_s(format: format).sub(fast_multiplier.to_s, "#{fast_multiplier}-#{slow_multiplier}")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/runby_pace/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runby_pace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.147
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Walls
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/runby_pace/pace.rb
|
80
80
|
- lib/runby_pace/pace_calculator.rb
|
81
81
|
- lib/runby_pace/pace_range.rb
|
82
|
+
- lib/runby_pace/parameter_sanitizer.rb
|
82
83
|
- lib/runby_pace/run_math.rb
|
83
84
|
- lib/runby_pace/run_type.rb
|
84
85
|
- lib/runby_pace/run_types/all_run_types.g.rb
|
@@ -105,7 +106,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
105
106
|
licenses:
|
106
107
|
- MIT
|
107
108
|
metadata:
|
108
|
-
commit-hash:
|
109
|
+
commit-hash: d8811ae095d9919ea5393bf0e6c93de27ae324f3
|
109
110
|
post_install_message:
|
110
111
|
rdoc_options: []
|
111
112
|
require_paths:
|