tcxread 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tcxread.rb +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42a89981c1614dec069270cb1315ee64d0c6a172de5c44a5370b5f5c8bd584f
|
4
|
+
data.tar.gz: dcee18bb770a1aa020d5ad8f67370f775a6f8d25139c39eb8576e76c463c1efd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c0b8ba80f7cd524c91417123353e6d9523551050c513d55447ae1c6d73ff8add6af60cc6ec319d26af8aa237e7bcb40771f587653ffe92766f57be7d538194
|
7
|
+
data.tar.gz: 42a2ea64072c68e786e002a5dd0fa32c4547ac0503a4eb207537c3d9442148ca958fe9038b44b826033fa94ca4ddf80feaff92f8904745bfdad7aaba96c591ae
|
data/lib/tcxread.rb
CHANGED
@@ -5,7 +5,7 @@ require "nokogiri"
|
|
5
5
|
class TCXRead
|
6
6
|
attr_reader :total_distance_meters, :total_time_seconds, :total_calories,
|
7
7
|
:total_ascent, :total_descent, :max_altitude, :average_heart_rate,
|
8
|
-
:max_watts, :average_watts
|
8
|
+
:max_watts, :average_watts, :average_cadence
|
9
9
|
|
10
10
|
def initialize(file_path)
|
11
11
|
@file_path = file_path
|
@@ -22,6 +22,7 @@ class TCXRead
|
|
22
22
|
# use NA if no watts exist in the TCX file
|
23
23
|
@max_watts = 'NA'
|
24
24
|
@average_watts = 'NA'
|
25
|
+
@average_cadence = 0
|
25
26
|
|
26
27
|
parse
|
27
28
|
end
|
@@ -38,6 +39,7 @@ class TCXRead
|
|
38
39
|
@total_ascent, @total_descent, @max_altitude = calculate_ascent_descent_and_max_altitude_from_activities(activities)
|
39
40
|
@average_heart_rate = calculate_average_heart_rate_from_activities(activities)
|
40
41
|
@max_watts, @average_watts = calculate_watts_from_activities(activities)
|
42
|
+
@average_cadence = calculate_average_cadence_from_activities(activities)
|
41
43
|
end
|
42
44
|
|
43
45
|
{ activities: activities }
|
@@ -168,7 +170,6 @@ class TCXRead
|
|
168
170
|
[total_ascent, total_descent, max_altitude]
|
169
171
|
end
|
170
172
|
|
171
|
-
|
172
173
|
# Calculates the total ascent, total descent, and maximum altitude from the activities.
|
173
174
|
#
|
174
175
|
# @param activities [Array<Hash>] an array of activity hashes.
|
@@ -263,4 +264,27 @@ class TCXRead
|
|
263
264
|
|
264
265
|
[max_watts, average_watts]
|
265
266
|
end
|
267
|
+
|
268
|
+
# Calculates the average cadence from the activities.
|
269
|
+
#
|
270
|
+
# @param activities [Array<Hash>] an array of activity hashes.
|
271
|
+
# @return [Float] the average cadence.
|
272
|
+
def calculate_average_cadence_from_activities(activities)
|
273
|
+
total_cadence = 0
|
274
|
+
cadence_count = 0
|
275
|
+
|
276
|
+
activities.each do |activity|
|
277
|
+
activity[:laps].each do |lap|
|
278
|
+
lap[:tracks].flatten.each do |trackpoint|
|
279
|
+
cadence = trackpoint[:cadence]
|
280
|
+
if cadence > 0
|
281
|
+
total_cadence += cadence
|
282
|
+
cadence_count += 1
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
cadence_count > 0 ? total_cadence.to_f / cadence_count : 0.0
|
289
|
+
end
|
266
290
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcxread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- firefly-cpp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|