simple-trail 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/simple_trail/generator/gpx.rb +13 -2
- data/lib/simple_trail/manipulation/enricher.rb +6 -3
- data/simple-trail.gemspec +1 -1
- data/spec/examples/test-xxl.gpx +1 -1
- data/spec/examples/test_no_time_and_ele.gpx +55 -0
- data/spec/generator/gpx_spec.rb +18 -0
- data/spec/manipulation/enricher_spec.rb +25 -0
- 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: 1764e72de880503bf6d9493359b9c5af1ce9e6e41de6521f38664c1523f50aaf
|
4
|
+
data.tar.gz: 35e92389256eccfffd647cec6a24ec48cfb7fd132ed52150b59f1ffcd5f705fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78e80884cb5140bd48ee9705e02eb4110c3af7ef209c16349e231e1906b110e9da3390966e4aa51b6981b23f5957f0804f127f5a31ed0bc6ec51edbb9906d73
|
7
|
+
data.tar.gz: 92eb3802ea53ac97d626fd383eb98cd5c2111d5e29640ca9e3d29bba4fc001f1d4be6c1a8ec25538cb0d40c46f9285c8c385304206682afd173186c7f5f5cc5a
|
data/README.md
CHANGED
@@ -3,4 +3,17 @@
|
|
3
3
|
.h3 Purpose
|
4
4
|
Reading and interpretation on trail files (GPX,...)
|
5
5
|
|
6
|
+
.h3 Usage
|
7
|
+
|
8
|
+
```
|
9
|
+
@parser = Parser::Gpx.new(@file)
|
10
|
+
|
11
|
+
@parser.read
|
12
|
+
@points = @parser.points
|
13
|
+
```
|
14
|
+
|
15
|
+
```
|
16
|
+
Manipulation::Enricher.new(@points, @enrichment_level, @offset).enrich
|
17
|
+
```
|
18
|
+
|
6
19
|
Licence: MIT
|
@@ -9,14 +9,25 @@ module Generator
|
|
9
9
|
@name = name
|
10
10
|
end
|
11
11
|
|
12
|
+
def time(xml, timestamp)
|
13
|
+
xml.send(:time, timestamp)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ele(xml, elevation)
|
17
|
+
xml.send(:ele, elevation)
|
18
|
+
end
|
19
|
+
|
12
20
|
def gpx
|
13
21
|
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
14
22
|
xml.gpx(version: '1.0') {
|
15
|
-
xml.name { @name }
|
16
23
|
xml.trk {
|
24
|
+
xml.name { @name }
|
17
25
|
xml.trkseg {
|
18
26
|
@points.map do |point|
|
19
|
-
xml.trkpt(lat: point[:lat], lon: point[:lon])
|
27
|
+
xml.trkpt(lat: point[:lat], lon: point[:lon]) {
|
28
|
+
time(xml, point[:time]) unless point[:time].nil?
|
29
|
+
ele(xml, point[:ele]) unless point[:ele].nil?
|
30
|
+
}
|
20
31
|
end
|
21
32
|
}
|
22
33
|
}
|
@@ -4,9 +4,10 @@ module Manipulation
|
|
4
4
|
class Enricher
|
5
5
|
attr_reader :enriched_points
|
6
6
|
|
7
|
-
def initialize(points, distance_limit=nil)
|
7
|
+
def initialize(points, distance_limit=nil, offset=0)
|
8
8
|
@points = points
|
9
9
|
@distance_limit = distance_limit
|
10
|
+
@offset = offset
|
10
11
|
@counter = 3
|
11
12
|
end
|
12
13
|
|
@@ -75,13 +76,15 @@ module Manipulation
|
|
75
76
|
|
76
77
|
def add_km_markers
|
77
78
|
total_distance = @points[-1][:total_distance].floor - 1
|
78
|
-
|
79
|
+
start_v = @offset.ceil
|
80
|
+
|
81
|
+
(start_v..start_v+total_distance).each do |i|
|
79
82
|
find_and_enrich_first_occurence(i+1)
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
86
|
def find_and_enrich_first_occurence(i)
|
84
|
-
index = @points.find_index{|point| point[:total_distance] > i}
|
87
|
+
index = @points.find_index{|point| point[:total_distance] + @offset > i}
|
85
88
|
@points[index].merge!(label: i)
|
86
89
|
end
|
87
90
|
|
data/simple-trail.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'simple-trail'
|
8
|
-
s.version = '0.2.
|
8
|
+
s.version = '0.2.2'
|
9
9
|
s.date = '2020-08-03'
|
10
10
|
s.summary = 'Readind and manipulating GPX and other trail representation file'
|
11
11
|
s.description = 'Optimazing and manipulating GPX file data. For my private purposes mostly'
|
data/spec/examples/test-xxl.gpx
CHANGED
@@ -98424,4 +98424,4 @@
|
|
98424
98424
|
</trkpt>
|
98425
98425
|
</trkseg>
|
98426
98426
|
</trk>
|
98427
|
-
</gpx>
|
98427
|
+
</gpx>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><gpx creator="https://mapa-turystyczna.pl" xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
2
|
+
<metadata>
|
3
|
+
<link href="https://mapa-turystyczna.pl">
|
4
|
+
<text>mapa-turystyczna.pl</text>
|
5
|
+
</link>
|
6
|
+
<time>2020-06-07T13:17:32Z</time>
|
7
|
+
<bounds maxlat="49.5039739" maxlon="20.0407328" minlat="49.4986602" minlon="20.0366753"/>
|
8
|
+
</metadata>
|
9
|
+
<wpt lat="49.49866" lon="20.040733">
|
10
|
+
<ele>617</ele>
|
11
|
+
<name>Nowy Targ, Kowaniec</name>
|
12
|
+
<link href="https://mapa-turystyczna.pl/node/88">
|
13
|
+
<text>Nowy Targ, Kowaniec</text>
|
14
|
+
</link>
|
15
|
+
</wpt>
|
16
|
+
<wpt lat="49.503974" lon="20.037433">
|
17
|
+
<ele>631</ele>
|
18
|
+
<name>Nowy Targ, Robów</name>
|
19
|
+
<link href="https://mapa-turystyczna.pl/node/4103">
|
20
|
+
<text>Nowy Targ, Robów</text>
|
21
|
+
</link>
|
22
|
+
</wpt>
|
23
|
+
|
24
|
+
<trk>
|
25
|
+
<name>Nowy Targ, Kowaniec – Nowy Targ, Robów</name>
|
26
|
+
<link href="https://mapa-turystyczna.pl/route?q=49.4986600,20.0407330;49.5039740,20.0374330">
|
27
|
+
<text>Nowy Targ, Kowaniec – Nowy Targ, Robów</text>
|
28
|
+
</link>
|
29
|
+
<trkseg>
|
30
|
+
<trkpt lat="49.4986602" lon="20.0407328"/>
|
31
|
+
<trkpt lat="49.4986967" lon="20.0404556"/>
|
32
|
+
<trkpt lat="49.4987087" lon="20.0400335"/>
|
33
|
+
<trkpt lat="49.4988349" lon="20.0397599"/>
|
34
|
+
<trkpt lat="49.4989091" lon="20.0396378"/>
|
35
|
+
<trkpt lat="49.499428" lon="20.0394863"/>
|
36
|
+
<trkpt lat="49.4996371" lon="20.0392445"/>
|
37
|
+
<trkpt lat="49.4997661" lon="20.0389653"/>
|
38
|
+
<trkpt lat="49.5002861" lon="20.038577"/>
|
39
|
+
<trkpt lat="49.5007575" lon="20.0380165"/>
|
40
|
+
<trkpt lat="49.5008552" lon="20.0378636"/>
|
41
|
+
<trkpt lat="49.5011271" lon="20.0373244"/>
|
42
|
+
<trkpt lat="49.5013462" lon="20.0370132"/>
|
43
|
+
<trkpt lat="49.5014997" lon="20.0368389"/>
|
44
|
+
<trkpt lat="49.501667" lon="20.0367343"/>
|
45
|
+
<trkpt lat="49.5019824" lon="20.0366753"/>
|
46
|
+
<trkpt lat="49.5023919" lon="20.0367289"/>
|
47
|
+
<trkpt lat="49.5027698" lon="20.0370616"/>
|
48
|
+
<trkpt lat="49.5031206" lon="20.037299"/>
|
49
|
+
<trkpt lat="49.5033425" lon="20.0373218"/>
|
50
|
+
<trkpt lat="49.5035736" lon="20.0373084"/>
|
51
|
+
<trkpt lat="49.5038343" lon="20.0374016"/>
|
52
|
+
<trkpt lat="49.5039739" lon="20.0374335"/>
|
53
|
+
</trkseg>
|
54
|
+
</trk>
|
55
|
+
</gpx>
|
data/spec/generator/gpx_spec.rb
CHANGED
@@ -18,4 +18,22 @@ RSpec.describe Generator::Gpx do
|
|
18
18
|
expect(output.match(/#{random_point[:lon]}/)).not_to be_nil
|
19
19
|
expect(output.match(/#{random_point[:lat]}/)).not_to be_nil
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'generates output when no time' do
|
23
|
+
parser = Parser::Gpx.new('./spec/examples/test_no_time_and_ele.gpx')
|
24
|
+
parser.read
|
25
|
+
|
26
|
+
points = parser.points
|
27
|
+
|
28
|
+
service = described_class.new(points: points)
|
29
|
+
expect{service.gpx}.not_to raise_error
|
30
|
+
output = service.output
|
31
|
+
expect(output).not_to be_nil
|
32
|
+
|
33
|
+
random_point = points.sample
|
34
|
+
expect(output.match(/#{random_point[:lon]}/)).not_to be_nil
|
35
|
+
expect(output.match(/#{random_point[:lat]}/)).not_to be_nil
|
36
|
+
expect(output.match(/time/)).to be_nil
|
37
|
+
expect(output.match(/ele/)).to be_nil
|
38
|
+
end
|
21
39
|
end
|
@@ -36,4 +36,29 @@ RSpec.describe Manipulation::Enricher do
|
|
36
36
|
expect(enrichement_logic.enriched_points.count).not_to eq point_count
|
37
37
|
expect(enrichement_logic.enriched_points.all?{|point| !point[:ele].nil?}).to be(true)
|
38
38
|
end
|
39
|
+
|
40
|
+
it 'adds labels' do
|
41
|
+
parser = Parser::Gpx.new('./spec/examples/gss20-full-official.gpx')
|
42
|
+
parser.read
|
43
|
+
|
44
|
+
enrichement_logic = described_class.new(parser.points, 0.1)
|
45
|
+
enrichement_logic.enrich
|
46
|
+
|
47
|
+
labels = enrichement_logic.enriched_points.map{|h| h[:label]}.compact.uniq
|
48
|
+
expect(labels.size).to eq 506
|
49
|
+
expect(labels.include?('1')).to be(true)
|
50
|
+
expect(labels.include?('535')).to be(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'adds labels with offset' do
|
54
|
+
parser = Parser::Gpx.new('./spec/examples/gss20-full-official.gpx')
|
55
|
+
parser.read
|
56
|
+
|
57
|
+
enrichement_logic = described_class.new(parser.points, 0.1, 50)
|
58
|
+
enrichement_logic.enrich
|
59
|
+
labels = enrichement_logic.enriched_points.map{|h| h[:label]}.compact.uniq
|
60
|
+
expect(labels.size).to eq 506
|
61
|
+
expect(labels.include?('1')).to be(false)
|
62
|
+
expect(labels.include?('535')).to be(true)
|
63
|
+
end
|
39
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Staszek Zawadzki
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- spec/examples/test_7.gpx
|
114
114
|
- spec/examples/test_8.gpx
|
115
115
|
- spec/examples/test_9.gpx
|
116
|
+
- spec/examples/test_no_time_and_ele.gpx
|
116
117
|
- spec/examples/test_with_segments.gpx
|
117
118
|
- spec/examples/zyleta2021.gpx
|
118
119
|
- spec/generator/gpx_spec.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.1.4
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Readind and manipulating GPX and other trail representation file
|
@@ -163,6 +164,7 @@ test_files:
|
|
163
164
|
- spec/examples/test_7.gpx
|
164
165
|
- spec/examples/test_8.gpx
|
165
166
|
- spec/examples/test_9.gpx
|
167
|
+
- spec/examples/test_no_time_and_ele.gpx
|
166
168
|
- spec/examples/test_with_segments.gpx
|
167
169
|
- spec/examples/zyleta2021.gpx
|
168
170
|
- spec/generator/gpx_spec.rb
|