geoptima 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/csv_chart CHANGED
@@ -10,7 +10,7 @@ require 'geoptima/options'
10
10
  require 'fileutils'
11
11
  require 'geoptima/daterange'
12
12
 
13
- Geoptima::assert_version("0.1.2")
13
+ Geoptima::assert_version("0.1.3")
14
14
  Geoptima::Chart.available? || puts("No charting libraries available") || exit(-1)
15
15
 
16
16
  $export_dir = '.'
data/bin/csv_merge CHANGED
@@ -9,7 +9,7 @@ require 'geoptima/options'
9
9
  require 'fileutils'
10
10
  require 'geoptima/daterange'
11
11
 
12
- Geoptima::assert_version("0.1.2")
12
+ Geoptima::assert_version("0.1.3")
13
13
 
14
14
  $export_dir = '.'
15
15
  $export_name = 'merged.csv'
data/bin/show_geoptima CHANGED
@@ -7,7 +7,7 @@ $: << '../lib'
7
7
  require 'date'
8
8
  require 'geoptima'
9
9
 
10
- Geoptima::assert_version("0.1.2")
10
+ Geoptima::assert_version("0.1.3")
11
11
 
12
12
  $debug=false
13
13
 
@@ -15,51 +15,33 @@ $event_names=[]
15
15
  $files = []
16
16
  $print_limit = 10000
17
17
 
