geoptima 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/show_geoptima +11 -0
- data/examples/show_geoptima.rb +11 -0
- data/lib/geoptima/data.rb +89 -0
- data/lib/geoptima/version.rb +1 -1
- metadata +4 -4
data/bin/show_geoptima
CHANGED
@@ -258,6 +258,12 @@ class Export
|
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
|
+
def export_gpx(trace)
|
262
|
+
File.open("#{$export_prefix}#{trace}.gpx",'w') do |out|
|
263
|
+
puts "Exporting #{trace.length} GPS events to trace: #{trace}"
|
264
|
+
out.puts trace.as_gpx
|
265
|
+
end
|
266
|
+
end
|
261
267
|
def header(name=nil)
|
262
268
|
@headers[name]
|
263
269
|
end
|
@@ -317,6 +323,11 @@ $datasets.keys.sort.each do |imei|
|
|
317
323
|
names = dataset.events_names if(names.length<1)
|
318
324
|
export = Export.new(imei,names,dataset)
|
319
325
|
export.export_stats(dataset.stats) if($export_stats)
|
326
|
+
if $export_gpx
|
327
|
+
dataset.each_trace do |trace|
|
328
|
+
export.export_gpx(trace)
|
329
|
+
end
|
330
|
+
end
|
320
331
|
if $header_maps && $header_maps.length > 0
|
321
332
|
$header_maps.each do |hm|
|
322
333
|
puts "Searching for events for header_maps '#{hm.event}'"
|
data/examples/show_geoptima.rb
CHANGED
@@ -258,6 +258,12 @@ class Export
|
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
|
+
def export_gpx(trace)
|
262
|
+
File.open("#{$export_prefix}#{trace}.gpx",'w') do |out|
|
263
|
+
puts "Exporting #{trace.length} GPS events to trace: #{trace}"
|
264
|
+
out.puts trace.as_gpx
|
265
|
+
end
|
266
|
+
end
|
261
267
|
def header(name=nil)
|
262
268
|
@headers[name]
|
263
269
|
end
|
@@ -317,6 +323,11 @@ $datasets.keys.sort.each do |imei|
|
|
317
323
|
names = dataset.events_names if(names.length<1)
|
318
324
|
export = Export.new(imei,names,dataset)
|
319
325
|
export.export_stats(dataset.stats) if($export_stats)
|
326
|
+
if $export_gpx
|
327
|
+
dataset.each_trace do |trace|
|
328
|
+
export.export_gpx(trace)
|
329
|
+
end
|
330
|
+
end
|
320
331
|
if $header_maps && $header_maps.length > 0
|
321
332
|
$header_maps.each do |hm|
|
322
333
|
puts "Searching for events for header_maps '#{hm.event}'"
|
data/lib/geoptima/data.rb
CHANGED
@@ -33,6 +33,75 @@ module Geoptima
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
class Trace
|
37
|
+
attr_reader :dataset, :name, :tracename, :bounds, :events
|
38
|
+
def initialize(dataset)
|
39
|
+
@dataset = dataset
|
40
|
+
@name = dataset.name
|
41
|
+
@events = []
|
42
|
+
end
|
43
|
+
def <<(e)
|
44
|
+
@tracename ||= "#{name}-#{e.time}"
|
45
|
+
check_bounds(e)
|
46
|
+
@events << e unless(co_located(e,@events[-1]))
|
47
|
+
end
|
48
|
+
def co_located(event,other)
|
49
|
+
event && other && event.latitude == other.latitude && event.longitude == other.longitude
|
50
|
+
end
|
51
|
+
def length
|
52
|
+
events.length
|
53
|
+
end
|
54
|
+
def to_s
|
55
|
+
tracename || name
|
56
|
+
end
|
57
|
+
def check_bounds(e)
|
58
|
+
@bounds ||= {}
|
59
|
+
check_bounds_min :minlat, e.latitude
|
60
|
+
check_bounds_min :minlon, e.longitude
|
61
|
+
check_bounds_max :maxlat, e.latitude
|
62
|
+
check_bounds_max :maxlon, e.longitude
|
63
|
+
end
|
64
|
+
def check_bounds_min(key,value)
|
65
|
+
@bounds[key] = value if(@bounds[key].nil? || @bounds[key] > value)
|
66
|
+
end
|
67
|
+
def check_bounds_max(key,value)
|
68
|
+
@bounds[key] = value if(@bounds[key].nil? || @bounds[key] < value)
|
69
|
+
end
|
70
|
+
def each
|
71
|
+
events.each{|e| yield e}
|
72
|
+
end
|
73
|
+
def too_far(other)
|
74
|
+
events && events[-1] && (events[-1].days_from(other) > 0.5 || events[-1].distance_from(other) > 0.002)
|
75
|
+
end
|
76
|
+
def bounds_as_gpx
|
77
|
+
"<bounds " + bounds.keys.map{|k| "#{k}=\"#{bounds[k]}\""}.join(' ') + "/>"
|
78
|
+
end
|
79
|
+
def event_as_gpx(e,index)
|
80
|
+
"<trkpt lat=\"#{e.latitude}\" lon=\"#{e.longitude}\"><ele>#{index}</ele><time>#{e.time}</time></trkpt>"
|
81
|
+
end
|
82
|
+
def as_gpx
|
83
|
+
ei = 0
|
84
|
+
gpx = %{<?xml version="1.0" encoding="UTF-8"?>
|
85
|
+
<gpx version="1.1" creator="geoptima.rb - Craig Taverner">
|
86
|
+
<metadata>
|
87
|
+
#{bounds_as_gpx}
|
88
|
+
</metadata>
|
89
|
+
<trk>
|
90
|
+
<name>#{tracename}</name>
|
91
|
+
<trkseg>
|
92
|
+
} +
|
93
|
+
events.map do |e|
|
94
|
+
ei += 1
|
95
|
+
event_as_gpx(e,ei)
|
96
|
+
end.join("\n ") +
|
97
|
+
"""
|
98
|
+
</trkseg>
|
99
|
+
</trk>
|
100
|
+
</gpx>
|
101
|
+
"""
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
36
105
|
module ErrorCounter
|
37
106
|
attr_reader :errors
|
38
107
|
def errors
|
@@ -135,6 +204,12 @@ module Geoptima
|
|
135
204
|
def time_key
|
136
205
|
utc.strftime("%Y-%m-%d %H:%M:%S.%3N").gsub(/\.(\d{3})\d+/,'.\1')
|
137
206
|
end
|
207
|
+
def days_from(other)
|
208
|
+
(other.time - time).abs
|
209
|
+
end
|
210
|
+
def distance_from(other)
|
211
|
+
Math.sqrt((other.latitude.to_f - latitude.to_f)**2 + (other.longitude.to_f - longitude.to_f)**2)
|
212
|
+
end
|
138
213
|
def [](key)
|
139
214
|
@fields[key] || @fields[key.gsub(/#{name}\./,'')]
|
140
215
|
end
|
@@ -516,6 +591,20 @@ module Geoptima
|
|
516
591
|
@sorted
|
517
592
|
end
|
518
593
|
|
594
|
+
def each_trace
|
595
|
+
puts "Exporting GPX traces"
|
596
|
+
trace = nil
|
597
|
+
sorted('gps').each do |gps|
|
598
|
+
trace ||= Trace.new(self)
|
599
|
+
if trace.too_far(gps)
|
600
|
+
yield trace
|
601
|
+
trace = Trace.new(self)
|
602
|
+
end
|
603
|
+
trace << gps
|
604
|
+
end
|
605
|
+
yield trace if(trace)
|
606
|
+
end
|
607
|
+
|
519
608
|
def locate_events
|
520
609
|
prev_gps = nil
|
521
610
|
count = 0
|
data/lib/geoptima/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoptima
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 12
|
10
|
+
version: 0.1.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Craig Taverner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: multi_json
|