Class: Legion::Extensions::Agentic::Executive::FlexibilityTraining::Helpers::SwitchTrial

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_task_id:, to_task_id:, switch_cost:, accuracy:) ⇒ SwitchTrial

Returns a new instance of SwitchTrial.



14
15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 14

def initialize(from_task_id:, to_task_id:, switch_cost:, accuracy:)
  @id           = SecureRandom.uuid
  @from_task_id = from_task_id
  @to_task_id   = to_task_id
  @switch_cost  = switch_cost.clamp(0.0, 1.0).round(10)
  @accuracy     = accuracy.clamp(0.0, 1.0).round(10)
  @created_at   = Time.now.utc
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def accuracy
  @accuracy
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def created_at
  @created_at
end

#from_task_idObject (readonly)

Returns the value of attribute from_task_id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def from_task_id
  @from_task_id
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def id
  @id
end

#switch_costObject (readonly)

Returns the value of attribute switch_cost.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def switch_cost
  @switch_cost
end

#to_task_idObject (readonly)

Returns the value of attribute to_task_id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 12

def to_task_id
  @to_task_id
end

Instance Method Details

#costly?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 23

def costly?
  @switch_cost > 0.5
end

#successful?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 27

def successful?
  @accuracy > 0.7
end

#switch_cost_labelObject



31
32
33
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 31

def switch_cost_label
  Constants.label_for(@switch_cost, Constants::SWITCH_COST_LABELS)
end

#to_hObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb', line 35

def to_h
  {
    id:                @id,
    from_task_id:      @from_task_id,
    to_task_id:        @to_task_id,
    switch_cost:       @switch_cost,
    accuracy:          @accuracy,
    costly:            costly?,
    successful:        successful?,
    switch_cost_label: switch_cost_label,
    created_at:        @created_at
  }
end