Class: Legion::Extensions::Agentic::Homeostasis::Weathering::Helpers::Stressor

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

Constant Summary

Constants included from Constants

Constants::BREAKDOWN_INTEGRITY, Constants::CRITICAL_INTEGRITY, Constants::DEFAULT_INTEGRITY, Constants::INTEGRITY_LABELS, Constants::MAX_EVENTS, Constants::MAX_STRESSORS, Constants::RECOVERY_RATE, Constants::STRESSOR_TYPES, Constants::TEMPERING_RATE, Constants::TEMPERING_THRESHOLD, Constants::WEAR_RATE, Constants::WEATHERING_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

integrity_label, weathering_label

Constructor Details

#initialize(description:, stressor_type:, intensity:, duration:, domain: nil) ⇒ Stressor

Returns a new instance of Stressor.



16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 16

def initialize(description:, stressor_type:, intensity:, duration:, domain: nil)
  @id           = SecureRandom.uuid
  @description  = description
  @stressor_type = validate_type(stressor_type)
  @intensity    = intensity.clamp(0.0, 1.0)
  @duration     = [duration.to_f, 0.0].max
  @domain       = domain
  @recorded_at  = Time.now.utc
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def description
  @description
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def domain
  @domain
end

#durationObject (readonly)

Returns the value of attribute duration.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def id
  @id
end

#intensityObject (readonly)

Returns the value of attribute intensity.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def intensity
  @intensity
end

#recorded_atObject (readonly)

Returns the value of attribute recorded_at.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def recorded_at
  @recorded_at
end

#stressor_typeObject (readonly)

Returns the value of attribute stressor_type.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 14

def stressor_type
  @stressor_type
end

Instance Method Details

#cumulative_impactObject



26
27
28
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 26

def cumulative_impact
  (intensity * (duration / 3600.0)).clamp(0.0, 1.0).round(10)
end

#manageable?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 30

def manageable?
  intensity <= Constants::TEMPERING_THRESHOLD
end

#overwhelming?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/stressor.rb', line 34

def overwhelming?
  intensity >= 0.8
end

#to_hObject



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

def to_h
  {
    id:                id,
    description:       description,
    stressor_type:     stressor_type,
    intensity:         intensity,
    duration:          duration,
    domain:            domain,
    cumulative_impact: cumulative_impact,
    manageable:        manageable?,
    overwhelming:      overwhelming?,
    recorded_at:       recorded_at.iso8601
  }
end