Class: Legion::Extensions::Agentic::Homeostasis::Tectonics::Helpers::SeismicEvent

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb

Constant Summary collapse

EVENT_TYPES =
%i[earthquake tremor aftershock].freeze

Constants included from Constants

Constants::AFTERSHOCK_DECAY, Constants::BOUNDARY_TYPES, Constants::COLLISION_THRESHOLD, Constants::MAGNITUDE_LABELS, Constants::MAX_DRIFT_RATE, Constants::MAX_PLATES, Constants::MAX_QUAKES, Constants::MIN_DRIFT_RATE, Constants::PLATE_STATES, Constants::STRESS_QUAKE_TRIGGER, Constants::SUBDUCTION_RATIO

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

#label_for

Constructor Details

#initialize(type:, magnitude:, epicenter_plate_id:, affected_plate_ids: [], parent_event_id: nil) ⇒ SeismicEvent

Returns a new instance of SeismicEvent.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 19

def initialize(type:, magnitude:, epicenter_plate_id:, affected_plate_ids: [], parent_event_id: nil, **)
  raise ArgumentError, "unknown event type: #{type.inspect}" unless EVENT_TYPES.include?(type)

  @id                 = SecureRandom.uuid
  @type               = type
  @magnitude          = magnitude.clamp(0.0, Float::INFINITY)
  @epicenter_plate_id = epicenter_plate_id
  @affected_plate_ids = Array(affected_plate_ids)
  @parent_event_id    = parent_event_id
  @timestamp          = Time.now.utc
end

Instance Attribute Details

#affected_plate_idsObject (readonly)

Returns the value of attribute affected_plate_ids.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def affected_plate_ids
  @affected_plate_ids
end

#epicenter_plate_idObject (readonly)

Returns the value of attribute epicenter_plate_id.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def epicenter_plate_id
  @epicenter_plate_id
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def id
  @id
end

#magnitudeObject (readonly)

Returns the value of attribute magnitude.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def magnitude
  @magnitude
end

#parent_event_idObject (readonly)

Returns the value of attribute parent_event_id.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def parent_event_id
  @parent_event_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16

def type
  @type
end

Instance Method Details

#aftershock?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 31

def aftershock?
  @type == :aftershock
end

#labelObject



35
36
37
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 35

def label
  label_for(@magnitude)
end

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 39

def to_h
  {
    id:                 @id,
    type:               @type,
    magnitude:          @magnitude,
    label:              label,
    epicenter_plate_id: @epicenter_plate_id,
    affected_plate_ids: @affected_plate_ids,
    parent_event_id:    @parent_event_id,
    timestamp:          @timestamp
  }
end