Class: NoSE::Serialize::WorkloadBuilder

Inherits:
Object
  • Object
show all
Includes:
Uber::Callable
Defined in:
lib/nose/serialize.rb

Overview

Construct a new workload from a parsed hash

Instance Method Summary collapse

Instance Method Details

#call(_, input:, fragment:, represented:) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/nose/serialize.rb', line 482

def call(_, input:, fragment:, represented:, **)
  workload = input.represented
  workload.instance_variable_set :@model, represented.model

  # Add all statements to the workload
  statement_weights = Hash.new { |h, k| h[k] = {} }
  fragment['weights'].each do |mix, weights|
    mix = mix.to_sym
    weights.each do |statement, weight|
      statement_weights[statement][mix] = weight
    end
  end
  fragment['statements'].each do |statement|
    workload.add_statement statement, statement_weights[statement],
                           group: fragment['group']
  end

  workload.mix = fragment['mix'].to_sym unless fragment['mix'].nil?

  workload
end