18
- while arg=ARGV.shift do
19
- if arg =~ /^\-(\w+)/
20
- $1.split(//).each do |aa|
21
- case aa
22
- when 'h'
23
- $help=true
24
- when 'd'
25
- $debug=true
26
- when 'p'
27
- $print=true
28
- when 'v'
29
- $verbose=true
30
- when 'x'
31
- $export=true
32
- when 's'
33
- $seperate=true
34
- when 'o'
35
- $export_stats=true
36
- when 'm'
37
- $map_headers=true
38
- when 'a'
39
- $combine_all=true
40
- when 'l'
41
- $more_headers=true
42
- when 'E'
43
- $event_names += ARGV.shift.split(/[\,\;\:\.]+/)
44
- when 'T'
45
- $time_range = Range.new(*(ARGV.shift.split(/[\,]+/).map do |t|
46
- DateTime.parse t
47
- end))
48
- when 'L'
49
- $print_limit = ARGV.shift.to_i
50
- $print_limit = 10 if($print_limit<1)
51
- else
52
- puts "Unrecognized option: -#{aa}"
53
- end
54
- end
55
- else
56
- if File.exist? arg
57
- $files << arg
58
- else
59
- puts "No such file: #{arg}"
60
- end
61
- end
62
- end
18
+ $files = Geoptima::Options.process_args do |option|
19
+ option.p {$print = true}
20
+ option.v {$verbose = true}
21
+ option.x {$export = true}
22
+ option.s {$seperate = true}
23
+ option.o {$export_stats = true}
24
+ option.m {$map_headers = true}
25
+ option.a {$combine_all = true}
26
+ option.l {$more_headers = true}
27
+ option.E {$event_names += ARGV.shift.split(/[\,\;\:\.]+/)}
28
+ option.T do
29
+ $time_range = Geoptima::DateRange.from ARGV.shift
30
+ end
31
+ option.L {$print_limit = [1,ARGV.shift.to_i].max}
32
+
33
+ option.t {$time_split = true}
34
+ option.D {$export_dir = ARGV.shift}
35
+ option.N {$merged_name = ARGV.shift}
36
+ option.S {$specfile = ARGV.shift}
37
+ option.P {$diversity = ARGV.shift.to_f}
38
+ option.W {$chart_width = ARGV.shift.to_i}
39
+ option.T do
40
+ $time_range = Geoptima::DateRange.from ARGV.shift
41
+ end
42
+ end.map do |file|
43
+ File.exist?(file) ? file : puts("No such file: #{file}")
44
+ end.compact
63
45
 
64
46
  $help = true if($files.length < 1)
65
47
  if $help
@@ -231,6 +213,10 @@ $datasets.keys.sort.each do |imei|
231
213
  events = dataset.sorted
232
214
  puts if($print)
233
215
  puts "Found #{dataset}"
216
+ if $verbose
217
+ puts "\tFirst Event: #{dataset.first}"
218
+ puts "\tLast Event: #{dataset.last}"
219
+ end
234
220
  if events && ($print || $export)
235
221
  names = $event_names
236
222
  names = dataset.events_names if(names.length<1)
@@ -10,7 +10,7 @@ require 'geoptima/options'
10
10
  require 'fileutils'
11
11
  require 'geoptima/daterange'
12
12
 
13
- Geoptima::assert_version("0.1.2")
13
+ Geoptima::assert_version("0.1.3")
14
14
  Geoptima::Chart.available? || puts("No charting libraries available") || exit(-1)
15
15
 
16
16
  $export_dir = '.'
@@ -9,7 +9,7 @@ require 'geoptima/options'
9
9
  require 'fileutils'
10
10
  require 'geoptima/daterange'
11
11
 
12
- Geoptima::assert_version("0.1.2")
12
+ Geoptima::assert_version("0.1.3")
13
13
 
14
14
  $export_dir = '.'
15
15
  $export_name = 'merged.csv'
@@ -7,7 +7,7 @@ $: << '../lib'
7
7
  require 'date'
8
8
  require 'geoptima'
9
9
 
10
- Geoptima::assert_version("0.1.2")
10
+ Geoptima::assert_version("0.1.3")
11
11
 
12
12
  $debug=false
13
13
 
@@ -15,51 +15,33 @@ $event_names=[]
15
15
  $files = []
16
16
  $print_limit = 10000
17
17
 
18
- while arg=ARGV.shift do
19
- if arg =~ /^\-(\w+)/
20
- $1.split(//).each do |aa|
21
- case aa
22
- when 'h'
23
- $help=true
24
- when 'd'
25
- $debug=true
26
- when 'p'
27
- $print=true
28
- when 'v'
29
- $verbose=true
30
- when 'x'
31
- $export=true
32
- when 's'
33
- $seperate=true
34
- when 'o'
35
- $export_stats=true
36
- when 'm'
37
- $map_headers=true
38
- when 'a'
39
- $combine_all=true
40
- when 'l'
41
- $more_headers=true
42
- when 'E'
43
- $event_names += ARGV.shift.split(/[\,\;\:\.]+/)
44
- when 'T'
45
- $time_range = Range.new(*(ARGV.shift.split(/[\,]+/).map do |t|
46
- DateTime.parse t
47
- end))
48
- when 'L'
49
- $print_limit = ARGV.shift.to_i
50
- $print_limit = 10 if($print_limit<1)
51
- else
52
- puts "Unrecognized option: -#{aa}"
53
- end
54
- end
55
- else
56
- if File.exist? arg
57
- $files << arg
58
- else
59
- puts "No such file: #{arg}"
60
- end
61
- end
62
- end
18
+ $files = Geoptima::Options.process_args do |option|
19
+ option.p {$print = true}
20
+ option.v {$verbose = true}
21
+ option.x {$export = true}
22
+ option.s {$seperate = true}
23
+ option.o {$export_stats = true}
24
+ option.m {$map_headers = true}
25
+ option.a {$combine_all = true}
26
+ option.l {$more_headers = true}
27
+ option.E {$event_names += ARGV.shift.split(/[\,\;\:\.]+/)}
28
+ option.T do
29
+ $time_range = Geoptima::DateRange.from ARGV.shift
30
+ end
31
+ option.L {$print_limit = [1,ARGV.shift.to_i].max}
32
+
33
+ option.t {$time_split = true}
34
+ option.D {$export_dir = ARGV.shift}
35
+ option.N {$merged_name = ARGV.shift}
36
+ option.S {$specfile = ARGV.shift}
37
+ option.P {$diversity = ARGV.shift.to_f}
38
+ option.W {$chart_width = ARGV.shift.to_i}
39
+ option.T do
40
+ $time_range = Geoptima::DateRange.from ARGV.shift
41
+ end
42
+ end.map do |file|
43
+ File.exist?(file) ? file : puts("No such file: #{file}")
44
+ end.compact
63
45
 
64
46
  $help = true if($files.length < 1)
65
47
  if $help
@@ -231,6 +213,10 @@ $datasets.keys.sort.each do |imei|
231
213
  events = dataset.sorted
232
214
  puts if($print)
233
215
  puts "Found #{dataset}"
216
+ if $verbose
217
+ puts "\tFirst Event: #{dataset.first}"
218
+ puts "\tLast Event: #{dataset.last}"
219
+ end
234
220
  if events && ($print || $export)
235
221
  names = $event_names
236
222
  names = dataset.events_names if(names.length<1)
data/lib/geoptima/data.rb CHANGED
@@ -12,9 +12,11 @@ module Geoptima
12
12
  SPERDAY = 60*60*24
13
13
  MSPERDAY = 1000*60*60*24
14
14
  SHORT = 256*256
15
+ MIN_DATETIME = DateTime.parse("2000-01-01")
16
+ MAX_DATETIME = DateTime.parse("2040-01-01")
15
17
 
16
18
  class Config
17
- DEFAULT={:min_datetime => DateTime.parse("2000-01-01"), :max_datetime => DateTime.parse("2030-01-01")}
19
+ DEFAULT={:min_datetime => MIN_DATETIME, :max_datetime => MAX_DATETIME}
18
20
  def self.config(options={})
19
21
  @@options = (@@options || DEFAULT).merge(options)
20
22
  end
@@ -117,6 +119,9 @@ module Geoptima
117
119
  def geoptima
118
120
  @geoptima ||= json['geoptima']
119
121
  end
122
+ def version
123
+ @version ||= geoptima['Version'] || geoptima['version']
124
+ end
120
125
  def subscriber
121
126
  @subscriber ||= geoptima['subscriber']
122
127
  end
@@ -133,14 +138,20 @@ module Geoptima
133
138
  start && start > Data.min_start && start < Data.max_start
134
139
  end
135
140
  def self.min_start
136
- @@min_start ||= DateTime.parse("2010-01-01 00:00:00")
141
+ @@min_start ||= MIN_DATETIME
137
142
  end
138
143
  def self.max_start
139
- @@max_start ||= DateTime.parse("2020-01-01 00:00:00")
144
+ @@max_start ||= MAX_DATETIME
140
145
  end
141
146
  def events
142
147
  @events ||= make_events
143
148
  end
149
+ def first
150
+ events && @first
151
+ end
152
+ def last
153
+ events && @last
154
+ end
144
155
  def events_names
145
156
  events.keys.sort
146
157
  end
@@ -164,6 +175,8 @@ module Geoptima
164
175
  events = data['values']
165
176
  event_type = data.keys.reject{|k| k=~/values/}[0]
166
177
  header = @events_metadata[event_type]
178
+ # If the JSON is broken (known bug on some releases of the iPhone app)
179
+ # Then get the header information from a list of known headers
167
180
  unless header
168
181
  puts "No header found for '#{event_type}', trying known Geoptima headers"
169
182
  header = Event::KNOWN_HEADERS[event_type]
@@ -181,6 +194,7 @@ module Geoptima
181
194
  end
182
195
  end
183
196
  end
197
+ # Now process the single long data array into a list of events with timestamps
184
198
  if header
185
199
  events_data[event_type] = (0...data[event_type].to_i).inject([]) do |a,block|
186
200
  index = header.length * block
@@ -204,8 +218,24 @@ module Geoptima
204
218
  puts "No header found for event type: #{event_type}"
205
219
  end
206
220
  end
221
+ find_first_and_last(events_data)
207
222
  events_data
208
223
  end
224
+ def find_first_and_last(events_data)
225
+ @first = nil
226
+ @last = nil
227
+ events_data.each do |event_type,data|
228
+ @first ||= data[0]
229
+ @last ||= data[-1]
230
+ @first = data[0] if(@first.time > data[0].time)
231
+ @last = data[-1] if(@last.time < data[-1].time)
232
+ end
233
+ if $debug
234
+ puts "For data: #{self}"
235
+ puts "\tFirst event: #{@first}"
236
+ puts "\tLast event: #{@last}"
237
+ end
238
+ end
209
239
  end
210
240
 
211
241
  class Dataset
@@ -353,13 +383,8 @@ module Geoptima
353
383
  @data.each do |data|
354
384
  puts "Processing #{(e=data.events[name]) && e.length} events for #{name}" if($debug)
355
385
  (events = data.events[name]) && events.each do |event|
356
- # t = event.time.to_i
357
386
  puts "\t\tTesting #{event.time} inside #{@time_range}" if($debug)
358
- # if t < tmax
359
- # if event.time > @time_range.min
360
- # if (event.time >= @time_range.min) && (event.time < @time_range.max)
361
387
  if @time_range.include?(event.time)
362
- # if @time_range.cover?(event.time)
363
388
  puts "\t\t\tEvent at #{event.time} is inside #{@time_range}" if($debug)
364
389
  key = "#{event.time_key} #{name}"
365
390
  event_hash[key] = event
@@ -1,6 +1,6 @@
1
1
  module Geoptima
2
2
 
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
 
5
5
  def self.version_as_int(ver)
6
6
  base = 1
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Craig Taverner
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-26 00:00:00 Z
18
+ date: 2012-04-04 00:00:00 +02:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: multi_json
@@ -93,6 +94,7 @@ files:
93
94
  - CONTRIBUTORS
94
95
  - Gemfile
95
96
  - geoptima.gemspec
97
+ has_rdoc: true
96
98
  homepage: http://github.com/craigtaverner/geoptima.rb
97
99
  licenses: []
98
100
 
@@ -130,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  requirements: []
131
133
 
132
134
  rubyforge_project: geoptima
133
- rubygems_version: 1.7.2
135
+ rubygems_version: 1.6.2
134
136
  signing_key:
135
137
  specification_version: 3
136
138
  summary: Ruby access to Geoptima JSON files