Class: Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Channel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Channel
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb
Constant Summary
Constants included from Constants
Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::CHANNELS, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::DEFAULT_ENERGY, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::DELEGATION_THRESHOLD, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::DEPLETION_RATES, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::ENERGY_CEILING, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::ENERGY_FLOOR, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::FATIGUE_LABELS, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::MAX_HISTORY, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::RECOVERY_RATES, Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::Constants::REST_THRESHOLD
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#energy ⇒ Object
readonly
Returns the value of attribute energy.
-
#last_used_at ⇒ Object
readonly
Returns the value of attribute last_used_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tasks_processed ⇒ Object
readonly
Returns the value of attribute tasks_processed.
-
#total_depletion ⇒ Object
readonly
Returns the value of attribute total_depletion.
Instance Method Summary collapse
- #deplete!(amount: nil) ⇒ Object
- #energy_label ⇒ Object
-
#initialize(name:, energy: DEFAULT_ENERGY) ⇒ Channel
constructor
A new instance of Channel.
- #needs_delegation? ⇒ Boolean
- #needs_rest? ⇒ Boolean
- #quality_modifier ⇒ Object
- #recover!(amount: nil) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, energy: DEFAULT_ENERGY) ⇒ Channel
Returns a new instance of Channel.
14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 14 def initialize(name:, energy: DEFAULT_ENERGY) @name = name @energy = energy.clamp(ENERGY_FLOOR, ENERGY_CEILING) @tasks_processed = 0 @total_depletion = 0.0 @last_used_at = nil @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def created_at @created_at end |
#energy ⇒ Object (readonly)
Returns the value of attribute energy.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def energy @energy end |
#last_used_at ⇒ Object (readonly)
Returns the value of attribute last_used_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def last_used_at @last_used_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def name @name end |
#tasks_processed ⇒ Object (readonly)
Returns the value of attribute tasks_processed.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def tasks_processed @tasks_processed end |
#total_depletion ⇒ Object (readonly)
Returns the value of attribute total_depletion.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 12 def total_depletion @total_depletion end |
Instance Method Details
#deplete!(amount: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 23 def deplete!(amount: nil) rate = amount || DEPLETION_RATES.fetch(name, 0.05) before = @energy @energy = (@energy - rate).clamp(ENERGY_FLOOR, ENERGY_CEILING) depleted = before - @energy @total_depletion += depleted @tasks_processed += 1 @last_used_at = Time.now.utc self end |
#energy_label ⇒ Object
40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 40 def energy_label FATIGUE_LABELS.each do |range, label| return label if range.cover?(@energy) end :unknown end |
#needs_delegation? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 51 def needs_delegation? @energy < DELEGATION_THRESHOLD end |
#needs_rest? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 47 def needs_rest? @energy < REST_THRESHOLD end |
#quality_modifier ⇒ Object
55 56 57 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 55 def quality_modifier @energy.clamp(ENERGY_FLOOR, ENERGY_CEILING) end |
#recover!(amount: nil) ⇒ Object
34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 34 def recover!(amount: nil) rate = amount || RECOVERY_RATES.fetch(name, 0.06) @energy = (@energy + rate).clamp(ENERGY_FLOOR, ENERGY_CEILING) self end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/channel.rb', line 59 def to_h { name: @name, energy: @energy.round(4), label: energy_label, tasks_processed: @tasks_processed, total_depletion: @total_depletion.round(4), needs_rest: needs_rest?, needs_delegation: needs_delegation?, quality_modifier: quality_modifier.round(4), last_used_at: @last_used_at, created_at: @created_at } end |