Class: Legion::Extensions::Agentic::Attention::Economy::Helpers::Demand
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Economy::Helpers::Demand
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/attention/economy/helpers/demand.rb
Constant Summary
Constants included from Constants
Constants::BUDGET_RECOVERY_RATE, Constants::DEFAULT_BUDGET, Constants::DEMAND_TYPES, Constants::EFFICIENCY_LABELS, Constants::MAX_DEMANDS, Constants::MIN_ALLOCATION, Constants::PRIORITY_LABELS
Instance Attribute Summary collapse
-
#allocated ⇒ Object
Returns the value of attribute allocated.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#demand_type ⇒ Object
readonly
Returns the value of attribute demand_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#roi ⇒ Object
readonly
Returns the value of attribute roi.
Instance Method Summary collapse
- #allocate!(amount:) ⇒ Object
- #deallocate! ⇒ Object
- #efficiency ⇒ Object
- #efficiency_label ⇒ Object
-
#initialize(label:, demand_type:, priority:, cost:, roi: 0.5) ⇒ Demand
constructor
A new instance of Demand.
- #priority_label ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(label:, demand_type:, priority:, cost:, roi: 0.5) ⇒ Demand
Returns a new instance of Demand.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 18 def initialize(label:, demand_type:, priority:, cost:, roi: 0.5) @id = SecureRandom.uuid @label = label @demand_type = demand_type @priority = priority.clamp(0.0, 1.0) @cost = cost.clamp(0.0, 1.0) @roi = roi.clamp(0.0, 1.0) @allocated = 0.0 @created_at = Time.now.utc end |
Instance Attribute Details
#allocated ⇒ Object
Returns the value of attribute allocated.
16 17 18 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 16 def allocated @allocated end |
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def cost @cost end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def created_at @created_at end |
#demand_type ⇒ Object (readonly)
Returns the value of attribute demand_type.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def demand_type @demand_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def label @label end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def priority @priority end |
#roi ⇒ Object (readonly)
Returns the value of attribute roi.
15 16 17 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 15 def roi @roi end |
Instance Method Details
#allocate!(amount:) ⇒ Object
29 30 31 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 29 def allocate!(amount:) @allocated = amount.clamp(0.0, 1.0).round(10) end |
#deallocate! ⇒ Object
33 34 35 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 33 def deallocate! @allocated = 0.0 end |
#efficiency ⇒ Object
37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 37 def efficiency return 0.0 if cost.zero? (roi / cost).clamp(0.0, 1.0).round(10) end |
#efficiency_label ⇒ Object
43 44 45 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 43 def efficiency_label Constants::EFFICIENCY_LABELS.find { |range, _| range.cover?(efficiency) }&.last || :wasted end |
#priority_label ⇒ Object
47 48 49 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 47 def priority_label Constants::PRIORITY_LABELS.find { |range, _| range.cover?(priority) }&.last || :background end |
#to_h ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/legion/extensions/agentic/attention/economy/helpers/demand.rb', line 51 def to_h { id: id, label: label, demand_type: demand_type, priority: priority, priority_label: priority_label, cost: cost, roi: roi, allocated: allocated, efficiency: efficiency, efficiency_label: efficiency_label, created_at: created_at } end |