geoptima 0.0.1
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/CHANGELOG +2 -0
- data/CONTRIBUTORS +5 -0
- data/Gemfile +15 -0
- data/README.rdoc +68 -0
- data/bin/show_geoptima +161 -0
- data/examples/export_layer.rb +59 -0
- data/examples/sample_geoptima.json +1173 -0
- data/examples/show_geoptima.rb +161 -0
- data/examples/show_geoptima_sos.rb +50 -0
- data/examples/stats.rb +41 -0
- data/geoptima.gemspec +31 -0
- data/lib/geoptima/data.rb +311 -0
- data/lib/geoptima/version.rb +3 -0
- data/lib/geoptima.rb +3 -0
- metadata +96 -0
data/CHANGELOG
ADDED
data/CONTRIBUTORS
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source :gemcutter
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group 'test' do
|
6
|
+
gem "rake", ">= 0.8.7"
|
7
|
+
gem "rdoc", ">= 2.5.10"
|
8
|
+
gem "horo", ">= 1.0.2"
|
9
|
+
gem "rspec", ">= 2.0.0"
|
10
|
+
gem "test-unit"
|
11
|
+
end
|
12
|
+
|
13
|
+
#gem 'ruby-debug-base19' if RUBY_VERSION.include? "1.9"
|
14
|
+
#gem 'ruby-debug-base' if RUBY_VERSION.include? "1.8"
|
15
|
+
#gem "ruby-debug-ide"
|
data/README.rdoc
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
== Welcome to geoptima.rb
|
2
|
+
|
3
|
+
Geoptima is a suite of applications for measuring and locating mobile/cellular subscriber experience on GPS enabled smartphones. It is produced by AmanziTel AB in Helsingborg, Sweden, and supports many phone manufacturers, with free downloads from the various app stores, markets or marketplaces. This Ruby library is only capable of reading the JSON format files priduced by these phones and reformating them as CSV for further analysis in Excel. This is a simple and independent way of analysing the data, when compared to the full-featured analysis applications and servers available from AmanziTel. If you want to analyse a limited amount of data in excel, or with Ruby, then this GEM might be for you. If you want to analyse large amounts of data, from many subscribers, or over long periods of time then rather consider the NetView and Customer IQ applications from AmanziTel at www.amanzitel.com.
|
4
|
+
|
5
|
+
For more information on Geoptima refer to:
|
6
|
+
* {AmanziTel}[http://www.amanzitel.com] - for commercial applications and platforms supporting Geoptima
|
7
|
+
* {Geoptima on Android}[https://market.android.com/details?id=com.AmanziTel.Geoptima] - on the android market
|
8
|
+
* For Geoptima on other plaforms, use the phone to search the relevant app-store or market
|
9
|
+
|
10
|
+
=== Documentation
|
11
|
+
|
12
|
+
The current version includes the core geoptima.rb library as well as a few command-line apps for using the library.
|
13
|
+
|
14
|
+
== show_geoptima.rb
|
15
|
+
|
16
|
+
This script simply imports the JSON files on the command-line and then:
|
17
|
+
* Prints out basic information about each file (subscriber information, start date and number of events)
|
18
|
+
* Optionally prints out all events on the console for visual inspection (using the -p option)
|
19
|
+
* Optionally prints out all events to files in CSV format with merging of event types and fields into a single header for further processing with Excel or OpenOffice (using the -x option)
|
20
|
+
|
21
|
+
Which event types to include and various other options are available using the command-line. Run it with the -h option to get a full list of options. The current version should support:
|
22
|
+
|
23
|
+
Usage: ./showGeoptimaEvents.rb <-dvxEh> <-L limit> <-E types> <-T min,max> file <files>
|
24
|
+
-d debug mode (output more context during processing) (false)
|
25
|
+
-p print mode (print out final results to console)
|
26
|
+
-v verbose mode (output extra information to console)
|
27
|
+
-x export IMEI specific CSV files for further processing
|
28
|
+
-s seperate the export files by event type
|
29
|
+
-h show this help
|
30
|
+
-L limit verbose output to specific number of lines (10000)
|
31
|
+
-E comma-seperated list of event types to show and export (default: all; current: )
|
32
|
+
-T time range to limit results to (default: all; current: )
|
33
|
+
|
34
|
+
Currently the script also locates events that are close enough in time to GPS events.
|
35
|
+
|
36
|
+
== show_geoptima_sos.rb
|
37
|
+
|
38
|
+
This is a simplified version of the above script with special support for finding the SOS events in Blackberry phones. Run with the JSON files on the command line and it will print out all SOS events, possibly located to close GPS events.
|
39
|
+
|
40
|
+
=== Installation
|
41
|
+
|
42
|
+
Two options:
|
43
|
+
* As a RubyGem: jruby -S gem install geoptima
|
44
|
+
* From source: git clone git@github.com:craigtaverner/geoptima.rb.git
|
45
|
+
|
46
|
+
=== Some Examples
|
47
|
+
|
48
|
+
.. to be done ..
|
49
|
+
(or see the code in the command-line utilities described below for examples)
|
50
|
+
|
51
|
+
=== Command-line utilities
|
52
|
+
|
53
|
+
The examples directory includes a few sample Ruby scripts for various import/export tasks, as well as some sample Geoptima data to test on. Consider the following run:
|
54
|
+
|
55
|
+
git clone git@github.com:craigtaverner/geoptima.rb.git
|
56
|
+
cd geoptima.rb/examples
|
57
|
+
./geoptima.rb -x craig.json
|
58
|
+
|
59
|
+
This should produce a file called ####.txt containing a CSV version of the Geoptima events for importing into Excel or OpenOffice.Calc for further processing.
|
60
|
+
|
61
|
+
=== Contributing
|
62
|
+
|
63
|
+
Have you found a bug, need help or have a patch ?
|
64
|
+
Just clone geoptima.rb and send me a pull request or email me.
|
65
|
+
|
66
|
+
=== License
|
67
|
+
|
68
|
+
MIT, see the LICENSE file http://github.com/craigtaverner/geoptima.rb/tree/master/LICENSE.
|
data/bin/show_geoptima
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# useful if being run inside a source code checkout
|
4
|
+
$: << 'lib'
|
5
|
+
$: << '../lib'
|
6
|
+
|
7
|
+
require 'date'
|
8
|
+
require 'geoptima'
|
9
|
+
|
10
|
+
$debug=false
|
11
|
+
|
12
|
+
$event_names=[]
|
13
|
+
$files = []
|
14
|
+
$print_limit = 10000
|
15
|
+
|
16
|
+
def cw(val)
|
17
|
+
val.nil? ? '' : "(#{val})"
|
18
|
+
end
|
19
|
+
|
20
|
+
while arg=ARGV.shift:
|
21
|
+
if arg =~ /^\-(\w+)/
|
22
|
+
$1.split(//).each do |aa|
|
23
|
+
case aa
|
24
|
+
when 'h'
|
25
|
+
$help=true
|
26
|
+
when 'd'
|
27
|
+
$debug=true
|
28
|
+
when 'p'
|
29
|
+
$print=true
|
30
|
+
when 'v'
|
31
|
+
$verbose=true
|
32
|
+
when 'x'
|
33
|
+
$export=true
|
34
|
+
when 's'
|
35
|
+
$seperate=true
|
36
|
+
when 'E'
|
37
|
+
$event_names += ARGV.shift.split(/[\,\;\:\.]+/)
|
38
|
+
when 'T'
|
39
|
+
$time_range = Range.new(*(ARGV.shift.split(/[\,]+/).map do |t|
|
40
|
+
DateTime.parse t
|
41
|
+
end))
|
42
|
+
when 'L'
|
43
|
+
$print_limit = ARGV.shift.to_i
|
44
|
+
$print_limit = 10 if($print_limit<1)
|
45
|
+
else
|
46
|
+
puts "Unrecognized option: -#{aa}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
else
|
50
|
+
if File.exist? arg
|
51
|
+
$files << arg
|
52
|
+
else
|
53
|
+
puts "No such file: #{arg}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
$help = true if($files.length < 1)
|
59
|
+
if $help
|
60
|
+
puts <<EOHELP
|
61
|
+
Usage: ./showGeoptimaEvents.rb <-dvxEh> <-L limit> <-E types> <-T min,max> file <files>
|
62
|
+
-d debug mode (output more context during processing) #{cw $debug}
|
63
|
+
-p print mode (print out final results to console) #{cw $print}
|
64
|
+
-v verbose mode (output extra information to console) #{cw $verbose}
|
65
|
+
-x export IMEI specific CSV files for further processing #{cw $export}
|
66
|
+
-s seperate the export files by event type #{cw $seperate}
|
67
|
+
-h show this help
|
68
|
+
-L limit verbose output to specific number of lines #{cw $print_limit}
|
69
|
+
-E comma-seperated list of event types to show and export (default: all; current: #{$event_names.join(',')})
|
70
|
+
-T time range to limit results to (default: all; current: #{$time_range})
|
71
|
+
EOHELP
|
72
|
+
exit 0
|
73
|
+
end
|
74
|
+
|
75
|
+
$verbose = $verbose || $debug
|
76
|
+
$datasets = Geoptima::Dataset.make_datasets($files, :locate => true, :time_range => $time_range)
|
77
|
+
|
78
|
+
class Export
|
79
|
+
attr_reader :files, :names, :headers
|
80
|
+
def initialize(imei,names,dataset)
|
81
|
+
@names = names
|
82
|
+
if $export
|
83
|
+
if $seperate
|
84
|
+
@files = names.inject({}) do |a,name|
|
85
|
+
a[name] = File.open("#{imei}_#{name}.csv",'w')
|
86
|
+
a
|
87
|
+
end
|
88
|
+
else
|
89
|
+
@files={nil => File.open("#{imei}.csv",'w')}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
@headers = names.inject({}) do |a,name|
|
93
|
+
a[name] = dataset.header([name]).reject{|h| h === 'timeoffset'}
|
94
|
+
puts "Created header for name #{name}: #{a[name].join(',')}" if($debug)
|
95
|
+
a
|
96
|
+
end
|
97
|
+
@headers[nil] = @headers.values.flatten
|
98
|
+
files && files.each do |key,file|
|
99
|
+
file.puts "Time\tEvent\tLatitude\tLongitude\t#{header(key).join("\t")}\n"
|
100
|
+
end
|
101
|
+
if $debug || $verbose
|
102
|
+
@headers.each do |name,head|
|
103
|
+
puts "Header[#{name}]: #{head.join(',')}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
def header(name=nil)
|
108
|
+
@headers[name]
|
109
|
+
end
|
110
|
+
def puts_to(line,name)
|
111
|
+
name = nil unless($seperate)
|
112
|
+
files[name].puts(line) if($export && files[name])
|
113
|
+
end
|
114
|
+
def puts_to_all(line)
|
115
|
+
files && files.each do |key,file|
|
116
|
+
file.puts line
|
117
|
+
end
|
118
|
+
end
|
119
|
+
def close
|
120
|
+
files && files.each do |key,file|
|
121
|
+
file.close
|
122
|
+
@files[key] = nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def if_le
|
128
|
+
$count ||= 0
|
129
|
+
if $print
|
130
|
+
if $count < $print_limit
|
131
|
+
yield
|
132
|
+
elsif $count == $print_limit
|
133
|
+
puts " ... "
|
134
|
+
end
|
135
|
+
end
|
136
|
+
$count += 1
|
137
|
+
end
|
138
|
+
|
139
|
+
puts "Found #{$datasets.length} IMEIs"
|
140
|
+
$datasets.keys.sort.each do |imei|
|
141
|
+
dataset = $datasets[imei]
|
142
|
+
events = dataset.sorted
|
143
|
+
puts if($print)
|
144
|
+
puts "Found #{dataset}"
|
145
|
+
if events && ($print || $export)
|
146
|
+
names = $event_names
|
147
|
+
names = dataset.events_names if(names.length<1)
|
148
|
+
export = Export.new(imei,names,dataset)
|
149
|
+
events.each do |event|
|
150
|
+
names.each do |name|
|
151
|
+
if event.name === name
|
152
|
+
fields = export.header($seperate ? name : nil).map{|h| event[h]}
|
153
|
+
export.puts_to "#{event.time_key}\t#{event.name}\t#{event.latitude}\t#{event.longitude}\t#{fields.join("\t")}", name
|
154
|
+
if_le{puts "#{event.time_key}\t#{event.name}\t#{event.latitude}\t#{event.longitude}\t#{event.fields.inspect}"}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
export.close
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
# useful if being run inside a source code checkout
|
4
|
+
$: << 'lib'
|
5
|
+
$: << '../lib'
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'neo4j/spatial'
|
9
|
+
require 'neo4j/spatial/cmd'
|
10
|
+
|
11
|
+
$zoom = 1.0
|
12
|
+
$args = Neo4j::Spatial::Cmd.args
|
13
|
+
|
14
|
+
if $list === 'layers'
|
15
|
+
layers = Neo4j::Spatial::Layer.list
|
16
|
+
puts "Have #{layers.length} existing layers in the database:"
|
17
|
+
layers.each {|l| puts "\t#{l} (#{l.type_name})"}
|
18
|
+
puts
|
19
|
+
exit 0
|
20
|
+
end
|
21
|
+
|
22
|
+
if $help || $args.length < 1
|
23
|
+
puts <<-eos
|
24
|
+
|
25
|
+
usage: ./export_layer.rb <-D storage_path> <-F format> <-E dir> <-Z zoom> <-W width> <-H height> <-l> <-h> layer <layers>
|
26
|
+
-D Use specified database location
|
27
|
+
-F Use specified export format (png, shp)
|
28
|
+
-E Use specified export directory path (default '.')
|
29
|
+
-Z Zoom in by specified factor (eg. 3.0)
|
30
|
+
-W Image width (default 600)
|
31
|
+
-H Image height (default 400)
|
32
|
+
-l List existing database layers first
|
33
|
+
-h Display this help and exit
|
34
|
+
The layer(s) should be pre-existing layers (including dynamic layers) in the database.
|
35
|
+
Supported formats are 'shp' for ESRI Shapefile and 'png' for images.
|
36
|
+
|
37
|
+
For example:
|
38
|
+
./export_layer.rb -D db -E exports -F png croatia.osm highway highway-residential natural-water
|
39
|
+
|
40
|
+
This will export four previously defined layers to png format files in the 'exports' directory.
|
41
|
+
|
42
|
+
eos
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
if $format.to_s.downcase === 'shp'
|
47
|
+
$exporter = Neo4j::Spatial::SHPExporter.new :dir => $export
|
48
|
+
else
|
49
|
+
$exporter = Neo4j::Spatial::ImageExporter.new :dir => $export, :zoom => $zoom, :width => $width, :height => $height
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "Exporting #{$args.length} layers to #{$exporter.format}"
|
53
|
+
|
54
|
+
$args.each do |layer|
|
55
|
+
l = Neo4j::Spatial::Layer.find layer
|
56
|
+
puts "Exporting #{l} (#{l.type_name}) - #{l.index.layer_bounding_box}"
|
57
|
+
$exporter.export l.name
|
58
|
+
puts "Finished exporting #{l} (#{l.type_name}) of #{l.index.count} entries"
|
59
|
+
end
|