tcxxxer 0.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14f5a74f5f9d90e76a8db7fd403084bae7ea7aa2
4
+ data.tar.gz: 87e21cda529977a29af08b50dec32b3b2317b803
5
+ SHA512:
6
+ metadata.gz: f29f63cd6eeecb6bb42cca4ca59ab9978f6a9d62dfa4f8cbae7945fd7e0864713567d25b4ba94f954addae85e6ac2d0a95af01b02474b71ad9c3c94863bcce2a
7
+ data.tar.gz: b44eba5f6356e70887f8f88485643d9b32c7c4785b9be05243caddb0a68849072e05a25ac824f4b6dbc0999a89f3a6c3359e4bdd4e727f4cd901528bf9b67380
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tcxxxer.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Xiang Zhuyuan, 2016 .
2
+
3
+ MIT License
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Tcxxxer
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/tcxxxer.svg)](https://badge.fury.io/rb/tcxxxer)
4
+
5
+ I search a lot but I couldn't find out a valid gem which I can use to parse/conert a `tcx` file easily.
6
+ so I wrote this, essentially I check the gem `guppy` but I found it outdated a long age, the logic to parse
7
+ `tcx` file had been outdated. please check this gem if you want to work with `tcx` file.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'tcxxxer'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install tcxxxer
24
+
25
+ ## Usage
26
+
27
+ ```
28
+ get '/map' do
29
+ # input parameter
30
+ # name
31
+ day = params['day']
32
+ file_name = "TourDeHokkaido_day#{day}"
33
+ db = Tcxxxer::DB.open("./tcx/#{file_name}.tcx")
34
+ @points_list = []
35
+ db.courses.each do |course|
36
+ max_distance = (course.track.last.distance/1000).round(2).to_s + "km"
37
+ course_range = course.track.each_slice(400).to_a
38
+
39
+ course_range.each_with_index do |range, _i|
40
+ @points = []
41
+ @altitudes = []
42
+ range.each do |point|
43
+ @points << (point.distance/1000).round(2).to_s + "km"
44
+ @altitudes << point.altitude.round(2)
45
+ # @points_list << {:points => @points, :altitudes => @altitudes}
46
+ end
47
+
48
+ begin
49
+ # read all, get each id
50
+ html_file = "./tcx_result/#{file_name}_#{_i}.html"
51
+ puts "start read erb, and create html file ...."
52
+ renderer = ERB.new(File.read("./views/line.erb"))
53
+ result = renderer.result(binding)
54
+
55
+ File.open(html_file, 'w') do |f|
56
+ puts "write #{html_file} start"
57
+ f.write(result)
58
+ end
59
+
60
+ rescue => e
61
+ puts e.message
62
+ end
63
+
64
+ end
65
+ end
66
+ # get file list
67
+ @result_list = Dir["./tcx_result/#{file_name}*.html"]
68
+ erb :line_result
69
+ end
70
+
71
+ ```
72
+
73
+ more please check [my strava 次世代の名刺](https://mystrava.herokuapp.com)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tcxxxer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ module Tcxxxer
2
+ class Course
3
+ attr_accessor :name
4
+ attr_accessor :lap
5
+ attr_accessor :track
6
+
7
+ def initialize
8
+ end
9
+
10
+
11
+ end
12
+ end
data/lib/tcxxxer/db.rb ADDED
@@ -0,0 +1,45 @@
1
+ module Tcxxxer
2
+ class DB
3
+ def self.file_type(file_name)
4
+ case File.extname(file_name).downcase
5
+ when '.tcx'
6
+ TCX
7
+ when '.gpx'
8
+ GPX
9
+ when '.fit'
10
+ FIT
11
+ else
12
+ raise "Unknown filetype"
13
+ end
14
+ end
15
+
16
+ def self.open(file_name)
17
+ db = new(file_name)
18
+ db.parse
19
+ return db
20
+ end
21
+
22
+ def initialize(file)
23
+ @file_name = file
24
+ end
25
+
26
+ def parse
27
+ case self.class.file_type(@file_name)
28
+ when TCX
29
+ @doc = Tcxxxer::TcxParser.open(@file_name)
30
+ when GPX
31
+ @doc = Tcxxxer::GpxParser.open(@file_name)
32
+ when FIT
33
+ @doc = Tcxxxer::FitParser.open(@file_name)
34
+ end
35
+ end
36
+
37
+ def courses
38
+ @doc.courses
39
+ end
40
+
41
+ def course(course_id)
42
+ @doc.courses(course_id)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ module Tcxxxer
2
+ class Lap
3
+
4
+ attr_accessor :total_time_seconds
5
+ attr_accessor :distance_meters
6
+ attr_accessor :begin_lat
7
+ attr_accessor :begin_lng
8
+ attr_accessor :end_lat
9
+ attr_accessor :end_lng
10
+ #
11
+ # def initialize(t, d, b_lat, b_lng, e_lat, e_lng)
12
+ # total_time_seconds =t
13
+ # distance_meters = d
14
+ # begin_lat = b_lat
15
+ # begin_lng = b_lng
16
+ # end_lat = e_lat
17
+ # end_lng = e_lng
18
+ # end
19
+ #
20
+
21
+ def initialize()
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,73 @@
1
+ require 'nokogiri'
2
+ module Tcxxxer
3
+
4
+ class TcxParser
5
+
6
+ def self.open(file)
7
+ tcx_parser = self.new(file)
8
+ tcx_parser.parse
9
+ tcx_parser
10
+ end
11
+
12
+ def initialize(file)
13
+ @file = file
14
+ end
15
+
16
+ def parse
17
+ f = File.open(@file)
18
+ @doc = Nokogiri.XML(f.read)
19
+ @doc.remove_namespaces!
20
+ f.close
21
+ end
22
+
23
+ def courses()
24
+ @doc.xpath('//Courses').map do |course_node|
25
+ build_course(course_node)
26
+ end
27
+ end
28
+
29
+ private
30
+ def build_course(course_node)
31
+ course = Course.new
32
+ course.name = course_node.xpath('//Name').first.inner_text.to_s
33
+ course.lap = build_lap(course_node.xpath('//Lap'))
34
+ course.track = build_track_point(course_node.xpath('//Track'))
35
+
36
+ course
37
+ end
38
+
39
+ def build_lap(lap_node)
40
+ lap = Tcxxxer::Lap.new
41
+ lap.total_time_seconds = lap_node.xpath('//TotalTimeSeconds').inner_text.to_s
42
+ lap.distance_meters = lap_node.xpath('//DistanceMeters').inner_text.to_s
43
+ lap.begin_lat = lap_node.xpath('//BeginPosition/LatitudeDegrees').inner_text.to_s
44
+ lap.begin_lng = lap_node.xpath('//BeginPosition/LongitudeDegrees').inner_text.to_s
45
+ lap.end_lat = lap_node.xpath('//EndPosition/LatitudeDegrees').inner_text.to_s
46
+ lap.end_lng = lap_node.xpath('//EndPosition/LongitudeDegrees').inner_text.to_s
47
+ lap
48
+ end
49
+
50
+ def build_track_point(track_point_node)
51
+
52
+ track_points = []
53
+ track_point_node.xpath('//Trackpoint').map do |track_node|
54
+ track_point = Tcxxxer::TrackPoint.new
55
+ track_point.latitude = track_node.xpath('Position/LatitudeDegrees').inner_text.to_f
56
+ track_point.longitude = track_node.xpath('Position/LongitudeDegrees').inner_text.to_f
57
+ track_point.altitude = track_node.xpath('AltitudeMeters').inner_text.to_f
58
+ track_point.distance = track_node.xpath('DistanceMeters').inner_text.to_f
59
+ track_point.heart_rate = track_node.xpath('HeartRateBpm').inner_text.to_i
60
+ track_point.time = Time.parse(track_node.xpath('Time').inner_text)
61
+ track_point.cadence = track_node.xpath('Cadence').inner_text.to_i
62
+ track_point.watts = track_node.xpath('Watts').inner_text.to_i
63
+ track_point.speed = track_node.xpath('Speed').inner_text.to_f
64
+
65
+ track_points<< track_point
66
+ end
67
+
68
+ track_points
69
+
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,38 @@
1
+ module Tcxxxer
2
+ class TrackPoint
3
+
4
+ attr_accessor :altitude
5
+ attr_accessor :cadence
6
+ attr_accessor :distance
7
+ attr_accessor :heart_rate
8
+ attr_accessor :latitude
9
+ attr_accessor :longitude
10
+ attr_accessor :time
11
+ attr_accessor :watts
12
+ attr_accessor :speed
13
+ attr_accessor :joules
14
+
15
+ @@attributes = [ :altitude, :cadence, :distance, :heart_rate,
16
+ :latitude, :longitude, :time, :watts,
17
+ :speed, :joules ]
18
+
19
+ attr_accessor *@@attributes
20
+
21
+ def initialize
22
+ zero_all_attrs
23
+ end
24
+
25
+ def zero_all_attrs
26
+ @@attributes.each do |a|
27
+ instance_variable_set "@#{a}", 0
28
+ end
29
+ end
30
+
31
+ def to_hash
32
+ @@attributes.each_with_object({}) {
33
+ |a,h| h[a] = instance_variable_get "@#{a}"
34
+ }
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Tcxxxer
2
+ VERSION = "0.4.0"
3
+ end
data/lib/tcxxxer.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "tcxxxer/version"
2
+ require 'tcxxxer/course'
3
+ require 'tcxxxer/db'
4
+ require 'tcxxxer/lap'
5
+ require 'tcxxxer/tcx_parser'
6
+ require 'tcxxxer/track_point'
7
+
8
+ require 'nokogiri'
9
+
10
+
11
+ module Tcxxxer
12
+ TCX = 'tcx'
13
+ GPX = 'gpx'
14
+ FIT = 'fit'
15
+ end
data/tcxxxer.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tcxxxer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tcxxxer"
8
+ spec.version = Tcxxxer::VERSION
9
+ spec.authors = ["xiang zhuyuan"]
10
+ spec.email = ["xiangzhuyuan@gmail.com"]
11
+ spec.licenses = ['MIT']
12
+ spec.summary = %q{copy from rubist/guppy}
13
+ spec.description = %q{A converter for TCX/GPX file, you get can all `lap`, `track` info from the `tcx` file!}
14
+ spec.homepage = "https://github.com/xiangzhuyuan/tcxxxer"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "nokogiri", "1.6.8"
27
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tcxxxer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - xiang zhuyuan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.8
55
+ description: A converter for TCX/GPX file, you get can all `lap`, `track` info from
56
+ the `tcx` file!
57
+ email:
58
+ - xiangzhuyuan@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/tcxxxer.rb
72
+ - lib/tcxxxer/course.rb
73
+ - lib/tcxxxer/db.rb
74
+ - lib/tcxxxer/lap.rb
75
+ - lib/tcxxxer/tcx_parser.rb
76
+ - lib/tcxxxer/track_point.rb
77
+ - lib/tcxxxer/version.rb
78
+ - tcxxxer.gemspec
79
+ homepage: https://github.com/xiangzhuyuan/tcxxxer
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: copy from rubist/guppy
103
+ test_files: []
104
+ has_rdoc: