Class: Legion::Extensions::Agentic::Homeostasis::Metabolism::Helpers::MetabolicCycle

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/metabolism/helpers/metabolic_cycle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetabolicCycle

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_atObject (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_countObject (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_cycleObject (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

#idObject (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_logObject (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_atObject (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_operationObject



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_secondsObject



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_hObject



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