stressfactor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +8 -0
- data/bin/stressfactor +27 -0
- data/examples/data/sample.gpx +246 -0
- data/examples/load_gpx.rb +5 -0
- data/lib/stressfactor.rb +14 -0
- data/lib/stressfactor/average_pace_accumulator.rb +24 -0
- data/lib/stressfactor/gpx_loader.rb +39 -0
- data/lib/stressfactor/grade_adjusted_pace_strategy.rb +24 -0
- data/lib/stressfactor/interval.rb +35 -0
- data/lib/stressfactor/pace_calculator.rb +24 -0
- data/lib/stressfactor/pace_strategy.rb +11 -0
- data/lib/stressfactor/raw_pace_strategy.rb +14 -0
- data/lib/stressfactor/stress_calculator.rb +29 -0
- data/lib/stressfactor/version.rb +3 -0
- data/scripts/analyze_sample_gpx.rb +7 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/stressfactor/gpx_loader_spec.rb +59 -0
- data/spec/stressfactor/grade_adjusted_pace_strategy_spec.rb +55 -0
- data/spec/stressfactor/interval_spec.rb +51 -0
- data/spec/stressfactor/pace_calculator_spec.rb +68 -0
- data/spec/stressfactor/raw_pace_strategy_spec.rb +47 -0
- data/spec/stressfactor/stress_calculator_spec.rb +34 -0
- data/stressfactor.gemspec +29 -0
- metadata +181 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Stressfactor::PaceCalculator do
|
4
|
+
let(:gpx_loader) { double("loader", intervals: intervals) }
|
5
|
+
let(:intervals) do
|
6
|
+
[Stressfactor::Interval.new(p1, p2),
|
7
|
+
Stressfactor::Interval.new(p2, p3)]
|
8
|
+
end
|
9
|
+
let(:end_time) { Time.now }
|
10
|
+
let(:p1) do
|
11
|
+
GPX::TrackPoint.new(
|
12
|
+
:lat => 37.7985474,
|
13
|
+
:lon => -122.2554386,
|
14
|
+
:elevation => 10.0,
|
15
|
+
:time => end_time - 10
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:p2) do
|
20
|
+
GPX::TrackPoint.new(
|
21
|
+
:lat => 37.7985583,
|
22
|
+
:lon => -122.2554564,
|
23
|
+
:elevation => 15.0,
|
24
|
+
:time => end_time - 3
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:p3) do
|
29
|
+
GPX::TrackPoint.new(
|
30
|
+
:lat => 37.7986548,
|
31
|
+
:lon => -122.2555806,
|
32
|
+
:elevation => 10.0,
|
33
|
+
:time => end_time
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
subject { described_class.new(gpx_loader) }
|
38
|
+
|
39
|
+
describe "#calculate" do
|
40
|
+
it "returns the standard (raw) pace without elevation data in minutes/km" do
|
41
|
+
expected_pace = 9.643387311498394
|
42
|
+
pace = subject.calculate(strategy: :raw, units: :metric)
|
43
|
+
expect(pace).to eq(expected_pace)
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with grade adjusted pace" do
|
47
|
+
it "returns the GAP using the GAP calculator" do
|
48
|
+
expected_gap_pace = 4.250092836947296
|
49
|
+
pace = subject.calculate(strategy: :grade_adjusted, units: :metric)
|
50
|
+
expect(pace).to eq expected_gap_pace
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with english metrics" do
|
55
|
+
it "returns raw pace in min/mi" do
|
56
|
+
expected_pace = 15.519532310806898
|
57
|
+
pace = subject.calculate(strategy: :raw, units: :english)
|
58
|
+
expect(pace).to eq expected_pace
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns GAP pace in min/mi" do
|
62
|
+
expected_pace = 6.839863522673726
|
63
|
+
pace = subject.calculate(strategy: :grade_adjusted, units: :english)
|
64
|
+
expect(pace).to eq expected_pace
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Stressfactor::RawPaceStrategy do
|
4
|
+
let(:points) { [p1, p2, p3] }
|
5
|
+
let(:end_time) { Time.now }
|
6
|
+
let(:p1) do
|
7
|
+
GPX::TrackPoint.new(
|
8
|
+
:lat => 37.7985474,
|
9
|
+
:lon => -122.2554386,
|
10
|
+
:elevation => 10.0,
|
11
|
+
:time => end_time - 10
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:p2) do
|
16
|
+
GPX::TrackPoint.new(
|
17
|
+
:lat => 37.7985583,
|
18
|
+
:lon => -122.2554564,
|
19
|
+
:elevation => 15.0,
|
20
|
+
:time => end_time - 3
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:p3) do
|
25
|
+
GPX::TrackPoint.new(
|
26
|
+
:lat => 37.7986548,
|
27
|
+
:lon => -122.2555806,
|
28
|
+
:elevation => 10.0,
|
29
|
+
:time => end_time
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:intervals) do
|
34
|
+
[Stressfactor::Interval.new(p1, p2),
|
35
|
+
Stressfactor::Interval.new(p2, p3)]
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { described_class.new(intervals) }
|
39
|
+
|
40
|
+
describe "#calculate" do
|
41
|
+
it "returns the standard (raw) pace without elevation data in minutes/km" do
|
42
|
+
pace = subject.calculate
|
43
|
+
expected_pace = 9.643387311498394
|
44
|
+
expect(pace).to eq(expected_pace)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Stressfactor::StressCalculator do
|
4
|
+
# use 5k pace
|
5
|
+
# 19min / 5k = 3.8 m/km
|
6
|
+
let(:threshold_pace) { 3.8 }
|
7
|
+
let(:gpx) { "gpx file" }
|
8
|
+
let(:normalized_graded_pace) { 3.0 }
|
9
|
+
let(:total_time) { 3600 }
|
10
|
+
let(:loader) { double('loader', :total_time => total_time) } #Stressfactor::GpxLoader.new(gpx) }
|
11
|
+
subject { described_class.new(threshold_pace: threshold_pace, loader: loader) }
|
12
|
+
|
13
|
+
describe "#calculate" do
|
14
|
+
it "returns a number" do
|
15
|
+
expect_any_instance_of(Stressfactor::PaceCalculator).to \
|
16
|
+
receive(:calculate).with(strategy: :grade_adjusted, units: :metric).\
|
17
|
+
and_return(normalized_graded_pace)
|
18
|
+
expect(subject.calculate).to be_kind_of Numeric
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the calculation" do
|
22
|
+
expect_any_instance_of(Stressfactor::PaceCalculator).to \
|
23
|
+
receive(:calculate).with(strategy: :grade_adjusted, units: :metric).\
|
24
|
+
and_return(normalized_graded_pace)
|
25
|
+
expect(loader).to \
|
26
|
+
receive(:total_time).\
|
27
|
+
at_least(1).\
|
28
|
+
and_return(total_time)
|
29
|
+
intensity_factor = normalized_graded_pace / threshold_pace
|
30
|
+
expected_score = 62.326869806094194
|
31
|
+
expect(subject.calculate).to eq expected_score
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stressfactor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "stressfactor"
|
8
|
+
spec.version = Stressfactor::VERSION
|
9
|
+
spec.authors = ["Andrew Hao"]
|
10
|
+
spec.email = ["andrewhao@gmail.com"]
|
11
|
+
spec.summary = %q{GPX library to generate training stress scores from GPX files.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# See Gemfile
|
21
|
+
spec.add_dependency "andrewhao-gpx", "~> 0.7"
|
22
|
+
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
26
|
+
spec.add_development_dependency "thor", "~> 0.19.1"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stressfactor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: andrewhao-gpx
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.19.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.19.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- andrewhao@gmail.com
|
114
|
+
executables:
|
115
|
+
- stressfactor
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".ruby-version"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- Guardfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/stressfactor
|
129
|
+
- examples/data/sample.gpx
|
130
|
+
- examples/load_gpx.rb
|
131
|
+
- lib/stressfactor.rb
|
132
|
+
- lib/stressfactor/average_pace_accumulator.rb
|
133
|
+
- lib/stressfactor/gpx_loader.rb
|
134
|
+
- lib/stressfactor/grade_adjusted_pace_strategy.rb
|
135
|
+
- lib/stressfactor/interval.rb
|
136
|
+
- lib/stressfactor/pace_calculator.rb
|
137
|
+
- lib/stressfactor/pace_strategy.rb
|
138
|
+
- lib/stressfactor/raw_pace_strategy.rb
|
139
|
+
- lib/stressfactor/stress_calculator.rb
|
140
|
+
- lib/stressfactor/version.rb
|
141
|
+
- scripts/analyze_sample_gpx.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/stressfactor/gpx_loader_spec.rb
|
144
|
+
- spec/stressfactor/grade_adjusted_pace_strategy_spec.rb
|
145
|
+
- spec/stressfactor/interval_spec.rb
|
146
|
+
- spec/stressfactor/pace_calculator_spec.rb
|
147
|
+
- spec/stressfactor/raw_pace_strategy_spec.rb
|
148
|
+
- spec/stressfactor/stress_calculator_spec.rb
|
149
|
+
- stressfactor.gemspec
|
150
|
+
homepage: ''
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.2.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: GPX library to generate training stress scores from GPX files.
|
174
|
+
test_files:
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/stressfactor/gpx_loader_spec.rb
|
177
|
+
- spec/stressfactor/grade_adjusted_pace_strategy_spec.rb
|
178
|
+
- spec/stressfactor/interval_spec.rb
|
179
|
+
- spec/stressfactor/pace_calculator_spec.rb
|
180
|
+
- spec/stressfactor/raw_pace_strategy_spec.rb
|
181
|
+
- spec/stressfactor/stress_calculator_spec.rb
|