Class: Legion::Extensions::Agentic::Affect::Reappraisal::Helpers::EmotionalEvent
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Affect::Reappraisal::Helpers::EmotionalEvent
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb
Constant Summary
Constants included from Constants
Constants::HIGH_INTENSITY_THRESHOLD, Constants::INTENSITY_LABELS, Constants::MAX_EVENTS, Constants::MAX_REAPPRAISALS, Constants::NEGATIVE_VALENCE_THRESHOLD, Constants::REAPPRAISAL_DIFFICULTY_MULTIPLIER, Constants::REGULATION_LABELS, Constants::STRATEGIES, Constants::STRATEGY_EFFECTIVENESS, Constants::VALENCE_LABELS
Instance Attribute Summary collapse
-
#appraisal ⇒ Object
readonly
Returns the value of attribute appraisal.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#current_intensity ⇒ Object
readonly
Returns the value of attribute current_intensity.
-
#current_valence ⇒ Object
readonly
Returns the value of attribute current_valence.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#initial_intensity ⇒ Object
readonly
Returns the value of attribute initial_intensity.
-
#initial_valence ⇒ Object
readonly
Returns the value of attribute initial_valence.
-
#reappraisal_count ⇒ Object
readonly
Returns the value of attribute reappraisal_count.
Instance Method Summary collapse
-
#initialize(content:, valence:, intensity:, appraisal:) ⇒ EmotionalEvent
constructor
A new instance of EmotionalEvent.
- #intense? ⇒ Boolean
- #intensity_label ⇒ Object
- #negative? ⇒ Boolean
- #reappraise!(strategy:, new_appraisal:) ⇒ Object
- #regulation_amount ⇒ Object
- #to_h ⇒ Object
- #valence_label ⇒ Object
Methods included from Constants
clamp, clamp_intensity, label_for, valid_strategy?
Constructor Details
#initialize(content:, valence:, intensity:, appraisal:) ⇒ EmotionalEvent
Returns a new instance of EmotionalEvent.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 18 def initialize(content:, valence:, intensity:, appraisal:) @id = SecureRandom.uuid @content = content @initial_valence = Constants.clamp(valence) @current_valence = @initial_valence @initial_intensity = Constants.clamp_intensity(intensity) @current_intensity = @initial_intensity @appraisal = appraisal @reappraisal_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#appraisal ⇒ Object (readonly)
Returns the value of attribute appraisal.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def appraisal @appraisal end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def created_at @created_at end |
#current_intensity ⇒ Object (readonly)
Returns the value of attribute current_intensity.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def current_intensity @current_intensity end |
#current_valence ⇒ Object (readonly)
Returns the value of attribute current_valence.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def current_valence @current_valence end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def id @id end |
#initial_intensity ⇒ Object (readonly)
Returns the value of attribute initial_intensity.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def initial_intensity @initial_intensity end |
#initial_valence ⇒ Object (readonly)
Returns the value of attribute initial_valence.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def initial_valence @initial_valence end |
#reappraisal_count ⇒ Object (readonly)
Returns the value of attribute reappraisal_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 14 def reappraisal_count @reappraisal_count end |
Instance Method Details
#intense? ⇒ Boolean
55 56 57 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 55 def intense? @current_intensity > Constants::HIGH_INTENSITY_THRESHOLD end |
#intensity_label ⇒ Object
70 71 72 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 70 def intensity_label Constants.label_for(@current_intensity, Constants::INTENSITY_LABELS) end |
#negative? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 51 def negative? @current_valence < Constants::NEGATIVE_VALENCE_THRESHOLD end |
#reappraise!(strategy:, new_appraisal:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 30 def reappraise!(strategy:, new_appraisal:) return 0.0 unless Constants.valid_strategy?(strategy) base_effectiveness = Constants::STRATEGY_EFFECTIVENESS[strategy] difficulty = @current_intensity > Constants::HIGH_INTENSITY_THRESHOLD ? Constants::REAPPRAISAL_DIFFICULTY_MULTIPLIER : 1.0 effectiveness = (base_effectiveness * difficulty).round(10) valence_shift = effectiveness intensity_reduction = (effectiveness * 0.5).round(10) old_valence = @current_valence old_intensity = @current_intensity @current_valence = Constants.clamp(@current_valence + valence_shift) @current_intensity = Constants.clamp_intensity(@current_intensity - intensity_reduction) @appraisal = new_appraisal @reappraisal_count += 1 ((@current_valence - old_valence).abs + (old_intensity - @current_intensity).abs).round(10) end |
#regulation_amount ⇒ Object
59 60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 59 def regulation_amount valence_change = (@current_valence - @initial_valence).abs intensity_change = (@initial_intensity - @current_intensity).abs raw = valence_change + intensity_change Constants.clamp_intensity(raw / 2.0) end |
#to_h ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 74 def to_h { id: @id, content: @content, initial_valence: @initial_valence.round(10), current_valence: @current_valence.round(10), initial_intensity: @initial_intensity.round(10), current_intensity: @current_intensity.round(10), appraisal: @appraisal, reappraisal_count: @reappraisal_count, negative: negative?, intense: intense?, regulation_amount: regulation_amount.round(10), valence_label: valence_label, intensity_label: intensity_label, created_at: @created_at } end |
#valence_label ⇒ Object
66 67 68 |
# File 'lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb', line 66 def valence_label Constants.label_for(@current_valence, Constants::VALENCE_LABELS) end |