Class: Legion::Extensions::Agentic::Affect::Motivation::Helpers::DriveState

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDriveState

Returns a new instance of DriveState.



12
13
14
15
16
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 12

def initialize
  @drives = Constants::DRIVE_TYPES.to_h do |type|
    [type, { level: 0.5, satisfied: false, last_signal: nil }]
  end
end

Instance Attribute Details

#drivesObject (readonly)

Returns the value of attribute drives.



10
11
12
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 10

def drives
  @drives
end

Instance Method Details

#amotivated?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 77

def amotivated?
  @drives.values.all? { |d| d[:level] < Constants::AMOTIVATION_THRESHOLD }
end

#current_modeObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 55

def current_mode
  level = overall_level
  if level >= Constants::APPROACH_THRESHOLD
    :approach
  elsif level <= Constants::BURNOUT_THRESHOLD
    :dormant
  elsif level <= Constants::AVOIDANCE_THRESHOLD
    :avoidance
  else
    :maintenance
  end
end

#decay_allObject



68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 68

def decay_all
  @drives.each_key do |type|
    current = @drives[type][:level]
    decayed = [current - Constants::DRIVE_DECAY_RATE, 0.0].max
    @drives[type][:level]     = decayed
    @drives[type][:satisfied] = decayed >= 0.6
  end
end

#drive_level(type) ⇒ Object



28
29
30
31
32
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 28

def drive_level(type)
  return 0.0 unless Constants::DRIVE_TYPES.include?(type)

  @drives[type][:level]
end

#extrinsic_averageObject



45
46
47
48
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 45

def extrinsic_average
  levels = Constants::EXTRINSIC_DRIVES.map { |d| @drives[d][:level] }
  mean(levels)
end

#intrinsic_averageObject



40
41
42
43
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 40

def intrinsic_average
  levels = Constants::INTRINSIC_DRIVES.map { |d| @drives[d][:level] }
  mean(levels)
end

#overall_levelObject



50
51
52
53
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 50

def overall_level
  all_levels = @drives.values.map { |d| d[:level] }
  mean(all_levels)
end

#satisfied?(type) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 34

def satisfied?(type)
  return false unless Constants::DRIVE_TYPES.include?(type)

  @drives[type][:satisfied]
end

#update_drive(type, signal) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb', line 18

def update_drive(type, signal)
  return unless Constants::DRIVE_TYPES.include?(type)

  clamped = signal.clamp(0.0, 1.0)
  current = @drives[type][:level]
  @drives[type][:level]       = ema(current, clamped, Constants::DRIVE_ALPHA)
  @drives[type][:satisfied]   = @drives[type][:level] >= 0.6
  @drives[type][:last_signal] = Time.now.utc
end