broutes 0.1.3 → 0.2.0
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 +6 -14
- data/lib/broutes/geo_route.rb +74 -2
- data/lib/broutes/version.rb +1 -1
- data/spec/broutes/formats/fit_file_spec.rb +3 -3
- data/spec/broutes/formats/gpx_track_spec.rb +2 -2
- data/spec/broutes/formats/tcx_spec.rb +24 -3
- data/spec/broutes/geo_route_spec.rb +145 -1
- data/spec/spec_helper.rb +5 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZWRmMTYwMGY1OTQ1ODdhZWY2NjE1MzkyNmFjZDA5MzNlMjMxNmVkMzViMTA5
|
10
|
-
MGI4Yjk0ZTI2YTRkMjgwMDkxZjE5ZWZkMzE3MTQxN2M2YWU2OTAzYTNlMmQ4
|
11
|
-
YmYzM2JlOThiMTkxYzUzNmI2MjlmNDBmNmM5M2YzZWFkYmYzZjI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Y2U5NmE5OWIyMzVhYzA3Y2FlMmNhN2M0MjA5YjdlYTU2NjVjMWQ2MmVkZGUw
|
14
|
-
NzQ4NWY0MTFmMDQwYzNlMjNjZTZlNzVhNTU0ZmNlOTZkNTBlMjZlY2ZkMTM1
|
15
|
-
Y2E5NjEzZWFiNGFmYmM5OTAzNDUxZDc0NDVkNGI4OGFhYTc5MDE=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 515ec9b7e7515cda5606a8b506af2bf15ddc7d8d
|
4
|
+
data.tar.gz: e6d0da5f298f8ca13a41fc243cda655953365922
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f13a1665b145bb5f0013051e91b24c8399c579ed543e932ad710c9c45f4fdef08cb4fe164faa94324839f328696dab8693c715817a26f490d878b411622dd1fd
|
7
|
+
data.tar.gz: cc5c63cec6a7dabc3b3dba62bed7e3fec8b504cd2e8fa318eb364cb08b9b7f15359fc9b4a47fd4ab9a675c21cbc7c2cc82117601183141b90b0ff73d0ab2e45f
|
data/lib/broutes/geo_route.rb
CHANGED
@@ -10,7 +10,7 @@ module Broutes
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(args={})
|
13
|
-
args.each_pair do |key, value|
|
13
|
+
args.each_pair do |key, value|
|
14
14
|
if key.to_sym == :points
|
15
15
|
value.each { |p| add_point(p) }
|
16
16
|
else
|
@@ -100,10 +100,82 @@ module Broutes
|
|
100
100
|
(total_distance > 0) ? (total_ascent * 1000 / total_distance) : 0
|
101
101
|
end
|
102
102
|
|
103
|
+
# Public: Get average heart_rate for whole GeoRoute.
|
104
|
+
#
|
105
|
+
# Examples
|
106
|
+
# @route.average_heart_rate
|
107
|
+
# # => 12
|
108
|
+
#
|
109
|
+
# Returns Integer average, or 0 if no heart_rate on points.
|
110
|
+
def average_heart_rate
|
111
|
+
points = @_points
|
112
|
+
points.map { |p| p.heart_rate || 0 }.inject { |sum, hr| sum + hr } / points.count
|
113
|
+
end
|
114
|
+
|
115
|
+
# Public: Get average power for whole GeoRoute.
|
116
|
+
#
|
117
|
+
# Examples
|
118
|
+
# @route.average_power
|
119
|
+
# # => 250
|
120
|
+
#
|
121
|
+
# Returns Float average, or 0 if no power on points.
|
122
|
+
def average_power
|
123
|
+
points = @_points
|
124
|
+
points.map { |p| p.power || 0 }.inject { |sum, p| sum + p } / points.count
|
125
|
+
end
|
126
|
+
|
127
|
+
# Public: Get maximum heart rate for whole GeoRoute.
|
128
|
+
#
|
129
|
+
# Examples
|
130
|
+
# @route.maximum_heart_rate
|
131
|
+
# # => 180
|
132
|
+
#
|
133
|
+
# Returns Integer maximum, or 0 if no heart rate on points.
|
134
|
+
def maximum_heart_rate
|
135
|
+
points = @_points
|
136
|
+
points.map { |p| p.heart_rate }.compact.max || 0
|
137
|
+
end
|
138
|
+
|
139
|
+
# Public: Get minimum heart rate for whole GeoRoute.
|
140
|
+
#
|
141
|
+
# Examples
|
142
|
+
# @route.minimum_heart_rate
|
143
|
+
# # => 100
|
144
|
+
#
|
145
|
+
# Returns Integer minimum, or 0 if no heart rate on points.
|
146
|
+
def minimum_heart_rate
|
147
|
+
points = @_points
|
148
|
+
points.map { |p| p.heart_rate }.compact.min || 0
|
149
|
+
end
|
150
|
+
|
151
|
+
# Public: Get maximum elevation for whole GeoRoute.
|
152
|
+
#
|
153
|
+
# Examples
|
154
|
+
# @route.maximum_elevation
|
155
|
+
# # => 1000
|
156
|
+
#
|
157
|
+
# Returns Integer maximum, or 0 if no elevation on points.
|
158
|
+
def maximum_elevation
|
159
|
+
points = @_points
|
160
|
+
points.map { |p| p.elevation }.compact.max || 0
|
161
|
+
end
|
162
|
+
|
163
|
+
# Public: Get minimum elevation for whole GeoRoute.
|
164
|
+
#
|
165
|
+
# Examples
|
166
|
+
# @route.minimum_elevation
|
167
|
+
# # => 10
|
168
|
+
#
|
169
|
+
# Returns Integer minimum, or 0 if no elevation on points.
|
170
|
+
def minimum_elevation
|
171
|
+
points = @_points
|
172
|
+
points.map { |p| p.elevation }.compact.min || 0
|
173
|
+
end
|
174
|
+
|
103
175
|
private
|
104
176
|
|
105
177
|
def get_points
|
106
178
|
@_points ||= []
|
107
179
|
end
|
108
180
|
end
|
109
|
-
end
|
181
|
+
end
|
data/lib/broutes/version.rb
CHANGED
@@ -44,11 +44,11 @@ describe Formats::FitFile do
|
|
44
44
|
@route.total_time.round.should eq(13675)
|
45
45
|
end
|
46
46
|
it "sets the started_at" do
|
47
|
-
@route.started_at.to_i.should eq(Time.new(2012, 5,
|
47
|
+
@route.started_at.to_i.should eq(Time.new(2012, 5, 11, 23, 29, 45, "-07:00").to_i)
|
48
48
|
end
|
49
49
|
it "sets the ended_at" do
|
50
|
-
@route.ended_at.to_i.should eq(Time.new(2012, 5, 12,
|
50
|
+
@route.ended_at.to_i.should eq(Time.new(2012, 5, 12, 3, 17, 40, "-07:00").to_i)
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
|
-
end
|
54
|
+
end
|
@@ -29,10 +29,10 @@ describe Formats::GpxTrack do
|
|
29
29
|
@route.total_time.round.should eq(1231)
|
30
30
|
end
|
31
31
|
it "sets the started_at" do
|
32
|
-
@route.started_at.to_i.should eq(Time.new(2011, 5, 19,
|
32
|
+
@route.started_at.to_i.should eq(Time.new(2011, 5, 19, 16, 57, 21, "+00:00").to_i)
|
33
33
|
end
|
34
34
|
it "sets the ended_at" do
|
35
|
-
@route.ended_at.to_i.should eq(Time.new(2011, 5, 19,
|
35
|
+
@route.ended_at.to_i.should eq(Time.new(2011, 5, 19, 17, 17, 52, "+00:00").to_i)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
describe "when file doesn't have elevation" do
|
@@ -29,10 +29,10 @@ describe Formats::Tcx do
|
|
29
29
|
@route.total_time.round.should eq(10631)
|
30
30
|
end
|
31
31
|
it "sets the started_at" do
|
32
|
-
@route.started_at.to_i.should eq(Time.new(2012, 3, 15, 21, 20, 38).to_i)
|
32
|
+
@route.started_at.to_i.should eq(Time.new(2012, 3, 15, 21, 20, 38, "+00:00").to_i)
|
33
33
|
end
|
34
34
|
it "sets the ended_at" do
|
35
|
-
@route.ended_at.to_i.should eq(Time.new(2012, 3, 16, 00, 17, 49).to_i)
|
35
|
+
@route.ended_at.to_i.should eq(Time.new(2012, 3, 16, 00, 17, 49, "+00:00").to_i)
|
36
36
|
end
|
37
37
|
it "can create hash" do
|
38
38
|
@route.to_hash
|
@@ -78,6 +78,27 @@ describe Formats::Tcx do
|
|
78
78
|
it "sets the total time" do
|
79
79
|
@route.total_time.round.should eq(6926)
|
80
80
|
end
|
81
|
+
it "sets the hilliness" do
|
82
|
+
@route.hilliness.should eq(9.482364000273426)
|
83
|
+
end
|
84
|
+
it "sets the average heart rate" do
|
85
|
+
@route.average_heart_rate.should eq(139)
|
86
|
+
end
|
87
|
+
it "sets the average power" do
|
88
|
+
@route.average_power.should eq(174)
|
89
|
+
end
|
90
|
+
it "sets the maximum heart rate" do
|
91
|
+
@route.maximum_heart_rate.should eq(189)
|
92
|
+
end
|
93
|
+
it "sets the minimum heart rate" do
|
94
|
+
@route.minimum_heart_rate.should eq(59)
|
95
|
+
end
|
96
|
+
it "sets the maximum elevation" do
|
97
|
+
@route.maximum_elevation.should eq(85.0)
|
98
|
+
end
|
99
|
+
it "sets the minimum elevation" do
|
100
|
+
@route.minimum_elevation.should eq(0)
|
101
|
+
end
|
81
102
|
it "can create hash" do
|
82
103
|
@route.to_hash
|
83
104
|
end
|
@@ -149,4 +170,4 @@ describe Formats::Tcx do
|
|
149
170
|
@route.to_hash['started_at'].should_not be_nil
|
150
171
|
end
|
151
172
|
end
|
152
|
-
end
|
173
|
+
end
|
@@ -166,9 +166,153 @@ describe GeoRoute do
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
+
describe "#average_heart_rate" do
|
170
|
+
before(:each) do
|
171
|
+
@route = GeoRoute.new
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when the route points have heart rates' do
|
175
|
+
before(:each) do
|
176
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 15)
|
177
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 10)
|
178
|
+
end
|
179
|
+
it 'should return average heart rate' do
|
180
|
+
@route.average_heart_rate.should eq(12)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
context 'when the route points have no heart rate' do
|
184
|
+
before(:each) do
|
185
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation)
|
186
|
+
end
|
187
|
+
it 'should return 0' do
|
188
|
+
@route.average_heart_rate.should eq(0)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#maximum_heart_rate" do
|
194
|
+
before(:each) do
|
195
|
+
@route = GeoRoute.new
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'when the route points have heart rates' do
|
199
|
+
before(:each) do
|
200
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 15)
|
201
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 10)
|
202
|
+
end
|
203
|
+
it 'should return maximum heart rate' do
|
204
|
+
@route.maximum_heart_rate.should eq(15)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
context 'when the route points have no heart rate' do
|
208
|
+
before(:each) do
|
209
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation)
|
210
|
+
end
|
211
|
+
it 'should return 0' do
|
212
|
+
@route.maximum_heart_rate.should eq(0)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "#minimum_heart_rate" do
|
218
|
+
before(:each) do
|
219
|
+
@route = GeoRoute.new
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when the route points have heart rates' do
|
223
|
+
before(:each) do
|
224
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 15)
|
225
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, heart_rate: 10)
|
226
|
+
end
|
227
|
+
it 'should return minimum heart rate' do
|
228
|
+
@route.minimum_heart_rate.should eq(10)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
context 'when the route points have no heart rate' do
|
232
|
+
before(:each) do
|
233
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation)
|
234
|
+
end
|
235
|
+
it 'should return 0' do
|
236
|
+
@route.minimum_heart_rate.should eq(0)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe "#maximum_elevation" do
|
242
|
+
before(:each) do
|
243
|
+
@route = GeoRoute.new
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when the route points have elevations' do
|
247
|
+
before(:each) do
|
248
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: 217)
|
249
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: 212)
|
250
|
+
end
|
251
|
+
it 'should return maximum elevation' do
|
252
|
+
@route.maximum_elevation.should eq(217)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
context 'when the route points have no elevations' do
|
256
|
+
before(:each) do
|
257
|
+
@route.add_point(lat: random_lat, lon: random_lon)
|
258
|
+
end
|
259
|
+
it 'should return 0' do
|
260
|
+
@route.maximum_elevation.should eq(0)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#minimum_elevation" do
|
266
|
+
before(:each) do
|
267
|
+
@route = GeoRoute.new
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'when the route points have elevations' do
|
271
|
+
before(:each) do
|
272
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: 217)
|
273
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: 212)
|
274
|
+
end
|
275
|
+
it 'should return minimum elevation' do
|
276
|
+
@route.minimum_elevation.should eq(212)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
context 'when the route points have no elevations' do
|
280
|
+
before(:each) do
|
281
|
+
@route.add_point(lat: random_lat, lon: random_lon)
|
282
|
+
end
|
283
|
+
it 'should return 0' do
|
284
|
+
@route.maximum_elevation.should eq(0)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "#average_power" do
|
290
|
+
before(:each) do
|
291
|
+
@route = GeoRoute.new
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when the route points have power' do
|
295
|
+
before(:each) do
|
296
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, power: 250)
|
297
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation, power: 233)
|
298
|
+
end
|
299
|
+
it 'should return average power' do
|
300
|
+
@route.average_power.should eq(241)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
context 'when the route points have no power' do
|
304
|
+
before(:each) do
|
305
|
+
@route.add_point(lat: random_lat, lon: random_lon, elevation: random_elevation)
|
306
|
+
end
|
307
|
+
it 'should return 0' do
|
308
|
+
@route.average_power.should eq(0)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
169
313
|
describe ".from_hash" do
|
170
314
|
let(:started_at) { Time.now }
|
171
|
-
let(:points) {[
|
315
|
+
let(:points) {[
|
172
316
|
GeoPoint.new(lat: random_lat, lon: random_lon, time: started_at),
|
173
317
|
GeoPoint.new(lat: random_lat, lon: random_lon, time: started_at + 1),
|
174
318
|
GeoPoint.new(lat: random_lat, lon: random_lon, time: started_at + 2)
|
data/spec/spec_helper.rb
CHANGED
@@ -29,6 +29,10 @@ def random_string
|
|
29
29
|
(0...24).map{ ('a'..'z').to_a[rand(26)] }.join
|
30
30
|
end
|
31
31
|
|
32
|
+
def random_heart_rate
|
33
|
+
rand
|
34
|
+
end
|
35
|
+
|
32
36
|
def round_to(number, decimal_places)
|
33
37
|
if number
|
34
38
|
if decimal_places > 0
|
@@ -45,4 +49,4 @@ end
|
|
45
49
|
|
46
50
|
def open_file(name)
|
47
51
|
File.open("#{Rake.application.original_dir}/spec/support/#{name}")
|
48
|
-
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broutes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bird
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: garmin-fit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.0.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.0.2
|
41
41
|
description: Utilities for parsing and creating geo route files
|
@@ -44,17 +44,17 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- lib/broutes.rb
|
48
|
+
- lib/broutes/formats.rb
|
47
49
|
- lib/broutes/formats/factory.rb
|
48
50
|
- lib/broutes/formats/fit_file.rb
|
49
51
|
- lib/broutes/formats/gpx_route.rb
|
50
52
|
- lib/broutes/formats/gpx_track.rb
|
51
53
|
- lib/broutes/formats/tcx.rb
|
52
|
-
- lib/broutes/formats.rb
|
53
54
|
- lib/broutes/geo_point.rb
|
54
55
|
- lib/broutes/geo_route.rb
|
55
56
|
- lib/broutes/maths.rb
|
56
57
|
- lib/broutes/version.rb
|
57
|
-
- lib/broutes.rb
|
58
58
|
- spec/broutes/formats/factory_spec.rb
|
59
59
|
- spec/broutes/formats/fit_file_spec.rb
|
60
60
|
- spec/broutes/formats/gpx_route_spec.rb
|
@@ -83,17 +83,17 @@ require_paths:
|
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.2
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Utilities for parsing and creating geo route files
|