Class: Claymore::GPUHashRate
- Inherits:
-
Object
- Object
- Claymore::GPUHashRate
- Includes:
- AssetSymbol
- Defined in:
- lib/claymore/gpu_hash_rate.rb
Overview
Extracts asset, gpu index and gpu hash rate Sets hash rate to -1 when gpu is off
Example input: 05:45:16:028 2100 ETH: GPU0 29.586 Mh/s, GPU1 off
Example output: [
{ 'asset' => 'ETH', 'gpu' => 0, 'hash_rate' => 29.586, 'type' => 'GPU_HASH_RATE' },
{ 'asset' => 'ETH', 'gpu' => 1, 'hash_rate' => -1.0, 'type' => 'GPU_HASH_RATE' }
]
Constant Summary collapse
- RATES_REGEXP =
%r{GPU(?<index>\d+) (?<rate>\d+(?:\.\d+)? Mh\/s|off)}
- LINE_REGEXP =
Regexp.new("#{ASSET_REGEXP.source} #{RATES_REGEXP.source}")
Constants included from AssetSymbol
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(line) ⇒ GPUHashRate
constructor
A new instance of GPUHashRate.
Methods included from AssetSymbol
Constructor Details
#initialize(line) ⇒ GPUHashRate
Returns a new instance of GPUHashRate.
27 28 29 |
# File 'lib/claymore/gpu_hash_rate.rb', line 27 def initialize(line) @line = line end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
25 26 27 |
# File 'lib/claymore/gpu_hash_rate.rb', line 25 def line @line end |
Class Method Details
.call(line) ⇒ Object
21 22 23 |
# File 'lib/claymore/gpu_hash_rate.rb', line 21 def self.call(line) new(line).call end |
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics/MethodLength
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/claymore/gpu_hash_rate.rb', line 32 def call (match = LINE_REGEXP.match(line)) || return raw_rates.each_with_object([]) do |(raw_index, raw_rate), acc| hash_rate = raw_rate == 'off' ? -1.0 : raw_rate.to_f.round(3) index = raw_index.to_i acc << { 'type' => 'GPU_HASH_RATE', 'asset' => match[:asset], 'gpu' => index, 'hash_rate' => hash_rate } end end |