Class: Legion::Extensions::Agentic::Homeostasis::Tempo::Helpers::TempoRecord

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_TEMPO, Constants::MAX_TEMPO_RECORDS, Constants::MISMATCH_LABELS, Constants::TEMPO_ADJUSTMENT, Constants::TEMPO_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain:, baseline_tempo: Constants::DEFAULT_TEMPO, current_tempo: Constants::DEFAULT_TEMPO, task_tempo_requirement: Constants::DEFAULT_TEMPO) ⇒ TempoRecord

Returns a new instance of TempoRecord.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 17

def initialize(domain:, baseline_tempo: Constants::DEFAULT_TEMPO,
               current_tempo: Constants::DEFAULT_TEMPO,
               task_tempo_requirement: Constants::DEFAULT_TEMPO)
  @id                    = SecureRandom.uuid
  @domain                = domain
  @baseline_tempo        = baseline_tempo.clamp(0.0, 1.0)
  @current_tempo         = current_tempo.clamp(0.0, 1.0)
  @task_tempo_requirement = task_tempo_requirement.clamp(0.0, 1.0)
  @created_at = Time.now.utc
end

Instance Attribute Details

#baseline_tempoObject (readonly)

Returns the value of attribute baseline_tempo.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def baseline_tempo
  @baseline_tempo
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def created_at
  @created_at
end

#current_tempoObject (readonly)

Returns the value of attribute current_tempo.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def current_tempo
  @current_tempo
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def id
  @id
end

#task_tempo_requirementObject (readonly)

Returns the value of attribute task_tempo_requirement.



14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 14

def task_tempo_requirement
  @task_tempo_requirement
end

Instance Method Details

#accelerate!(amount: Constants::TEMPO_ADJUSTMENT) ⇒ Object



32
33
34
35
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 32

def accelerate!(amount: Constants::TEMPO_ADJUSTMENT)
  @current_tempo = (@current_tempo + amount).clamp(0.0, 1.0)
  self
end

#adapt_to!(target:, rate: Constants::TEMPO_ADJUSTMENT) ⇒ Object



42
43
44
45
46
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 42

def adapt_to!(target:, rate: Constants::TEMPO_ADJUSTMENT)
  delta = (target - @current_tempo).clamp(-rate, rate)
  @current_tempo = (@current_tempo + delta).clamp(0.0, 1.0)
  self
end

#decelerate!(amount: Constants::TEMPO_ADJUSTMENT) ⇒ Object



37
38
39
40
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 37

def decelerate!(amount: Constants::TEMPO_ADJUSTMENT)
  @current_tempo = (@current_tempo - amount).clamp(0.0, 1.0)
  self
end

#mismatchObject



28
29
30
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 28

def mismatch
  (@current_tempo - @task_tempo_requirement).abs.round(10)
end

#mismatch_labelObject



52
53
54
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 52

def mismatch_label
  label_for(mismatch, Constants::MISMATCH_LABELS)
end

#tempo_labelObject



48
49
50
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 48

def tempo_label
  label_for(@current_tempo, Constants::TEMPO_LABELS)
end

#to_hObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/homeostasis/tempo/helpers/tempo_record.rb', line 56

def to_h
  {
    id:                     @id,
    domain:                 @domain,
    baseline_tempo:         @baseline_tempo.round(10),
    current_tempo:          @current_tempo.round(10),
    task_tempo_requirement: @task_tempo_requirement.round(10),
    mismatch:               mismatch,
    tempo_label:            tempo_label,
    mismatch_label:         mismatch_label,
    created_at:             @created_at
  }
end