Class: Legion::Extensions::Agentic::Homeostasis::Metabolism::Helpers::MetabolicCycle
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Metabolism::Helpers::MetabolicCycle
- Defined in:
- lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#cycle_count ⇒ Object
readonly
Returns the value of attribute cycle_count.
-
#energy_spent_this_cycle ⇒ Object
readonly
Returns the value of attribute energy_spent_this_cycle.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#operations_log ⇒ Object
readonly
Returns the value of attribute operations_log.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #average_energy_per_operation ⇒ Object
- #complete! ⇒ Object
- #duration_seconds ⇒ Object
-
#initialize ⇒ MetabolicCycle
constructor
A new instance of MetabolicCycle.
- #record_operation(operation_type:, energy_spent:) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ MetabolicCycle
Returns a new instance of MetabolicCycle.
14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 14 def initialize @id = SecureRandom.uuid @cycle_count = 0 @operations_log = [] @energy_spent_this_cycle = 0.0 @started_at = Time.now.utc @completed_at = nil end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def completed_at @completed_at end |
#cycle_count ⇒ Object (readonly)
Returns the value of attribute cycle_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def cycle_count @cycle_count end |
#energy_spent_this_cycle ⇒ Object (readonly)
Returns the value of attribute energy_spent_this_cycle.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def energy_spent_this_cycle @energy_spent_this_cycle end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def id @id end |
#operations_log ⇒ Object (readonly)
Returns the value of attribute operations_log.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def operations_log @operations_log end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 12 def started_at @started_at end |
Instance Method Details
#average_energy_per_operation ⇒ Object
44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 44 def average_energy_per_operation return 0.0 if @cycle_count.zero? (@energy_spent_this_cycle / @cycle_count).round(10) end |
#complete! ⇒ Object
33 34 35 36 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 33 def complete! @completed_at = Time.now.utc to_h end |
#duration_seconds ⇒ Object
38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 38 def duration_seconds return nil unless @completed_at (@completed_at - @started_at).round(4) end |
#record_operation(operation_type:, energy_spent:) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 23 def record_operation(operation_type:, energy_spent:) @operations_log << { operation_type: operation_type, energy_spent: energy_spent.round(10), recorded_at: Time.now.utc } @energy_spent_this_cycle += energy_spent @cycle_count += 1 end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb', line 50 def to_h { id: @id, cycle_count: @cycle_count, energy_spent_this_cycle: @energy_spent_this_cycle.round(10), average_per_operation: average_energy_per_operation, operations_log: @operations_log, started_at: @started_at, completed_at: @completed_at, duration_seconds: duration_seconds } end |