Class: Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::WeatherEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::WeatherEngine
- Defined in:
- lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb
Instance Attribute Summary collapse
-
#fronts ⇒ Object
readonly
Returns the value of attribute fronts.
-
#storms ⇒ Object
readonly
Returns the value of attribute storms.
Instance Method Summary collapse
-
#atmospheric_report ⇒ Object
Full atmospheric report.
-
#brew_storm(front_id:, condition: :stormy, intensity: 0.5, coverage: 0.5) ⇒ Object
Brew a storm anchored to a front; respects MAX_STORMS.
-
#calmest ⇒ Object
Front with lowest pressure.
-
#create_front(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) ⇒ Object
Create a new atmospheric front; respects MAX_FRONTS.
-
#dissipate_all!(rate = Constants::DISSIPATION_RATE) ⇒ Object
Dissipate all storms by one cycle.
-
#initialize ⇒ WeatherEngine
constructor
A new instance of WeatherEngine.
-
#intensify_storm(storm_id:, rate: Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Intensify a storm by id.
-
#most_severe ⇒ Object
Front with highest pressure.
-
#weather_forecast ⇒ Object
Current conditions summary: dominant condition, average intensity, active storm count.
Constructor Details
#initialize ⇒ WeatherEngine
Returns a new instance of WeatherEngine.
12 13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 12 def initialize @fronts = [] @storms = [] end |
Instance Attribute Details
#fronts ⇒ Object (readonly)
Returns the value of attribute fronts.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 10 def fronts @fronts end |
#storms ⇒ Object (readonly)
Returns the value of attribute storms.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 10 def storms @storms end |
Instance Method Details
#atmospheric_report ⇒ Object
Full atmospheric report
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 104 def atmospheric_report { front_count: @fronts.size, storm_count: @storms.size, fronts: @fronts.map(&:to_h), storms: @storms.map(&:to_h), forecast: weather_forecast, most_severe: most_severe&.to_h, calmest: calmest&.to_h } end |
#brew_storm(front_id:, condition: :stormy, intensity: 0.5, coverage: 0.5) ⇒ Object
Brew a storm anchored to a front; respects MAX_STORMS
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 33 def brew_storm(front_id:, condition: :stormy, intensity: 0.5, coverage: 0.5) return nil if @storms.size >= Constants::MAX_STORMS return nil unless find_front(front_id) storm = Storm.new( condition: condition, front_ids: [front_id], intensity: intensity, coverage: coverage ) @storms << storm storm end |
#calmest ⇒ Object
Front with lowest pressure
97 98 99 100 101 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 97 def calmest return nil if @fronts.empty? @fronts.min_by(&:pressure) end |
#create_front(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) ⇒ Object
Create a new atmospheric front; respects MAX_FRONTS
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 18 def create_front(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) return nil if @fronts.size >= Constants::MAX_FRONTS front = Front.new( front_type: front_type, domain: domain, pressure: pressure, temperature: temperature, humidity: humidity ) @fronts << front front end |
#dissipate_all!(rate = Constants::DISSIPATION_RATE) ⇒ Object
Dissipate all storms by one cycle
57 58 59 60 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 57 def dissipate_all!(rate = Constants::DISSIPATION_RATE) @storms.each { |s| s.dissipate!(rate) } @storms.size end |
#intensify_storm(storm_id:, rate: Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Intensify a storm by id
48 49 50 51 52 53 54 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 48 def intensify_storm(storm_id:, rate: Constants::PRESSURE_CHANGE_RATE) storm = find_storm(storm_id) return nil unless storm storm.intensify!(rate) storm end |
#most_severe ⇒ Object
Front with highest pressure
90 91 92 93 94 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 90 def most_severe return nil if @fronts.empty? @fronts.max_by(&:pressure) end |
#weather_forecast ⇒ Object
Current conditions summary: dominant condition, average intensity, active storm count
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/weather_engine.rb', line 63 def weather_forecast if @storms.empty? return { condition: :clear, avg_intensity: 0.0, active_storms: 0, dominant_front: nil, clarity_label: 'crystal', severity_label: 'calm' } end avg_intensity = @storms.sum(&:intensity) / @storms.size.to_f dominant_storm = @storms.max_by(&:intensity) dominant_front = most_severe { condition: dominant_storm.condition, avg_intensity: avg_intensity.round(10), active_storms: @storms.size, dominant_front: dominant_front&.to_h, clarity_label: dominant_storm.clarity_label, severity_label: dominant_front ? dominant_front.severity_label : 'calm' } end |