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
Instance Method Summary collapse
-
#initialize(batch_size: 10, rate: 2, work_type: :cpu, variance: 0, logging: false, timer: nil) ⇒ Mover
constructor
A new instance of Mover.
- #load_ore(amt) ⇒ Object
- #move(duration) ⇒ Object
- #move_batch ⇒ Object
- #state ⇒ Object
- #status ⇒ Object
Methods inherited from Worker
Constructor Details
#initialize(batch_size: 10, rate: 2, work_type: :cpu, variance: 0, logging: false, timer: nil) ⇒ Mover
Returns a new instance of Mover.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/miner_mover/worker.rb', line 105 def initialize(batch_size: 10, rate: 2, # 2M ore per sec work_type: :cpu, variance: 0, logging: 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, logging: logging, timer: timer) end |
Instance Attribute Details
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def batch @batch end |
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def batch_size @batch_size end |
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def batches @batches end |
#ore_moved ⇒ Object (readonly)
Returns the value of attribute ore_moved.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def ore_moved @ore_moved end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def rate @rate end |
#work_type ⇒ Object (readonly)
Returns the value of attribute work_type.
103 104 105 |
# File 'lib/miner_mover/worker.rb', line 103 def work_type @work_type end |
Instance Method Details
#load_ore(amt) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/miner_mover/worker.rb', line 135 def load_ore(amt) @batch += amt move_batch if @batch >= @batch_size log format("LOAD %s", self.status) @batch end |
#move(duration) ⇒ Object
142 143 144 |
# File 'lib/miner_mover/worker.rb', line 142 def move(duration) MinerMover.work(duration, @work_type) end |
#move_batch ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/miner_mover/worker.rb', line 146 def move_batch raise "unexpected batch: #{@batch}" if @batch <= 0 amt = [@batch, @batch_size].min duration = self.varied(amt / @rate) log format("MOVE %s (%.2f s)", Ore.display(amt), duration) _, elapsed = CompSci::Timer.elapsed { self.move(duration) } log format("MOVD %s (%.2f s)", Ore.display(amt), elapsed) # accounting @ore_moved += amt @batch -= amt @batches += 1 # what moved amt end |
#state ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/miner_mover/worker.rb', line 118 def state super.merge(work_type: @work_type, batch_size: @batch_size, batch: @batch, batches: @batches, ore_moved: @ore_moved) end |
#status ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/miner_mover/worker.rb', line 126 def status [format("Batch %s / %s %i%%", Ore.units(@batch), Ore.units(@batch_size), @batch.to_f * 100 / @batch_size), format("Moved %ix (%s)", @batches, Ore.units(@ore_moved)), ].join(' | ') end |