geoptima 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/bin/csv_merge CHANGED
@@ -213,8 +213,8 @@ class CSVDatasets
213
213
  filename = "#{$export_dir}/#{$export_name}"
214
214
  File.open(filename,'w') do |out|
215
215
  out.puts headers.join("\t")
216
- @datasets.sort.each(headers) do |dataset|
217
- dataset.each do |day,line|
216
+ @datasets.sort.each do |dataset|
217
+ dataset.each(headers) do |day,line|
218
218
  out.puts line.join("\t")
219
219
  end
220
220
  end
data/bin/show_geoptima CHANGED
@@ -8,7 +8,7 @@ require 'date'
8
8
  require 'geoptima'
9
9
  require 'geoptima/options'
10
10
 
11
- Geoptima::assert_version(">=0.1.14")
11
+ Geoptima::assert_version(">=0.1.15")
12
12
 
13
13
  $debug=false
14
14
 
@@ -18,7 +18,7 @@ $print_limit = 10000
18
18
  $gpx_options = {
19
19
  'scale' => 190, 'padding' => 5,
20
20
  'limit' => 2, 'png_limit' => 10,
21
- 'points' => true, 'point_size' => 2, 'point_color' => '0000aa'
21
+ 'points' => true, 'point_size' => 2, 'point_color' => 'auto'
22
22
  }
23
23
 
24
24
  $files = Geoptima::Options.process_args do |option|
@@ -147,12 +147,13 @@ Usage: show_geoptima <-dwvpxomlsafegh> <-P export_prefix> <-L limit> <-E types>
147
147
  Known supported GPX options (might be more, see data.rb code):
148
148
  limit:#{$gpx_options['limit']}\t\tLimit GPX output to traces with at least this number of events
149
149
  png_limit:#{$gpx_options['png_limit']}\t\tLimit PNG output to traces with at least this number of events
150
+ merge:#{$gpx_options['merge']}\t\tMerge all traces into a single trace
150
151
  scale:#{$gpx_options['scale']}\t\tSize of print area in PNG output
151
152
  padding:#{$gpx_options['padding']}\t\tSpace around print area
152
153
  points:#{$gpx_options['points']}\t\tTurn on/off points
153
154
  point_size:#{$gpx_options['point_size']}\t\tSet point size
154
155
  point_color:#{$gpx_options['point_color']}\tSet point color: RRGGBBAA in hex (else 'auto')
