Class: Legion::Extensions::Agentic::Learning::Fermentation::Helpers::FermentationEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Fermentation::Helpers::FermentationEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.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 Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
Returns a new instance of FermentationEngine.
12
13
14
15
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 12
def initialize
@substrates = {}
@batches = {}
end
|
Instance Method Details
#catalyze(substrate_id:, catalyst_type:) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 37
def catalyze(substrate_id:, catalyst_type:)
return nil unless CATALYST_TYPES.include?(catalyst_type.to_sym)
sub = @substrates[substrate_id]
return nil unless sub
sub.catalyze!(catalyst_type)
sub
end
|
#create_substrate(substrate_type:, domain:, content: '', potency: nil, volatility: nil) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 17
def create_substrate(substrate_type:, domain:, content: '', potency: nil, volatility: nil)
return nil unless SUBSTRATE_TYPES.include?(substrate_type.to_sym)
sub = Substrate.new(substrate_type: substrate_type, domain: domain, content: content,
potency: potency, volatility: volatility)
@substrates[sub.id] = sub
batch = find_or_create_batch(domain: domain)
batch.add_substrate(sub)
prune_substrates
sub
end
|
#ferment(substrate_id:, rate: MATURATION_RATE) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 29
def ferment(substrate_id:, rate: MATURATION_RATE)
sub = @substrates[substrate_id]
return nil unless sub
sub.ferment!(rate)
sub
end
|
#ferment_all!(rate: MATURATION_RATE) ⇒ Object
47
48
49
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 47
def ferment_all!(rate: MATURATION_RATE)
@batches.each_value { |b| b.ferment_all!(rate) }
end
|
#fermentation_report ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 97
def fermentation_report
{
total_substrates: @substrates.size,
total_batches: @batches.size,
overall_potency: overall_potency,
potency_label: Constants.label_for(POTENCY_LABELS, overall_potency),
overall_maturity: overall_maturity,
maturity_label: Constants.label_for(MATURITY_LABELS, overall_maturity),
overall_volatility: overall_volatility,
volatility_label: Constants.label_for(VOLATILITY_LABELS, overall_volatility),
yield_rate: yield_rate,
ripe_count: ripe_substrates.size,
peak_count: peak_substrates.size,
spoiled_count: spoiled_substrates.size,
stage_distribution: stage_distribution,
batches: @batches.values.map(&:to_h),
most_potent: most_potent(limit: 3).map(&:to_h)
}
end
|
#most_mature(limit: 5) ⇒ Object
63
64
65
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 63
def most_mature(limit: 5)
@substrates.values.sort_by { |s| -s.maturity }.first(limit)
end
|
#most_potent(limit: 5) ⇒ Object
59
60
61
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 59
def most_potent(limit: 5)
@substrates.values.sort_by { |s| -s.potency }.first(limit)
end
|
#overall_maturity ⇒ Object
73
74
75
76
77
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 73
def overall_maturity
return 0.0 if @substrates.empty?
(@substrates.values.sum(&:maturity) / @substrates.size).round(10)
end
|
#overall_potency ⇒ Object
67
68
69
70
71
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 67
def overall_potency
return 0.0 if @substrates.empty?
(@substrates.values.sum(&:potency) / @substrates.size).round(10)
end
|
#overall_volatility ⇒ Object
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 79
def overall_volatility
return 0.0 if @substrates.empty?
(@substrates.values.sum(&:volatility) / @substrates.size).round(10)
end
|
#peak_substrates ⇒ Object
55
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 55
def peak_substrates = @substrates.values.select(&:peak?)
|
#raw_substrates ⇒ Object
57
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 57
def raw_substrates = @substrates.values.select(&:raw?)
|
#ripe_substrates ⇒ Object
54
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 54
def ripe_substrates = @substrates.values.select(&:ripe?)
|
#spoiled_substrates ⇒ Object
56
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 56
def spoiled_substrates = @substrates.values.select(&:spoiled?)
|
#stage_distribution ⇒ Object
91
92
93
94
95
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 91
def stage_distribution
dist = Hash.new(0)
@substrates.each_value { |s| dist[s.stage] += 1 }
dist
end
|
#substrates_by_domain(domain:) ⇒ Object
51
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 51
def substrates_by_domain(domain:) = @substrates.values.select { |s| s.domain == domain.to_sym }
|
#substrates_by_stage(stage:) ⇒ Object
53
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 53
def substrates_by_stage(stage:) = @substrates.values.select { |s| s.stage == stage.to_sym }
|
#substrates_by_type(type:) ⇒ Object
52
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 52
def substrates_by_type(type:) = @substrates.values.select { |s| s.substrate_type == type.to_sym }
|
#to_h ⇒ Object
117
118
119
120
121
122
123
124
125
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 117
def to_h
{
total_substrates: @substrates.size,
total_batches: @batches.size,
potency: overall_potency,
maturity: overall_maturity,
volatility: overall_volatility
}
end
|
#yield_rate ⇒ Object
85
86
87
88
89
|
# File 'lib/legion/extensions/agentic/learning/fermentation/helpers/fermentation_engine.rb', line 85
def yield_rate
return 0.0 if @substrates.empty?
(ripe_substrates.size.to_f / @substrates.size).round(10)
end
|