tcxread 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +79 -0
- data/lib/tcxread.rb +26 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed1afce3cee9d915fdabd00e0732caafa749719188118bbe428ddf7eadd3f52d
|
4
|
+
data.tar.gz: a3867ff511e74ea4e2b11efbdcfcf36d453e5b1030a4d5c28bd1ef10ac70a76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0666fd2bd6601145ad998911252e4856f9e4e6d8eca9673dd2f4076c3fc0abff1cd2264a3521a5602771f4a4d16914a9ded05f678d08c8ca04efef138effbcc9
|
7
|
+
data.tar.gz: aa6bc442fe648352928bf01710b98ba37faca036c5e0be103fbef453e7edafe0da1060bf955fd66f206da97e048e40031f35878b45fe881e517c681ea062ab0f
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022-2024 Iztok Fister Jr.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
<h1 align="center">
|
2
|
+
tcxread -- A parser for TCX files written in Ruby
|
3
|
+
</h1>
|
4
|
+
|
5
|
+
<p align="center">
|
6
|
+
<a href="https://badge.fury.io/rb/tcxread">
|
7
|
+
<img alt="Gem Version" src="https://badge.fury.io/rb/tcxread.svg">
|
8
|
+
</a>
|
9
|
+
<a href="https://github.com/firefly-cpp/tcxread/blob/master/LICENSE">
|
10
|
+
<img alt="License" src="https://img.shields.io/github/license/firefly-cpp/tcxread.svg">
|
11
|
+
</a>
|
12
|
+
<a href=https://repology.org/project/ruby:tcxread/versions>
|
13
|
+
<img alt="Packaging status" src="https://repology.org/badge/tiny-repos/ruby:tcxread.svg">
|
14
|
+
</a>
|
15
|
+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/w/firefly-cpp/tcxread.svg">
|
16
|
+
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/firefly-cpp/tcxread">
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p align="center">
|
20
|
+
<a href="#-installation">📦 Installation</a> •
|
21
|
+
<a href="#-basic-run-example">🚀 Basic run example</a> •
|
22
|
+
<a href="#-datasets">💾 Datasets</a> •
|
23
|
+
<a href="#-further-read">📖 Further read</a> •
|
24
|
+
<a href="#-related-packagesframeworks">🔗 Related packages/frameworks</a> •
|
25
|
+
<a href="#-license">🔑 License</a>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
tcxread is a Ruby package designed to simplify the process of reading and processing .tcx files, commonly used by Garmin devices and other GPS-enabled fitness devices to store workout data.
|
29
|
+
|
30
|
+
## 📦 Installation
|
31
|
+
|
32
|
+
```sh
|
33
|
+
$ gem install tcxread
|
34
|
+
```
|
35
|
+
|
36
|
+
## 🚀 Basic run example
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'tcxread'
|
40
|
+
|
41
|
+
data = TCXRead.new('23.tcx')
|
42
|
+
|
43
|
+
puts "Distance meters: #{data.total_distance_meters}, " \
|
44
|
+
"Time seconds: #{data.total_time_seconds}, " \
|
45
|
+
"Calories: #{data.total_calories}, " \
|
46
|
+
"Total ascent: #{data.total_ascent}, " \
|
47
|
+
"Total descent: #{data.total_descent}, " \
|
48
|
+
"Max altitude: #{data.max_altitude}, " \
|
49
|
+
"Average heart rate: #{data.average_heart_rate}, " \
|
50
|
+
"Average watts: #{data.average_watts}, " \
|
51
|
+
"Max watts: #{data.max_watts}, " \
|
52
|
+
"Average cadence: #{data.average_cadence}"
|
53
|
+
```
|
54
|
+
|
55
|
+
## 💾 Datasets
|
56
|
+
|
57
|
+
Datasets available and used in the examples on the following links: [DATASET1](http://iztok-jr-fister.eu/static/publications/Sport5.zip), [DATASET2](http://iztok-jr-fister.eu/static/css/datasets/Sport.zip), [DATASET3](https://github.com/firefly-cpp/tcx-test-files).
|
58
|
+
|
59
|
+
## 📖 Further read
|
60
|
+
|
61
|
+
[1] [Awesome Computational Intelligence in Sports](https://github.com/firefly-cpp/awesome-computational-intelligence-in-sports)
|
62
|
+
|
63
|
+
## 🔗 Related packages/frameworks
|
64
|
+
|
65
|
+
[1] [tcxreader: Python reader/parser for Garmin's TCX file format.](https://github.com/alenrajsp/tcxreader)
|
66
|
+
|
67
|
+
[2] [sport-activities-features: A minimalistic toolbox for extracting features from sports activity files written in Python](https://github.com/firefly-cpp/sport-activities-features)
|
68
|
+
|
69
|
+
[3] [TCXReader.jl: Julia package designed for parsing TCX files](https://github.com/firefly-cpp/TCXReader.jl)
|
70
|
+
|
71
|
+
[4] [TCXWriter: A Tiny Library for writing/creating TCX files on Arduino](https://github.com/firefly-cpp/tcxwriter)
|
72
|
+
|
73
|
+
## 🔑 License
|
74
|
+
|
75
|
+
This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
|
76
|
+
|
77
|
+
## Disclaimer
|
78
|
+
|
79
|
+
This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!
|
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.3
|
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-
|
11
|
+
date: 2024-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -31,6 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
34
36
|
- lib/tcxread.rb
|
35
37
|
homepage: https://github.com/firefly-cpp/tcxread
|
36
38
|
licenses:
|