geoptima 0.1.8 → 0.1.9
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/show_geoptima +2 -1
- data/examples/show_geoptima.rb +2 -1
- data/lib/geoptima/data.rb +76 -5
- data/lib/geoptima/version.rb +1 -1
- metadata +4 -4
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.
|
11
|
+
Geoptima::assert_version(">=0.1.9")
|
12
12
|
|
13
13
|
$debug=false
|
14
14
|
|
@@ -297,6 +297,7 @@ $datasets.keys.sort.each do |imei|
|
|
297
297
|
if $verbose
|
298
298
|
puts "\tFirst Event: #{dataset.first}"
|
299
299
|
puts "\tLast Event: #{dataset.last}"
|
300
|
+
dataset.report_errors "\t"
|
300
301
|
end
|
301
302
|
if events && ($print || $export)
|
302
303
|
names = $event_names
|
data/examples/show_geoptima.rb
CHANGED
@@ -8,7 +8,7 @@ require 'date'
|
|
8
8
|
require 'geoptima'
|
9
9
|
require 'geoptima/options'
|
10
10
|
|
11
|
-
Geoptima::assert_version(">=0.1.
|
11
|
+
Geoptima::assert_version(">=0.1.9")
|
12
12
|
|
13
13
|
$debug=false
|
14
14
|
|
@@ -297,6 +297,7 @@ $datasets.keys.sort.each do |imei|
|
|
297
297
|
if $verbose
|
298
298
|
puts "\tFirst Event: #{dataset.first}"
|
299
299
|
puts "\tLast Event: #{dataset.last}"
|
300
|
+
dataset.report_errors "\t"
|
300
301
|
end
|
301
302
|
if events && ($print || $export)
|
302
303
|
names = $event_names
|
data/lib/geoptima/data.rb
CHANGED
@@ -33,9 +33,34 @@ module Geoptima
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
module ErrorCounter
|
37
|
+
attr_reader :errors
|
38
|
+
def errors
|
39
|
+
@errors ||= {}
|
40
|
+
end
|
41
|
+
def incr_error(name)
|
42
|
+
errors[name] ||= 0
|
43
|
+
errors[name] += 1
|
44
|
+
end
|
45
|
+
def combine_errors(other)
|
46
|
+
puts "Combining errors(#{other.class}:#{other.errors.inspect}) into self(#{self.class}:#{errors.inspect})" if($debug)
|
47
|
+
other.errors.keys.each do |name|
|
48
|
+
errors[name] = errors[name].to_i + other.errors[name].to_i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def report_errors(prefix=nil)
|
52
|
+
if errors && errors.keys.length > 0
|
53
|
+
puts "#{prefix}Have #{errors.keys.length} known errors in #{self}:"
|
54
|
+
errors.keys.sort.each do |name|
|
55
|
+
puts "#{prefix}\t#{name}:\t#{errors[name]}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
36
61
|
# The Geoptima::Event class represents and individual record or event
|
37
62
|
class Event
|
38
|
-
KNOWN_HEADERS={
|
63
|
+
KNOWN_HEADERS = {
|
39
64
|
"gps" => ["timeoffset","latitude","longitude","altitude","accuracy","direction","speed"],
|
40
65
|
"service" => ["timeoffset","plmn","cell_id","lac","mnc","mcc"],
|
41
66
|
"call" => ["timeoffset","status","number"],
|
@@ -48,8 +73,27 @@ module Geoptima
|
|
48
73
|
"httpRequest" => ["timeoffset","interface","address","delay","speed"],
|
49
74
|
"dnsLookup" => ["timeoffset","interface","address","lookupTime","ip"],
|
50
75
|
"ftpSpeed" => ["timeoffset","interface","direction","delay","peak","speed"],
|
51
|
-
"browserDedicatedTest" => ["timeoffset","url","pageRenders","pageRendered","pageSize","success"]
|
76
|
+
"browserDedicatedTest" => ["timeoffset","url","pageRenders","pageRendered","pageSize","success"],
|
77
|
+
"pingTest" => ["timeoffset","interface","address","count","length","pingTime","packetLossPercent","jitter","error"]
|
52
78
|
}
|
79
|
+
HEADER_BUGS = {
|
80
|
+
'ftpSpeed' => '#4303',
|
81
|
+
'pingTest' => '#4509'
|
82
|
+
}
|
83
|
+
ALT_HEADERS = {
|
84
|
+
"pingTest" => [
|
85
|
+
["timeoffset","interface","address","count","length","pingTime","packetLossPercent","jitter","error"],
|
86
|
+
["timeoffset","id","interface","address","count","length","pingTime","packetLossPercent","jitter","error"]
|
87
|
+
],
|
88
|
+
"ftpSpeed" => [
|
89
|
+
["timeoffset","interface","direction","delay","speed"],
|
90
|
+
["timeoffset","interface","direction","delay","peak","speed"],
|
91
|
+
["timeoffset","interface","direction","delay","peak","speed","error"],
|
92
|
+
["timeoffset","interface","direction","delay","peak","speed","size","error"]
|
93
|
+
]
|
94
|
+
}
|
95
|
+
|
96
|
+
include ErrorCounter
|
53
97
|
attr_reader :file, :header, :name, :data, :fields, :time, :latitude, :longitude
|
54
98
|
def initialize(file,start,name,header,data)
|
55
99
|
@file = file
|
@@ -60,11 +104,17 @@ module Geoptima
|
|
60
104
|
a[v] = check_field(@data[a.length])
|
61
105
|
a
|
62
106
|
end
|
63
|
-
|
107
|
+
timeoffset = (@fields['timeoffset'].to_f / MSPERDAY.to_f)
|
108
|
+
if(timeoffset<-0.0000001)
|
109
|
+
puts "Have negative time offset: #{@fields['timeoffset']}" if($debug)
|
110
|
+
incr_error "#4506 negative offsets"
|
111
|
+
end
|
112
|
+
@time = start + timeoffset
|
64
113
|
@fields.reject!{|k,v| k=~/timeoffset/}
|
65
114
|
if @fields['cell_id'].to_i > SHORT
|
66
115
|
@fields['cell_id'] = @fields['cell_id'].to_i % SHORT
|
67
116
|
end
|
117
|
+
incr_error "Empty data" if(data.length == 0)
|
68
118
|
puts "Created Event: #{self}" if($debug)
|
69
119
|
end
|
70
120
|
def check_field(field)
|
@@ -102,12 +152,14 @@ module Geoptima
|
|
102
152
|
|
103
153
|
# The Geoptima::Data is an entire JSON file of events
|
104
154
|
class Data
|
155
|
+
include ErrorCounter
|
105
156
|
attr_reader :path, :json, :count
|
106
157
|
def initialize(path)
|
107
158
|
@path = path
|
108
159
|
# @json = JSON.parse(File.read(path))
|
109
160
|
@json = MultiJson.decode(File.read(path))
|
110
161
|
@fields = {}
|
162
|
+
@errors = {}
|
111
163
|
if $debug
|
112
164
|
puts "Read Geoptima: #{geoptima.to_json}"
|
113
165
|
puts "\tSubscriber: #{subscriber.to_json}"
|
@@ -118,6 +170,10 @@ module Geoptima
|
|
118
170
|
puts "\tStart: #{start}"
|
119
171
|
end
|
120
172
|
end
|
173
|
+
def incr_error(name)
|
174
|
+
@errors[name] ||= 0
|
175
|
+
@errors[name] += 1
|
176
|
+
end
|
121
177
|
def to_s
|
122
178
|
json.to_json[0..100]
|
123
179
|
end
|
@@ -193,6 +249,16 @@ module Geoptima
|
|
193
249
|
if mismatch != 0
|
194
250
|
puts "'#{event_type}' header length #{header.length} incompatible with data length #{events.length}"
|
195
251
|
header = nil
|
252
|
+
incr_error "Metadata mismatch"
|
253
|
+
if Event::ALT_HEADERS.keys.grep(event_type).length>0
|
254
|
+
incr_error "#{Event::HEADER_BUGS[event_type]} #{event_type}"
|
255
|
+
[Event::KNOWN_HEADERS[event_type],*(Event::ALT_HEADERS[event_type])].each do |alt_header|
|
256
|
+
if alt_header && (events.length % alt_header.length) == 0
|
257
|
+
header = alt_header
|
258
|
+
puts "Found alternative header that matches #{event_type}: #{header.join(',')}"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
196
262
|
end
|
197
263
|
else
|
198
264
|
puts "No header found for event type: #{event_type}"
|
@@ -204,9 +270,12 @@ module Geoptima
|
|
204
270
|
record = events[index...(index+header.length)]
|
205
271
|
if record && record.length == header.length
|
206
272
|
@count += 1
|
207
|
-
|
273
|
+
event = Event.new(self,start,event_type,header,record)
|
274
|
+
combine_errors event
|
275
|
+
a << event
|
208
276
|
else
|
209
277
|
puts "Invalid '#{event_type}' data block #{block}: #{record.inspect}"
|
278
|
+
incr_error "Invalid data block"
|
210
279
|
break a
|
211
280
|
end
|
212
281
|
end
|
@@ -226,7 +295,7 @@ module Geoptima
|
|
226
295
|
@first = nil
|
227
296
|
@last = nil
|
228
297
|
events_data.each do |event_type,data|
|
229
|
-
if data.length >
|
298
|
+
if data.length > 0
|
230
299
|
@first ||= data[0]
|
231
300
|
@last ||= data[-1]
|
232
301
|
@first = data[0] if(@first && @first.time > data[0].time)
|
@@ -243,6 +312,7 @@ module Geoptima
|
|
243
312
|
|
244
313
|
class Dataset
|
245
314
|
|
315
|
+
include ErrorCounter
|
246
316
|
attr_reader :name, :options
|
247
317
|
|
248
318
|
def initialize(name,options={})
|
@@ -409,6 +479,7 @@ module Geoptima
|
|
409
479
|
event_hash[key] = event
|
410
480
|
end
|
411
481
|
end
|
482
|
+
combine_errors data
|
412
483
|
end
|
413
484
|
puts "After adding #{name} events, maps are #{event_hash.length} long" if($debug)
|
414
485
|
end
|
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: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Craig Taverner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: multi_json
|