geoptima 0.1.2 → 0.1.3
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.
- data/bin/csv_chart +1 -1
- data/bin/csv_merge +1 -1
- data/bin/show_geoptima +32 -46
- data/examples/csv_chart.rb +1 -1
- data/examples/csv_merge.rb +1 -1
- data/examples/show_geoptima.rb +32 -46
- data/lib/geoptima/data.rb +33 -8
- data/lib/geoptima/version.rb +1 -1
- metadata +7 -5
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.
|
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
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.
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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/examples/csv_chart.rb
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.
|
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/examples/csv_merge.rb
CHANGED
data/examples/show_geoptima.rb
CHANGED
@@ -7,7 +7,7 @@ $: << '../lib'
|
|
7
7
|
require 'date'
|
8
8
|
require 'geoptima'
|
9
9
|
|
10
|
-
Geoptima::assert_version("0.1.
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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 =>
|
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 ||=
|
141
|
+
@@min_start ||= MIN_DATETIME
|
137
142
|
end
|
138
143
|
def self.max_start
|
139
|
-
@@max_start ||=
|
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
|
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: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
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-
|
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.
|
135
|
+
rubygems_version: 1.6.2
|
134
136
|
signing_key:
|
135
137
|
specification_version: 3
|
136
138
|
summary: Ruby access to Geoptima JSON files
|