Class: Geoptima::Event
- Inherits:
-
Object
- Object
- Geoptima::Event
- Includes:
- ErrorCounter, Locatable
- Defined in:
- lib/geoptima/data.rb
Overview
The Geoptima::Event class represents and individual record or event
Constant Summary collapse
- KNOWN_HEADERS =
{ "gps" => ["timeoffset","latitude","longitude","altitude","accuracy","direction","speed"], "service" => ["timeoffset","plmn","cell_id","lac","mnc","mcc"], "call" => ["timeoffset","status","number"], "runningApps" => ["timeoffset","appName","state"], "batteryState" => ["timeoffset","state"], "trafficSpeed" => ["timeoffset","interface","direction","delay","speed"], "storageStatus" => ["timeoffset","path","totalSize","freeSize"], "signal" => ["timeoffset","strength","rxqual","ecio"], "roundtrip" => ["timeoffset","interface","address","type","roundtripTime"], "httpRequest" => ["timeoffset","interface","address","delay","speed"], "dnsLookup" => ["timeoffset","interface","address","lookupTime","ip"], "ftpSpeed" => ["timeoffset","interface","direction","delay","peak","speed"], "browserDedicatedTest" => ["timeoffset","url","pageRenders","pageRendered","pageSize","success"], "pingTest" => ["timeoffset","interface","address","count","length","pingTime","packetLossPercent","jitter","error"] }
- HEADER_BUGS =
{ 'ftpSpeed' => '#4303', 'pingTest' => '#4509' }
- ALT_HEADERS =
{ "pingTest" => [ ["timeoffset","interface","address","count","length","pingTime","packetLossPercent","jitter","error"], ["timeoffset","id","interface","address","count","length","pingTime","packetLossPercent","jitter","error"] ], "ftpSpeed" => [ ["timeoffset","interface","direction","delay","speed"], ["timeoffset","interface","direction","delay","peak","speed"], ["timeoffset","interface","direction","delay","peak","speed","error"], ["timeoffset","interface","direction","delay","peak","speed","size","error"] ] }
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#gps ⇒ Object
readonly
Returns the value of attribute gps.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#timeoffset ⇒ Object
readonly
Returns the value of attribute timeoffset.
Attributes included from Locatable
#next_gps, #next_point, #next_point_gap, #previous_gps, #previous_point, #previous_point_gap
Attributes included from ErrorCounter
Instance Method Summary collapse
- #-(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #check_field(field) ⇒ Object
- #closer_than(other, seconds = 60) ⇒ Object
- #days_from(other) ⇒ Object
- #description ⇒ Object
- #distance_from(other) ⇒ Object
- #gpx_id ⇒ Object
-
#initialize(file, start, name, header, data, previous = nil) ⇒ Event
constructor
A new instance of Event.
- #location ⇒ Object
- #puts(line) ⇒ Object
- #time_key ⇒ Object
- #to_s ⇒ Object
- #to_type ⇒ Object
- #utc ⇒ Object
- #valid_gpx? ⇒ Boolean
Methods included from Locatable
#set_next_if, #set_previous_if
Methods included from ErrorCounter
#combine_errors, #incr_error, #report_errors
Constructor Details
#initialize(file, start, name, header, data, previous = nil) ⇒ Event
Returns a new instance of Event.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/geoptima/data.rb', line 488 def initialize(file,start,name,header,data,previous=nil) @file = file @name = name @header = header @data = data @fields = @header.inject({}) do |a,v| a[v] = check_field(@data[a.length]) a end @timeoffset = (@fields['timeoffset'].to_f / MSPERDAY.to_f) @time = start + timeoffset # Note we set this again later after corrections (need it now for puts output) if(@timeoffset<-0.0000001) puts "Have negative time offset: #{@fields['timeoffset']}" if($debug) incr_error "#4506 negative offsets" end if previous prev_to = previous.timeoffset puts "Comparing timeoffset:#{timeoffset} to previous:#{prev_to}" if($debug) if @timeoffset == prev_to puts "Found the same timeoffset in consecutive events: #{name}:#{timeoffset} == #{previous.name}:#{previous.timeoffset}" incr_error "#4576 same timeoffset" @timeoffset = @timeoffset + 1.0 / MSPERDAY.to_f end end @time = start + timeoffset @fields.reject!{|k,v| k=~/timeoffset/} if @fields['cell_id'].to_i > SHORT @fields['cell_id'] = @fields['cell_id'].to_i % SHORT end incr_error "Empty data" if(data.length == 0) puts "Created Event: #{self}" if($debug) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def data @data end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def fields @fields end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def file @file end |
#gps ⇒ Object (readonly)
Returns the value of attribute gps.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def gps @gps end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def header @header end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def longitude @longitude end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def name @name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def time @time end |
#timeoffset ⇒ Object (readonly)
Returns the value of attribute timeoffset.
487 488 489 |
# File 'lib/geoptima/data.rb', line 487 def timeoffset @timeoffset end |
Instance Method Details
#-(other) ⇒ Object
541 542 543 |
# File 'lib/geoptima/data.rb', line 541 def -(other) (self.time - other.time) * SPERDAY end |
#[](key) ⇒ Object
535 536 537 |
# File 'lib/geoptima/data.rb', line 535 def [](key) @fields[key] || @fields[key.gsub(/#{name}\./,'')] end |
#[]=(key, value) ⇒ Object
538 539 540 |
# File 'lib/geoptima/data.rb', line 538 def []=(key,value) @fields[key] ||= value end |
#check_field(field) ⇒ Object
520 521 522 |
# File 'lib/geoptima/data.rb', line 520 def check_field(field) (field && field.respond_to?('length') && field =~ /\d\,\d/) ? field.gsub(/\,/,'.').to_f : field end |
#closer_than(other, seconds = 60) ⇒ Object
544 545 546 |
# File 'lib/geoptima/data.rb', line 544 def closer_than(other,seconds=60) (self - other).abs < seconds end |
#days_from(other) ⇒ Object
529 530 531 |
# File 'lib/geoptima/data.rb', line 529 def days_from(other) (other.time - time).abs end |
#description ⇒ Object
562 563 564 |
# File 'lib/geoptima/data.rb', line 562 def description "#{name}" end |
#distance_from(other) ⇒ Object
532 533 534 |
# File 'lib/geoptima/data.rb', line 532 def distance_from(other) Math.sqrt((other.latitude.to_f - latitude.to_f)**2 + (other.longitude.to_f - longitude.to_f)**2) end |
#gpx_id ⇒ Object
568 569 570 |
# File 'lib/geoptima/data.rb', line 568 def gpx_id file.id end |
#location ⇒ Object
553 554 555 |
# File 'lib/geoptima/data.rb', line 553 def location @location ||= self['latitude'] && Point.new(self['latitude'],self['longitude']) end |
#puts(line) ⇒ Object
556 557 558 |
# File 'lib/geoptima/data.rb', line 556 def puts line Kernel.puts "#{name}[#{time}]: #{line}" end |
#time_key ⇒ Object
526 527 528 |
# File 'lib/geoptima/data.rb', line 526 def time_key utc.strftime("%Y-%m-%d %H:%M:%S.%3N").gsub(/\.(\d{3})\d+/,'.\1') end |
#to_s ⇒ Object
559 560 561 |
# File 'lib/geoptima/data.rb', line 559 def to_s "#{name}[#{time}]: #{@fields.inspect}" end |
#to_type ⇒ Object
571 572 573 574 575 576 577 578 |
# File 'lib/geoptima/data.rb', line 571 def to_type case name when 'runningApps' RunningApps.new(self) else self end end |
#utc ⇒ Object
523 524 525 |
# File 'lib/geoptima/data.rb', line 523 def utc time.new_offset(0) end |
#valid_gpx? ⇒ Boolean
565 566 567 |
# File 'lib/geoptima/data.rb', line 565 def valid_gpx? location end |