geoptima 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  == Welcome to geoptima.rb
2
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.
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 capable of reading the JSON format files produced 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
+ More recent versions of this script, since about 0.1.0, have been able to perform statistics and generate charts. See below for the csv_chart script usage.
4
6
 
5
7
  For more information on Geoptima refer to:
6
8
  * {AmanziTel}[http://www.amanzitel.com] - for commercial applications and platforms supporting Geoptima
@@ -18,29 +20,34 @@ This script imports the JSON files on the command-line and then:
18
20
  * Optionally prints out all events on the console for visual inspection (using the -p option)
19
21
  * 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
22
  * The CSV export mode has many further options for exporting to multiple files (-s), merging IMEI's into single dataset (-a), long headers with repeated information (-l), etc.
23
+ * Configuration of the export format (static columns and header names) is possible with the -l and -M options
21
24
 
22
25
  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:
23
26
 
24
- Usage: show_geoptima <-dpvxomlsah> <-L limit> <-E types> <-T min,max> file <files>
27
+ Usage: show_geoptima <-dwvpxomlsafh> <-P export_prefix> <-L limit> <-E types> <-T min,max> <-M mapfile> file <files>
25
28
  -d debug mode (output more context during processing) (false)
29
+ -w verbose mode (output extra information to console)
30
+ -v print geoptima library version 0.1.7
26
31
  -p print mode (print out final results to console)
27
- -v verbose mode (output extra information to console)
28
32
  -x export IMEI specific CSV files for further processing
29
33
  -o export field statistis
30
34
  -m map headers to classic NetView compatible version
31
35
  -l longer header list (phone and operator fields)
32
36
  -s seperate the export files by event type
33
37
  -a combine all IMEI's into a single dataset
38
+ -f flush stdout
34
39
  -h show this help
40
+ -P prefix for exported files (default: ''; current: )
35
41
  -E comma-seperated list of event types to show and export (default: all; current: )
36
42
  -T time range to limit results to (default: all; current: )
37
43
  -L limit verbose output to specific number of lines (10000)
44
+ -M mapfile of normal->altered header names:
38
45
 
39
46
  Currently the script also locates events that are close enough in time to GPS events. We hope to improve this with interpolation in the near future to be more compatible with the results from the commercial solutions. This time-window is also used for some of the extended header information, like LAC and CI, and effectively duplicates those fields from their own events to others. Take this into account when doing statistics on the results. It is better to use the original values, not the duplicates, if you want reliable statistics.
40
47
 
41
48
  ==== csv_stats
42
49
 
43
- This script reads any CSV file and outputs histograms of the values for each column. These can be manually imported into a spreadsheet or charting program for further analysis or charting.
50
+ This script reads any CSV file and outputs histograms of the values for each column. These can be manually imported into a spreadsheet or charting program for further analysis or charting. This script is to a large extent superceded by the csv_chart script which both calculates stats as well as generates charts of the results.
44
51
 
45
52
  ==== csv_charts
46
53
 
@@ -120,9 +127,11 @@ https://github.com/craigtaverner/geoptima.rb/blob/master/images/Chart_All_Call%2
120
127
  === Installation
121
128
 
122
129
  Two options:
123
- * As a RubyGem: jruby -S gem install geoptima
130
+ * As a RubyGem: gem install geoptima json
124
131
  * From source: git clone git@github.com:craigtaverner/geoptima.rb.git
125
132
 
133
+ If you install without the json gem you will get a working library but not well optimized for JSON parsing. To install the json gem you need the minimal build environment for installing C code gems. On Linux and Mac this is usually already the case (or fix with 'apt-get install build-essential'). On windows you need to install the DevKit. See below for windows specific installation instructions.
134
+
126
135
  When installing the ruby gem you get the commands like 'show_geoptima' and 'csv_charts' in the path. However, if you install from source, you instead get them as examples/show_geoptima.rb.
127
136
 
128
137
  git clone git@github.com:craigtaverner/geoptima.rb.git
@@ -131,13 +140,23 @@ When installing the ruby gem you get the commands like 'show_geoptima' and 'csv_
131
140
 
132
141
  This should produce a file called 357841036600753.csv containing a CSV version of the Geoptima events for importing into Excel or OpenOffice.Calc for further processing. The number is the IMEI of the phone used, and if you process many JSON files in one go, you will get as many output files as there are phones represented by the data.
133
142
 
134
- The examples directory also contains a number of sample *.spec files for the csv_chart command.
143
+ The examples directory also contains a number of sample *.spec files for the csv_chart command. In order for csv_chart to be able to generate charts, you need to also install a supported chart library. We have planned support for various charting libraries, but at the moment only support GRUFF. For installation of GRUFF, see below.
135
144
 
136
145
  ==== Installing on Windows
137
146
 
138
147
  For windows use the RubyInstaller at http://rubyinstaller.org/
139
148
 
140
- To get chart support working you will probably need to install the DevKit as described on https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
149
+ To get the optimized json gem installed, or to get chart support working you will need to install the DevKit as described on https://github.com/oneclick/rubyinstaller/wiki/Development-Kit. Please follow those instructions carefully as they are not entirely trivial.
150
+
151
+ ==== Running on Windows
152
+
153
+ The best way to run on windows is to edit your system path (usually go to 'my computer->properties->advanced->environment), and add the path to your ruby bin directory (usually C:\Ruby\bin) to the end of the system PATH. After that, open a command-prompt (start->cmd.exe) and type 'ruby -v' to see that it worked. Then you can execute the 'gem install' commands and the 'show_geoptima' commands from this console.
154
+
155
+ ==== Installing Gruff for Charting
156
+
157
+ In order to support charting, you need to install Gruff (see http://nubyonrails.com/pages/gruff). This depends on image-magick, so you need to install that first. Please refer to the installation instructions specific to your OS. On Ubuntu the following should work:
158
+ apt-get install imagemagick libmagickcore-dev
159
+ gem install rmagick
141
160
 
142
161
  === Contributing
143
162
 
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.6")
13
+ Geoptima::assert_version(">=0.1.6")
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.6")
12
+ Geoptima::assert_version(">=0.1.6")
13
13
 
14
14
  $export_dir = '.'
15
15
  $export_name = 'merged.csv'
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'date'
3
+ # useful if being run inside a source code checkout
4
+ $: << 'lib'
5
+ $: << '../lib'
4
6
 
5
- $root=DateTime.parse("1970-01-01 00:00:00")
6
- ARGV.each do |arg|
7
- base,seconds=arg.split(/_/)
8
- date = ($root + seconds.to_f/(60*60*24))
9
- puts "#{date}\t#{arg}"
7
+ require 'geoptima/version'
8
+ require 'geoptima/file_time'
9
+
10
+ Geoptima::assert_version(">=0.1.7")
11
+
12
+ ARGV.each do |filename|
13
+ puts "#{(filename.to_s+" "*40)[0..40]} --> #{Geoptima::FileTime.from_file filename}"
10
14
  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.6")
11
+ Geoptima::assert_version(">=0.1.6")
12
12
 
13
13
  $debug=false
14
14
 
@@ -18,7 +18,6 @@ $print_limit = 10000
18
18
 
19
19
  $files = Geoptima::Options.process_args do |option|
20
20
  option.p {$print = true}
21
- option.v {$verbose = true}
22
21
  option.x {$export = true}
23
22
  option.s {$seperate = true}
24
23
  option.o {$export_stats = true}
@@ -104,13 +103,16 @@ def show_header_maps
104
103
  end
105
104
  end
106
105
 
106
+ exit 0 if($print_version && !$verbose)
107
+
107
108
  $help = true if($files.length < 1)
108
109
  if $help
109
110
  puts <<EOHELP
110
- Usage: show_geoptima <-dpvxomlsah> <-L limit> <-E types> <-T min,max> <-M mapfile> file <files>
111
+ Usage: show_geoptima <-dwvpxomlsafh> <-P export_prefix> <-L limit> <-E types> <-T min,max> <-M mapfile> file <files>
111
112
  -d debug mode (output more context during processing) #{cw $debug}
113
+ -w verbose mode (output extra information to console) #{cw $verbose}
114
+ -v print geoptima library version #{Geoptima::VERSION}
112
115
  -p print mode (print out final results to console) #{cw $print}
113
- -v verbose mode (output extra information to console) #{cw $verbose}
114
116
  -x export IMEI specific CSV files for further processing #{cw $export}
115
117
  -o export field statistis #{cw $export_stats}
116
118
  -m map headers to classic NetView compatible version #{cw $map_headers}
@@ -10,7 +10,7 @@ require 'geoptima/options'
10
10
  require 'fileutils'
11
11
  require 'geoptima/daterange'
12
12
 
13
- Geoptima::assert_version("0.1.6")
13
+ Geoptima::assert_version(">=0.1.6")
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.6")
12
+ Geoptima::assert_version(">=0.1.6")
13
13
 
14
14
  $export_dir = '.'
15
15
  $export_name = 'merged.csv'
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'date'
3
+ # useful if being run inside a source code checkout
4
+ $: << 'lib'
5
+ $: << '../lib'
4
6
 
5
- $root=DateTime.parse("1970-01-01 00:00:00")
6
- ARGV.each do |arg|
7
- base,seconds=arg.split(/_/)
8
- date = ($root + seconds.to_f/(60*60*24))
9
- puts "#{date}\t#{arg}"
7
+ require 'geoptima/version'
8
+ require 'geoptima/file_time'
9
+
10
+ Geoptima::assert_version(">=0.1.7")
11
+
12
+ ARGV.each do |filename|
13
+ puts "#{(filename.to_s+" "*40)[0..40]} --> #{Geoptima::FileTime.from_file filename}"
10
14
  end
@@ -8,7 +8,7 @@ require 'date'
8
8
  require 'geoptima'
9
9
  require 'geoptima/options'
10
10
 
11
- Geoptima::assert_version("0.1.6")
11
+ Geoptima::assert_version(">=0.1.6")
12
12
 
13
13
  $debug=false
14
14
 
@@ -18,7 +18,6 @@ $print_limit = 10000
18
18
 
19
19
  $files = Geoptima::Options.process_args do |option|
20
20
  option.p {$print = true}
21
- option.v {$verbose = true}
22
21
  option.x {$export = true}
23
22
  option.s {$seperate = true}
24
23
  option.o {$export_stats = true}
@@ -104,13 +103,16 @@ def show_header_maps
104
103
  end
105
104
  end
106
105
 
106
+ exit 0 if($print_version && !$verbose)
107
+
107
108
  $help = true if($files.length < 1)
108
109
  if $help
109
110
  puts <<EOHELP
110
- Usage: show_geoptima <-dpvxomlsah> <-L limit> <-E types> <-T min,max> <-M mapfile> file <files>
111
+ Usage: show_geoptima <-dwvpxomlsafh> <-P export_prefix> <-L limit> <-E types> <-T min,max> <-M mapfile> file <files>
111
112
  -d debug mode (output more context during processing) #{cw $debug}
113
+ -w verbose mode (output extra information to console) #{cw $verbose}
114
+ -v print geoptima library version #{Geoptima::VERSION}
112
115
  -p print mode (print out final results to console) #{cw $print}
113
- -v verbose mode (output extra information to console) #{cw $verbose}
114
116
  -x export IMEI specific CSV files for further processing #{cw $export}
115
117
  -o export field statistis #{cw $export_stats}
116
118
  -m map headers to classic NetView compatible version #{cw $map_headers}
data/lib/geoptima/data.rb CHANGED
@@ -12,7 +12,9 @@ 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")
15
+ MIN_VALID_DATETIME = DateTime.parse("1970-01-01")
16
+ MAX_VALID_DATETIME = DateTime.parse("2040-01-01")
17
+ MIN_DATETIME = DateTime.parse("2008-01-01")
16
18
  MAX_DATETIME = DateTime.parse("2040-01-01")
17
19
 
18
20
  class Config
@@ -141,10 +143,10 @@ module Geoptima
141
143
  start && start >= (Data.min_start-1) && start < Data.max_start
142
144
  end
143
145
  def self.min_start
144
- @@min_start ||= MIN_DATETIME
146
+ @@min_start ||= MIN_VALID_DATETIME
145
147
  end
146
148
  def self.max_start
147
- @@max_start ||= MAX_DATETIME
149
+ @@max_start ||= MAX_VALID_DATETIME
148
150
  end
149
151
  def events
150
152
  @events ||= make_events
@@ -25,12 +25,12 @@ module Geoptima
25
25
  @range = Range.new(@min,@max)
26
26
  end
27
27
  if ENV['RUBY_VERSION'] =~ /1\.8/
28
- puts "Defining Range.include? to wrap for 1.8"
28
+ puts "Defining Range.include? to wrap for 1.8" if($verbose)
29
29
  def include?(time)
30
30
  @range.include?(time)
31
31
  end
32
32
  else
33
- puts "Defining Range.include? to perform inequality tests for 1.9"
33
+ puts "Defining Range.include? to perform inequality tests for 1.9" if($verbose)
34
34
  def include?(time)
35
35
  (time >= min) && (time <= @max)
36
36
  end
@@ -0,0 +1,30 @@
1
+ require 'date'
2
+
3
+ module Geoptima
4
+ module FileTime
5
+ @@root=DateTime.parse("1970-01-01 00:00:00")
6
+ DAY_SECONDS = 24 * 60 * 60
7
+ DAY_MILLIS = DAY_SECONDS * 1000
8
+ HUNDRED_YEARS_SECONDS = 100 * 365 * DAY_SECONDS
9
+ HUNDRED_YEARS_MILLIS = HUNDRED_YEARS_SECONDS * 1000
10
+ def self.from_file(arg)
11
+ base,time=arg.to_s.split(/_/)
12
+ self.from(time)
13
+ end
14
+ def self.from(time)
15
+ time = time.to_f
16
+ ms = time > HUNDRED_YEARS_SECONDS
17
+ (@@root + time.to_f/(ms ? DAY_MILLIS : DAY_SECONDS))
18
+ end
19
+ end
20
+ end
21
+
22
+ if $PROGRAM_NAME =~ /\/file_time.rb$/
23
+ puts "Running test cases"
24
+ [123456789,1337089446603].each do |time|
25
+ puts "#{(time.to_s+" "*40)[0..40]} --> #{Geoptima::FileTime.from time}"
26
+ end
27
+ ["356409048945284_1334764343.json","353491048201465_1337160798.json","3859F91B6B2C_1337097736981.json","\"724044021273460_1337093857605.txt\""].each do |filename|
28
+ puts "#{(filename.to_s+" "*40)[0..40]} --> #{Geoptima::FileTime.from_file filename}"
29
+ end
30
+ end
@@ -47,6 +47,7 @@ module Geoptima
47
47
  options = Options.new(debug)
48
48
  options.add('f') {$flush_stdout = true}
49
49
  options.add('v') {$print_version = true}
50
+ options.add('w') {$verbose = true}
50
51
  options.add('d') {$debug = true}
51
52
  options.add('h') {$help = true}
52
53
  puts "Processing options: #{options}" if(debug)
@@ -1,29 +1,88 @@
1
1
  module Geoptima
2
2
 
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
 
5
- def self.version_as_int(ver)
6
- base = 1
7
- ver.split(/\./).reverse.inject(0) do |acc,v|
8
- acc += base * v.to_i
9
- base *= 100
10
- acc
5
+ class Version
6
+ attr_reader :comparator, :version, :major, :minor, :patch
7
+ def initialize(text)
8
+ @comparator,@version = clean_version(text)
9
+ @major,@minor,@patch=@version.split(/\./)
11
10
  end
11
+ def clean_version(version)
12
+ comparator,cleaned = "==", version
13
+ if version =~ /^([\>\<\=]+)(\d+\.\d+\.\d+)/
14
+ comparator = $1[0..2]
15
+ cleaned = $2
16
+ end
17
+ [comparator,cleaned]
18
+ end
19
+ def to_i
20
+ unless @version_int
21
+ base = 1
22
+ @version_int = version.split(/\./).reverse.inject(0) do |acc,v|
23
+ acc += base * v.to_i
24
+ base *= 100
25
+ acc
26
+ end
27
+ end
28
+ @version_int
29
+ end
30
+ def to_s
31
+ version
32
+ end
33
+ def as_geoptima_version
34
+ self
35
+ end
36
+ def compare(other)
37
+ ogv = other.as_geoptima_version
38
+ self.to_i.send(ogv.comparator, ogv.to_i)
39
+ end
40
+ def diff(other)
41
+ other.as_geoptima_version.to_i - self.to_i
42
+ end
43
+ end
44
+
45
+ def self.version
46
+ @@version ||= VERSION.as_geoptima_version
12
47
  end
13
48
 
14
- def self.compare_version(expected_ver)
15
- version_as_int(expected_ver) - version_as_int(VERSION)
49
+ def self.version=(test_version)
50
+ @@version = test_version.as_geoptima_version
16
51
  end
17
52
 
18
- def self.assert_version(expected_ver)
19
- if expected_ver.to_s != VERSION
20
- diff = compare_version(expected_ver)
21
- if(diff != 0)
22
- msg = diff > 0 ? "against and older library" : "an older script"
23
- puts "Geoptima library version mismatch. Expected #{expected_ver}, found #{VERSION}. Are you running #{msg}?"
53
+ def self.assert_version(expected_ver, test_mode = false)
54
+ unless version.compare(expected_ver)
55
+ diff = version.diff(expected_ver)
56
+ if(!test_mode)
57
+ puts "Geoptima library version mismatch. Expected #{expected_ver}, found #{version}."
24
58
  exit -1
25
59
  end
60
+ return diff
26
61
  end
62
+ true
27
63
  end
28
64
 
29
65
  end
66
+
67
+ class String
68
+ def as_geoptima_version
69
+ Geoptima::Version.new(self)
70
+ end
71
+ end
72
+
73
+ if $PROGRAM_NAME =~ /version.rb$/
74
+ test_lib_versions = ["0.1.5","0.1.6","0.1.7"]
75
+ test_comparators = ["","==","<","<=",">",">="]
76
+ test_lib_versions.each do |lib_ver|
77
+ Geoptima.version = lib_ver
78
+ puts "Testing with library version: #{lib_ver}"
79
+ puts (["Version"]+test_comparators.map{|v| "#{v} "[0..3]}).join(" | ")
80
+ test_lib_versions.map do |test_ver|
81
+ puts "#{test_ver} | "+(test_comparators.map do |comp|
82
+ expected_ver = "#{comp}#{test_ver}"
83
+ Geoptima.assert_version expected_ver, true
84
+ end.map{|v| " #{v}"[-4..-1]}.join(" | "))
85
+ end
86
+ end
87
+ end
88
+
data/lib/geoptima.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'geoptima/version.rb'
2
2
  require 'geoptima/data.rb'
3
3
  require 'geoptima/options.rb'
4
+ require 'geoptima/file_time.rb'
4
5
 
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Craig Taverner
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-23 00:00:00 +02:00
19
- default_executable:
18
+ date: 2012-05-18 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: multi_json
@@ -80,22 +79,22 @@ files:
80
79
  - lib/geoptima/version.rb
81
80
  - lib/geoptima/data.rb
82
81
  - lib/geoptima/chart.rb
83
- - lib/geoptima/options.rb
84
82
  - lib/geoptima/daterange.rb
83
+ - lib/geoptima/options.rb
84
+ - lib/geoptima/file_time.rb
85
85
  - lib/geoptima.rb
86
86
  - examples/show_geoptima_sos.rb
87
87
  - examples/show_geoptima.rb
88
88
  - examples/csv_chart.rb
89
+ - examples/csv_merge.rb
89
90
  - examples/geoptima_file_time.rb
90
91
  - examples/csv_stats.rb
91
- - examples/csv_merge.rb
92
92
  - examples/sample_geoptima.json
93
93
  - README.rdoc
94
94
  - CHANGELOG
95
95
  - CONTRIBUTORS
96
96
  - Gemfile
97
97
  - geoptima.gemspec
98
- has_rdoc: true
99
98
  homepage: http://github.com/craigtaverner/geoptima.rb
100
99
  licenses: []
101
100
 
@@ -133,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
132
  requirements: []
134
133
 
135
134
  rubyforge_project: geoptima
136
- rubygems_version: 1.6.2
135
+ rubygems_version: 1.8.15
137
136
  signing_key:
138
137
  specification_version: 3
139
138
  summary: Ruby access to Geoptima JSON files