Sha256: c922ea63cc8c5d33f0f5411516906da1582ff3b2d665779e7a5ec12adafeb5d3

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

require 'claymore/asset_symbol'

module Claymore
  # Extracts total hash rate with asset symbol
  #
  # Example input:
  # 05:45:16:028 2100 ETH - Total Speed: 90.118 Mh/s, Total Shares: 237, Rejected: 0, Time: 06:50
  #
  # Example output:
  # { 'asset' => 'ETH', 'hash_rate' => 90.118, 'type' => 'TOTAL_HASH_RATE' }
  class TotalHashRate
    include AssetSymbol

    TOTAL_RATE_REGEXP = %r{Total Speed: (?<rate>\d+\.\d+ Mh\/s)}
    LINE_REGEXP = Regexp.new("#{ASSET_REGEXP.source} #{TOTAL_RATE_REGEXP.source}")

    def self.call(line)
      new(line).call
    end

    attr_reader :line

    def initialize(line)
      @line = line
    end

    def call
      (match = LINE_REGEXP.match(line)) || return

      {
        'asset' => match[:asset],
        'hash_rate' => match[:rate].to_f.round(3),
        'type' => 'TOTAL_HASH_RATE'
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-claymore-1.0.0 lib/claymore/total_hash_rate.rb