Class: Legion::Extensions::Agentic::Learning::Fermentation::Helpers::Batch

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb

Constant Summary

Constants included from Constants

Constants::CATALYSIS_BOOST, Constants::CATALYST_TYPES, Constants::DEFAULT_POTENCY, Constants::DOMAINS, Constants::FERMENTATION_STAGES, Constants::MATURATION_RATE, Constants::MATURITY_LABELS, Constants::MAX_BATCHES, Constants::MAX_SUBSTRATES, Constants::OVER_FERMENTED_DECAY, Constants::PEAK_THRESHOLD, Constants::POTENCY_LABELS, Constants::RIPE_THRESHOLD, Constants::SPOILAGE_THRESHOLD, Constants::SUBSTRATE_TYPES, Constants::VOLATILITY_DECAY, Constants::VOLATILITY_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initialize(domain:) ⇒ Batch

Returns a new instance of Batch.



14
15
16
17
18
19
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 14

def initialize(domain:)
  @id         = SecureRandom.uuid
  @domain     = domain.to_sym
  @substrates = []
  @created_at = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 12

def id
  @id
end

#substratesObject (readonly)

Returns the value of attribute substrates.



12
13
14
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 12

def substrates
  @substrates
end

Instance Method Details

#add_substrate(substrate) ⇒ Object



21
22
23
24
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 21

def add_substrate(substrate)
  @substrates << substrate
  substrate
end

#average_maturityObject



36
37
38
39
40
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 36

def average_maturity
  return 0.0 if @substrates.empty?

  (@substrates.sum(&:maturity) / @substrates.size).round(10)
end

#average_potencyObject



30
31
32
33
34
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 30

def average_potency
  return 0.0 if @substrates.empty?

  (@substrates.sum(&:potency) / @substrates.size).round(10)
end

#ferment_all!(rate = MATURATION_RATE) ⇒ Object



26
27
28
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 26

def ferment_all!(rate = MATURATION_RATE)
  @substrates.each { |s| s.ferment!(rate) }
end

#peak_countObject



43
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 43

def peak_count = @substrates.count(&:peak?)

#raw_countObject



45
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 45

def raw_count = @substrates.count(&:raw?)

#ready_to_harvest?Boolean

Returns:

  • (Boolean)


53
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 53

def ready_to_harvest? = yield_rate >= 0.5

#ripe_countObject



42
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 42

def ripe_count = @substrates.count(&:ripe?)

#spoiled_countObject



44
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 44

def spoiled_count = @substrates.count(&:spoiled?)

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 55

def to_h
  {
    id:               @id,
    domain:           @domain,
    substrate_count:  @substrates.size,
    average_potency:  average_potency,
    average_maturity: average_maturity,
    ripe_count:       ripe_count,
    peak_count:       peak_count,
    spoiled_count:    spoiled_count,
    yield_rate:       yield_rate,
    ready_to_harvest: ready_to_harvest?
  }
end

#yield_rateObject



47
48
49
50
51
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/batch.rb', line 47

def yield_rate
  return 0.0 if @substrates.empty?

  (ripe_count.to_f / @substrates.size).round(10)
end