Class: Legion::Extensions::Agentic::Affect::Appraisal::Helpers::Appraisal
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Affect::Appraisal::Helpers::Appraisal
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb
Constant Summary
Constants included from Constants
Constants::APPRAISAL_EMOTIONS, Constants::COPING_TYPES, Constants::DECAY_RATE, Constants::DEFAULT_INTENSITY, Constants::INTENSITY_CEILING, Constants::INTENSITY_FLOOR, Constants::MAX_APPRAISALS, Constants::MAX_COPING_STRATEGIES, Constants::MAX_HISTORY, Constants::PRIMARY_DIMENSIONS, Constants::REAPPRAISAL_DISCOUNT, Constants::SECONDARY_DIMENSIONS
Instance Attribute Summary collapse
-
#coping_strategy ⇒ Object
readonly
Returns the value of attribute coping_strategy.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#emotional_outcome ⇒ Object
readonly
Returns the value of attribute emotional_outcome.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#intensity ⇒ Object
readonly
Returns the value of attribute intensity.
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
-
#reappraised ⇒ Object
readonly
Returns the value of attribute reappraised.
-
#reappraised_at ⇒ Object
readonly
Returns the value of attribute reappraised_at.
-
#secondary ⇒ Object
readonly
Returns the value of attribute secondary.
Instance Method Summary collapse
- #assign_coping(strategy_name) ⇒ Object
- #compute_emotion ⇒ Object
- #decay! ⇒ Object
-
#initialize(event:, primary:, secondary:, domain: nil) ⇒ Appraisal
constructor
A new instance of Appraisal.
- #reappraise(new_primary:, new_secondary:) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(event:, primary:, secondary:, domain: nil) ⇒ Appraisal
Returns a new instance of Appraisal.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 18 def initialize(event:, primary:, secondary:, domain: nil) @id = SecureRandom.uuid @event = event @domain = domain @primary = normalize_dimensions(primary, PRIMARY_DIMENSIONS) @secondary = normalize_dimensions(secondary, SECONDARY_DIMENSIONS) @intensity = DEFAULT_INTENSITY @coping_strategy = nil @reappraised = false @created_at = Time.now.utc @reappraised_at = nil @emotional_outcome = compute_emotion end |
Instance Attribute Details
#coping_strategy ⇒ Object (readonly)
Returns the value of attribute coping_strategy.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def coping_strategy @coping_strategy end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def domain @domain end |
#emotional_outcome ⇒ Object (readonly)
Returns the value of attribute emotional_outcome.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def emotional_outcome @emotional_outcome end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def event @event end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def id @id end |
#intensity ⇒ Object (readonly)
Returns the value of attribute intensity.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def intensity @intensity end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def primary @primary end |
#reappraised ⇒ Object (readonly)
Returns the value of attribute reappraised.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def reappraised @reappraised end |
#reappraised_at ⇒ Object (readonly)
Returns the value of attribute reappraised_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def reappraised_at @reappraised_at end |
#secondary ⇒ Object (readonly)
Returns the value of attribute secondary.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 14 def secondary @secondary end |
Instance Method Details
#assign_coping(strategy_name) ⇒ Object
68 69 70 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 68 def assign_coping(strategy_name) @coping_strategy = strategy_name end |
#compute_emotion ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 42 def compute_emotion relevance = @primary[:relevance] goal_congruence = @primary[:goal_congruence] coping_potential = @secondary[:coping_potential] return :indifference if relevance < 0.3 classify_emotion(goal_congruence, coping_potential) end |
#decay! ⇒ Object
72 73 74 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 72 def decay! @intensity = (@intensity - DECAY_RATE).clamp(INTENSITY_FLOOR, INTENSITY_CEILING) end |
#reappraise(new_primary:, new_secondary:) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 32 def reappraise(new_primary:, new_secondary:) @primary = normalize_dimensions(new_primary, PRIMARY_DIMENSIONS) @secondary = normalize_dimensions(new_secondary, SECONDARY_DIMENSIONS) @emotional_outcome = compute_emotion @intensity = (@intensity * (1 - REAPPRAISAL_DISCOUNT)).clamp(INTENSITY_FLOOR, INTENSITY_CEILING) @reappraised = true @reappraised_at = Time.now.utc self end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb', line 52 def to_h { id: @id, event: @event, domain: @domain, primary: @primary, secondary: @secondary, emotional_outcome: @emotional_outcome, intensity: @intensity, coping_strategy: @coping_strategy, reappraised: @reappraised, created_at: @created_at, reappraised_at: @reappraised_at } end |