Class: TacScribe::EventQueue

Inherits:
TacviewClient::BaseProcessor
  • Object
show all
Defined in:
lib/tac_scribe/event_queue.rb

Overview

Processes the events emitted by the Ruby Tacview Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verbose_logging:) ⇒ EventQueue

Returns a new instance of EventQueue.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tac_scribe/event_queue.rb', line 11

def initialize(verbose_logging:)
  @verbose_logging = verbose_logging
  @events = Queue.new
  @event_write = 0
  @event_read = 0

  return unless verbose_logging == true

  Thread.new do
    loop do
      puts "#{Time.now.strftime('%FT%T')} - Queue Size: #{@events.size} \t Events Added: #{@event_write} \t Events Processed: #{@event_read}"
      @event_write = 0
      @event_read = 0
      sleep 1
    end
  end
end

Instance Attribute Details

#reference_latitudeObject

Returns the value of attribute reference_latitude.



9
10
11
# File 'lib/tac_scribe/event_queue.rb', line 9

def reference_latitude
  @reference_latitude
end

#reference_longitudeObject

Returns the value of attribute reference_longitude.



9
10
11
# File 'lib/tac_scribe/event_queue.rb', line 9

def reference_longitude
  @reference_longitude
end

Instance Method Details

#clearObject



29
30
31
# File 'lib/tac_scribe/event_queue.rb', line 29

def clear
  @events.clear
end

#delete_object(object_id) ⇒ Object

Process a delete event for an object

Parameters:

  • object_id (String)

    A hexadecimal number representing the object ID



64
65
66
67
# File 'lib/tac_scribe/event_queue.rb', line 64

def delete_object(object_id)
  @event_write += 1
  @events << { type: :delete_object, object_id: object_id }
end

#get_eventObject



33
34
35
36
# File 'lib/tac_scribe/event_queue.rb', line 33

def get_event
  @event_read += 1
  @events.shift
end

#set_property(property:, value:) ⇒ Object

Set a property

Parameters:

  • property (String)

    The name of the property to be set

  • value (String)

    The value of the property to be set



81
82
83
84
85
86
87
88
89
90
# File 'lib/tac_scribe/event_queue.rb', line 81

def set_property(property:, value:)
  case property
  when 'ReferenceLatitude'
    self.reference_latitude = BigDecimal(value)
  when 'ReferenceLongitude'
    self.reference_longitude = BigDecimal(value)
  when 'ReferenceTime'
    @reference_time = @time = Time.parse(value)
  end
end

#update_object(event) ⇒ Object

Process an update event for an object

On the first appearance of the object there are usually more fields including pilot names, object type etc.

For existing objects these events are almost always lat/lon/alt updates only

Parameters:

  • event (Hash)

    A parsed ACMI line. This hash will always include the fields listed below but may also include others depending on the source line.

Options Hash (event):

  • :object_id (String)

    The hexadecimal format object ID.

  • :latitude (BigDecimal)

    The object latitude in WGS 84 format.

  • :longitude (BigDecimal)

    The object latitude in WGS 84 format.

  • :altitude (BigDecimal)

    The object altitude above sea level in meters to 1 decimal place.



55
56
57
58
# File 'lib/tac_scribe/event_queue.rb', line 55

def update_object(event)
  @event_write += 1
  @events << { type: :update_object, event: event, time: @time }
end

#update_time(time) ⇒ Object

Process a time update event

Parameters:

  • time (BigDecimal)

    A time update in seconds from the ReferenceTime to 2 decimal places



73
74
75
# File 'lib/tac_scribe/event_queue.rb', line 73

def update_time(time)
  @time = @reference_time + time
end