155
- format:#{$gpx_options['format']}\t\tExport format: 'gpx', 'png', default 'all'
156
+ format:#{$gpx_options['format']}\t\tExport format: 'gpx', 'csv', 'png', default 'all'
156
157
  PNG images will be 'scale + 2 * padding' big (#{$gpx_options['scale'].to_i+2*$gpx_options['padding'].to_i} for current settings). The scale will be used for the widest dimension, and the other will be reduced to fit the actual size of the trace. The projection used is non, with the points simply mapped to their GPS locations. This will cause visual distortions far from the equator where dlat!=dlon.
157
158
  EOHELP
158
159
  show_header_maps
@@ -290,16 +291,24 @@ class Export
290
291
  end
291
292
  end
292
293
  end
293
- def export_gpx(trace)
294
- if !($gpx_options['format'].to_s =~ /png/)
294
+ def self.export_gpx(trace)
295
+ if $gpx_options['format'].to_s =~ /^(gpx|all|)$/
295
296
  File.open("#{$export_prefix}#{trace}.gpx",'w') do |out|
296
297
  puts "Exporting #{trace.length} GPS events to trace: #{trace}"
297
298
  out.puts trace.as_gpx
298
299
  end
299
300
  end
300
301
  end
301
- def export_png(trace)
302
- if !($gpx_options['format'].to_s =~ /gpx/)
302
+ def self.export_gps(trace)
303
+ if $gpx_options['format'].to_s =~ /^(csv|all|)$/
304
+ File.open("#{$export_prefix}#{trace}.csv",'w') do |out|
305
+ puts "Exporting #{trace.length} GPS events to trace: #{trace}"
306
+ out.puts trace.as_csv
307
+ end
308
+ end
309
+ end
310
+ def self.export_png(trace)
311
+ if $gpx_options['format'].to_s =~ /^(png|all|)$/
303
312
  puts "Exporting #{trace.length} GPS events to PNG: #{trace}"
304
313
  if $verbose
305
314
  puts "\tBounds: #{trace.bounds}"
@@ -363,23 +372,25 @@ $datasets.keys.sort.each do |imei|
363
372
  puts "\tLast Event: #{dataset.last}"
364
373
  dataset.report_errors "\t"
365
374
  end
375
+ if $export_gpx
376
+ merged_traces = Geoptima::MergedTrace.new(dataset)
377
+ dataset.each_trace do |trace|
378
+ Export.export_gpx(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
379
+ Export.export_gps(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
380
+ Export.export_png(trace) if(trace.length>=($gpx_options['png_limit'] || 10).to_i)
381
+ merged_traces << trace if($gpx_options['merge'])
382
+ end
383
+ if($gpx_options['merge'])
384
+ Export.export_gpx(merged_traces)
385
+ Export.export_gps(merged_traces)
386
+ Export.export_png(merged_traces)
387
+ end
388
+ end
366
389
  if events && ($print || $export)
367
390
  names = $event_names
368
391
  names = dataset.events_names if(names.length<1)
369
392
  export = Export.new(imei,names,dataset)
370
393
  export.export_stats(dataset.stats) if($export_stats)
371
- if $export_gpx
372
- merged_traces = Geoptima::MergedTrace.new(dataset)
373
- dataset.each_trace do |trace|
374
- export.export_gpx(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
375
- export.export_png(trace) if(trace.length>=($gpx_options['png_limit'] || 10).to_i)
376
- merged_traces << trace if($gpx_options['merge'])
377
- end
378
- if($gpx_options['merge'])
379
- export.export_gpx(merged_traces)
380
- export.export_png(merged_traces)
381
- end
382
- end
383
394
  if $header_maps && $header_maps.length > 0
384
395
  $header_maps.each do |hm|
385
396
  puts "Searching for events for header_maps '#{hm.event}'"
@@ -213,8 +213,8 @@ class CSVDatasets
213
213
  filename = "#{$export_dir}/#{$export_name}"
214
214
  File.open(filename,'w') do |out|
215
215
  out.puts headers.join("\t")
216
- @datasets.sort.each(headers) do |dataset|
217
- dataset.each do |day,line|
216
+ @datasets.sort.each do |dataset|
217
+ dataset.each(headers) do |day,line|
218
218
  out.puts line.join("\t")
219
219
  end
220
220
  end
@@ -8,7 +8,7 @@ require 'date'
8
8
  require 'geoptima'
9
9
  require 'geoptima/options'
10
10
 
11
- Geoptima::assert_version(">=0.1.14")
11
+ Geoptima::assert_version(">=0.1.15")
12
12
 
13
13
  $debug=false
14
14
 
@@ -18,7 +18,7 @@ $print_limit = 10000
18
18
  $gpx_options = {
19
19
  'scale' => 190, 'padding' => 5,
20
20
  'limit' => 2, 'png_limit' => 10,
21
- 'points' => true, 'point_size' => 2, 'point_color' => '0000aa'
21
+ 'points' => true, 'point_size' => 2, 'point_color' => 'auto'
22
22
  }
23
23
 
24
24
  $files = Geoptima::Options.process_args do |option|
@@ -147,12 +147,13 @@ Usage: show_geoptima <-dwvpxomlsafegh> <-P export_prefix> <-L limit> <-E types>
147
147
  Known supported GPX options (might be more, see data.rb code):
148
148
  limit:#{$gpx_options['limit']}\t\tLimit GPX output to traces with at least this number of events
149
149
  png_limit:#{$gpx_options['png_limit']}\t\tLimit PNG output to traces with at least this number of events
150
+ merge:#{$gpx_options['merge']}\t\tMerge all traces into a single trace
150
151
  scale:#{$gpx_options['scale']}\t\tSize of print area in PNG output
151
152
  padding:#{$gpx_options['padding']}\t\tSpace around print area
152
153
  points:#{$gpx_options['points']}\t\tTurn on/off points
153
154
  point_size:#{$gpx_options['point_size']}\t\tSet point size
154
155
  point_color:#{$gpx_options['point_color']}\tSet point color: RRGGBBAA in hex (else 'auto')
155
- format:#{$gpx_options['format']}\t\tExport format: 'gpx', 'png', default 'all'
156
+ format:#{$gpx_options['format']}\t\tExport format: 'gpx', 'csv', 'png', default 'all'
156
157
  PNG images will be 'scale + 2 * padding' big (#{$gpx_options['scale'].to_i+2*$gpx_options['padding'].to_i} for current settings). The scale will be used for the widest dimension, and the other will be reduced to fit the actual size of the trace. The projection used is non, with the points simply mapped to their GPS locations. This will cause visual distortions far from the equator where dlat!=dlon.
157
158
  EOHELP
158
159
  show_header_maps
@@ -290,16 +291,24 @@ class Export
290
291
  end
291
292
  end
292
293
  end
293
- def export_gpx(trace)
294
- if !($gpx_options['format'].to_s =~ /png/)
294
+ def self.export_gpx(trace)
295
+ if $gpx_options['format'].to_s =~ /^(gpx|all|)$/
295
296
  File.open("#{$export_prefix}#{trace}.gpx",'w') do |out|
296
297
  puts "Exporting #{trace.length} GPS events to trace: #{trace}"
297
298
  out.puts trace.as_gpx
298
299
  end
299
300
  end
300
301
  end
301
- def export_png(trace)
302
- if !($gpx_options['format'].to_s =~ /gpx/)
302
+ def self.export_gps(trace)
303
+ if $gpx_options['format'].to_s =~ /^(csv|all|)$/
304
+ File.open("#{$export_prefix}#{trace}.csv",'w') do |out|
305
+ puts "Exporting #{trace.length} GPS events to trace: #{trace}"
306
+ out.puts trace.as_csv
307
+ end
308
+ end
309
+ end
310
+ def self.export_png(trace)
311
+ if $gpx_options['format'].to_s =~ /^(png|all|)$/
303
312
  puts "Exporting #{trace.length} GPS events to PNG: #{trace}"
304
313
  if $verbose
305
314
  puts "\tBounds: #{trace.bounds}"
@@ -363,23 +372,25 @@ $datasets.keys.sort.each do |imei|
363
372
  puts "\tLast Event: #{dataset.last}"
364
373
  dataset.report_errors "\t"
365
374
  end
375
+ if $export_gpx
376
+ merged_traces = Geoptima::MergedTrace.new(dataset)
377
+ dataset.each_trace do |trace|
378
+ Export.export_gpx(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
379
+ Export.export_gps(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
380
+ Export.export_png(trace) if(trace.length>=($gpx_options['png_limit'] || 10).to_i)
381
+ merged_traces << trace if($gpx_options['merge'])
382
+ end
383
+ if($gpx_options['merge'])
384
+ Export.export_gpx(merged_traces)
385
+ Export.export_gps(merged_traces)
386
+ Export.export_png(merged_traces)
387
+ end
388
+ end
366
389
  if events && ($print || $export)
367
390
  names = $event_names
368
391
  names = dataset.events_names if(names.length<1)
369
392
  export = Export.new(imei,names,dataset)
370
393
  export.export_stats(dataset.stats) if($export_stats)
371
- if $export_gpx
372
- merged_traces = Geoptima::MergedTrace.new(dataset)
373
- dataset.each_trace do |trace|
374
- export.export_gpx(trace) if(trace.length>=($gpx_options['limit'] || 1).to_i)
375
- export.export_png(trace) if(trace.length>=($gpx_options['png_limit'] || 10).to_i)
376
- merged_traces << trace if($gpx_options['merge'])
377
- end
378
- if($gpx_options['merge'])
379
- export.export_gpx(merged_traces)
380
- export.export_png(merged_traces)
381
- end
382
- end
383
394
  if $header_maps && $header_maps.length > 0
384
395
  $header_maps.each do |hm|
385
396
  puts "Searching for events for header_maps '#{hm.event}'"
data/lib/geoptima/data.rb CHANGED
@@ -112,9 +112,10 @@ module Geoptima
112
112
  def scale
113
113
  @scale ||= [100,100]
114
114
  unless @rescaled
115
- major,minor = (width > height) ? [0,1] : [1,0]
116
- puts "About to rescale scale=#{@scale.inspect} using major=#{major}, minor=#{minor}, height=#{height}, width=#{width}" if($debug)
117
- @scale[minor] = (@scale[major].to_f * height / width).to_i
115
+ major = [width,height].max
116
+ puts "About to rescale scale=#{@scale.inspect} using major=#{major}, height=#{height}, width=#{width}" if($debug)
117
+ @scale[0] = (@scale[0].to_f * width / major).to_i
118
+ @scale[1] = (@scale[1].to_f * height / major).to_i
118
119
  @rescaled = true
119
120
  end
120
121
  @scale
@@ -135,7 +136,7 @@ module Geoptima
135
136
  [totals[0] / totals[2], totals[1] / totals[2]]
136
137
  end
137
138
  def remove_outliers
138
- if width > 0.1 || height > 0.1
139
+ if @bounds && (width > 0.1 || height > 0.1)
139
140
  distances = []
140
141
  total_distance = 0.0
141
142
  max_distance = 0.0
@@ -199,6 +200,13 @@ module Geoptima
199
200
  </gpx>
200
201
  """
201
202
  end
203
+ def as_csv
204
+ traces.map do |trace|
205
+ trace.events.map do |e|
206
+ [e.time_key,e.latitude,e.longitude].join("\t")
207
+ end.join("\n")
208
+ end.join("\n")
209
+ end
202
210
  def fix_options(options={})
203
211
  options.keys.each do |key|
204
212
  val = options[key]
@@ -220,6 +228,7 @@ module Geoptima
220
228
  self.colors[index%(self.colors.length)]
221
229
  end
222
230
  def to_png(filename, options={})
231
+ return unless(length>0)
223
232
  fix_options options
224
233
  puts "Exporting with options: #{options.inspect}"
225
234
  self.scale = options['scale']
@@ -242,6 +251,7 @@ module Geoptima
242
251
  end
243
252
  end
244
253
  traces.each_with_index do |trace,index|
254
+ point_color = color(index)
245
255
  line_color = PNG::Color.from "0x00006688"
246
256
  if options['point_color'] && !(options['point_color'] =~ /auto/i)
247
257
  pc = options['point_color'].gsub(/^\#/,'').gsub(/^0x/,'').upcase
@@ -256,7 +266,7 @@ module Geoptima
256
266
  puts "Got point color #{point_color} from data ID '#{trace.data_id}' index #{data_idm[trace.data_id]}" if($debug)
257
267
  else
258
268
  point_color = color(index)
259
- puts "Got point color #{point_color} from trace index #{index}"
269
+ puts "Got point color #{point_color} from trace index #{index}" if($debug)
260
270
  end
261
271
 
262
272
  prev = nil
@@ -1,6 +1,6 @@
1
1
  module Geoptima
2
2
 
3
- VERSION = "0.1.14"
3
+ VERSION = "0.1.15"
4
4
 
5
5
  class Version
6
6
  attr_reader :comparator, :version, :major, :minor, :patch
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoptima
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-03 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json