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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drive_state: nil) ⇒ MotivationStore

Returns a new instance of MotivationStore.



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

def initialize(drive_state: nil)
  @drive_state      = drive_state || DriveState.new
  @goal_motivations = {}
  @low_motivation_ticks = 0
end

Instance Attribute Details

#drive_stateObject (readonly)

Returns the value of attribute drive_state.



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

def drive_state
  @drive_state
end

#goal_motivationsObject (readonly)

Returns the value of attribute goal_motivations.



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

def goal_motivations
  @goal_motivations
end

Instance Method Details

#burnout_checkObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb', line 58

def burnout_check
  overall = @drive_state.overall_level
  if overall < Constants::BURNOUT_THRESHOLD
    @low_motivation_ticks += 1
  else
    @low_motivation_ticks = 0
  end

  {
    burnout:              @low_motivation_ticks >= 10,
    low_motivation_ticks: @low_motivation_ticks,
    overall_level:        overall.round(4)
  }
end

#commit_goal(goal_id, drives) ⇒ Object



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

def commit_goal(goal_id, drives)
  valid_drives = Array(drives).select { |d| Constants::DRIVE_TYPES.include?(d) }
  return false if valid_drives.empty?

  trim_goals
  @goal_motivations[goal_id] = {
    drives:       valid_drives,
    energy:       goal_energy_for(valid_drives),
    committed:    true,
    committed_at: Time.now.utc
  }
  true
end

#goal_energy(goal_id) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb', line 37

def goal_energy(goal_id)
  entry = @goal_motivations[goal_id]
  return 0.0 unless entry

  entry[:energy] = goal_energy_for(entry[:drives])
  entry[:energy]
end

#most_motivated_goalObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb', line 45

def most_motivated_goal
  return nil if @goal_motivations.empty?

  refreshed = @goal_motivations.transform_values do |entry|
    entry.merge(energy: goal_energy_for(entry[:drives]))
  end

  best_id, best_entry = refreshed.max_by { |_, v| v[:energy] }
  return nil unless best_id

  { goal_id: best_id, energy: best_entry[:energy].round(4), drives: best_entry[:drives] }
end

#release_goal(goal_id) ⇒ Object



32
33
34
35
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb', line 32

def release_goal(goal_id)
  @goal_motivations.delete(goal_id)
  true
end

#statsObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb', line 73

def stats
  {
    overall_level:        @drive_state.overall_level.round(4),
    current_mode:         @drive_state.current_mode,
    intrinsic_average:    @drive_state.intrinsic_average.round(4),
    extrinsic_average:    @drive_state.extrinsic_average.round(4),
    amotivated:           @drive_state.amotivated?,
    goal_count:           @goal_motivations.size,
    low_motivation_ticks: @low_motivation_ticks
  }
end