class Symian::Configuration

Attributes

filename[RW]

Public Class Methods

load_from_file(filename) click to toggle source
# File lib/symian/configuration.rb, line 79
def self.load_from_file(filename)
  # allow filename, string, and IO objects as input
  raise ArgumentError, "File #{filename} does not exist!" unless File.exists?(filename)

  # create configuration object
  conf = Configuration.new(filename)

  # take the file content and pass it to instance_eval
  conf.instance_eval(File.new(filename, 'r').read)

  # validate and finalize configuration
  conf.validate

  # return new object
  conf
end
new(filename) click to toggle source
# File lib/symian/configuration.rb, line 24
def initialize(filename)
  @filename = filename
end

Public Instance Methods

end_time() click to toggle source
# File lib/symian/configuration.rb, line 28
def end_time
  @start_time + @duration
end
reallocate_ops_and_clone(operators) click to toggle source
# File lib/symian/configuration.rb, line 51
def reallocate_ops_and_clone(operators)
  raise 'Wrong allocation' unless operators.size == @support_groups.size

  new_conf = Configuration.new(@filename)
  new_conf.start_time          @start_time
  new_conf.duration            @duration
  new_conf.warmup_duration     @warmup_duration
  new_conf.incident_generation @incident_generation
  new_conf.transition_matrix   @transition_matrix
  new_conf.cost_analysis       @cost_analysis

  new_sgs = {}
  @support_groups.zip(operators) do |(sg_name,sg_conf),num_ops|
    new_sgs[sg_name] = {
      work_time: sg_conf[:work_time], # this is already frozen
      operators: {
        number: num_ops,
        workshift: sg_conf[:operators][:workshift], # this is already frozen
      },
    }
  end
  new_sgs.deep_freeze

  new_conf.support_groups(new_sgs)

  new_conf
end
validate() click to toggle source
# File lib/symian/configuration.rb, line 32
def validate
  # @start_time      = @start_time.to_i
  # @duration        = @duration.to_i
  # @warmup_duration = @warmup_duration.to_i

  if @incident_generation[:type] == :file
    @incident_generation[:source][:path].gsub!('<pwd>', File.expand_path(File.dirname(@filename)))
  end

  # freeze everything!
  @start_time.deep_freeze
  @duration.deep_freeze
  @warmup_duration.deep_freeze
  @incident_generation.deep_freeze
  @transition_matrix.deep_freeze
  @cost_analysis.deep_freeze
  @support_groups.deep_freeze
end