class GnCrossmap::Stats

Collects statistics about crossmapping process

Attributes

stats[RW]

Public Class Methods

new() click to toggle source
# File lib/gn_crossmap/stats.rb, line 8
def initialize
  @stats = { status: :init, total_records: 0, ingested_records: 0,
             ingestion_span: nil, ingestion_start: nil,
             resolution: eta_struct,
             matches: match_types, errors: [] }
  @smooth = 0.05
end

Public Instance Methods

penalty(threads) click to toggle source
# File lib/gn_crossmap/stats.rb, line 16
def penalty(threads)
  pnlt = 0.7
  penalty_adj(threads.to_i, 1, pnlt)
end
update_eta(current_speed) click to toggle source
# File lib/gn_crossmap/stats.rb, line 21
def update_eta(current_speed)
  eta = @stats[:resolution]
  eta[:speed] = current_speed if eta[:speed].nil?
  eta[:speed] = eta[:speed] * (1 - @smooth) + current_speed * @smooth
  eta[:eta] = (@stats[:total_records] -
               @stats[:resolution][:completed_records]) /
              eta[:speed]
end

Private Instance Methods

eta_struct() click to toggle source
# File lib/gn_crossmap/stats.rb, line 32
def eta_struct
  { start_time: nil, completed_records: 0, time_span: 0,
    speed: nil, eta: nil, stop_time: nil }
end
match_types() click to toggle source
# File lib/gn_crossmap/stats.rb, line 37
def match_types
  matches = GnCrossmap::MATCH_TYPES.keys
  matches.each_with_object({}) do |key, obj|
    obj[key] = 0
  end
end
penalty_adj(threads, val, pnlt) click to toggle source
# File lib/gn_crossmap/stats.rb, line 44
def penalty_adj(threads, val, pnlt)
  return val if threads < 2
  val + penalty_adj(threads - 1, (val * pnlt), pnlt)
end