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
# File 'lib/tac_scribe/event_queue.rb', line 11

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

  return unless verbose_logging == true

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

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



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

def events
  @events
end

#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

#delete_object(object_id) ⇒ Object

Process a delete event for an object

Parameters:

  • object_id (String)

    A hexadecimal number representing the object ID



53
54
55
56
# File 'lib/tac_scribe/event_queue.rb', line 53

def delete_object(object_id)
  @event_count += 1
  events << { type: :delete_object, object_id: object_id }
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



70
71
72
73
74
75
76
77
78
79
# File 'lib/tac_scribe/event_queue.rb', line 70

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.



44
45
46
47
# File 'lib/tac_scribe/event_queue.rb', line 44

def update_object(event)
  @event_count += 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



62
63
64
# File 'lib/tac_scribe/event_queue.rb', line 62

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