Class: MinerMover::Mover
Instance Attribute Summary collapse
-
#batch ⇒ Object
readonly
Returns the value of attribute batch.
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#batches ⇒ Object
readonly
Returns the value of attribute batches.
-
#ore_moved ⇒ Object
readonly
Returns the value of attribute ore_moved.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#work_type ⇒ Object
readonly
Returns the value of attribute work_type.
Attributes inherited from Worker
#debugging, #logging, #timer, #variance
Instance Method Summary collapse
-
#initialize(batch_size: 10, rate: 2, work_type: :cpu, variance: 0, logging: false, debugging: false, timer: nil) ⇒ Mover
constructor
A new instance of Mover.
-
#load_ore(amount) ⇒ Object
accept some ore for moving; just accumulate unless we have a full batch.
-
#move(amount) ⇒ Object
perform the work of moving the amount of ore.
-
#move_batch ⇒ Object
return the amount moved.
- #state ⇒ Object
- #status ⇒ Object
Methods inherited from Worker
#debug, #id, #log, #to_s, #varied
Constructor Details
#initialize(batch_size: 10, rate: 2, work_type: :cpu, variance: 0, logging: false, debugging: false, timer: nil) ⇒ Mover
Returns a new instance of Mover.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/miner_mover/worker.rb', line 120 def initialize(batch_size: 10, rate: 2, # 2M ore per sec work_type: :cpu, variance: 0, logging: false, debugging: false, timer: nil) @batch_size = batch_size * Ore::BLOCK @rate = rate.to_f * Ore::BLOCK @work_type = work_type @batch, @batches, @ore_moved = 0, 0, 0 super(variance: variance, timer: timer, logging: logging, debugging: debugging) end |
Instance Attribute Details
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def batch @batch end |
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def batch_size @batch_size end |
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def batches @batches end |
#ore_moved ⇒ Object (readonly)
Returns the value of attribute ore_moved.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def ore_moved @ore_moved end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def rate @rate end |
#work_type ⇒ Object (readonly)
Returns the value of attribute work_type.
118 119 120 |
# File 'lib/miner_mover/worker.rb', line 118 def work_type @work_type end |
Instance Method Details
#load_ore(amount) ⇒ Object
accept some ore for moving; just accumulate unless we have a full batch
153 154 155 156 157 158 159 |
# File 'lib/miner_mover/worker.rb', line 153 def load_ore amount log format("LOAD %s | %s", Ore.display(amount), self.status) @batch += amount move_batch if @batch >= @batch_size log format("LDED %s | %s", Ore.display(amount), self.status) @batch end |
#move(amount) ⇒ Object
perform the work of moving the amount of ore
177 178 179 180 181 182 183 |
# File 'lib/miner_mover/worker.rb', line 177 def move amount duration = self.varied(amount / @rate) log format("MOVE %s (%.2f s)", Ore.display(amount), duration) _, elapsed = Timer.elapsed { MinerMover.work(duration, @work_type) } log format("MOVD %s (%.2f s)", Ore.display(amount), elapsed) self end |
#move_batch ⇒ Object
return the amount moved
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/miner_mover/worker.rb', line 162 def move_batch raise "unexpected batch: #{@batch}" if @batch <= 0 amount = [@batch, @batch_size].min self.move amount # accounting @ore_moved += amount @batch -= amount @batches += 1 amount end |
#state ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/miner_mover/worker.rb', line 135 def state super.merge(work_type: @work_type, batch_size: @batch_size, batch: @batch, batches: @batches, ore_moved: @ore_moved) end |