class Symian::Incident

Constants

MAX_PRIORITY
MIN_PRIORITY

priorities are not currently used

OTHER_ATTRIBUTES
REQUIRED_ATTRIBUTES
TRACED_ATTRIBUTES

Public Class Methods

new(iid, arrival_time, opts={}) click to toggle source
# File lib/symian/incident.rb, line 47
def initialize(iid, arrival_time, opts={})
  @iid = iid
  @arrival_time = arrival_time

  # set correspondent instance variables for optional arguments
  opts.each do |k, v|
    # ignore invalid attributes
    instance_variable_set("@#{k}", v) if OTHER_ATTRIBUTES.include?(k)
  end

  @tracking_information ||= []
  @visited_support_groups ||= 0
end

Public Instance Methods

add_tracking_information(track_info) click to toggle source

the format of track_info is: { :type => one of [ :queue, :work, :suspend ]

:at => begin time
:duration => duration
:sg => support_group_name
:operator => operator_id (if applicable)

}

# File lib/symian/incident.rb, line 69
def add_tracking_information(track_info)
  @tracking_information << track_info
end
closed?() click to toggle source
# File lib/symian/incident.rb, line 105
def closed?
  !@closure_time.nil?
end
queue_time_at_last_sg() click to toggle source
# File lib/symian/incident.rb, line 101
def queue_time_at_last_sg
  calculate_time_at_last_support_group(:queue)
end
total_queue_time() click to toggle source
# File lib/symian/incident.rb, line 89
def total_queue_time
  calculate_time(:queue)
end
total_suspend_time() click to toggle source
# File lib/symian/incident.rb, line 93
def total_suspend_time
  calculate_time(:suspend)
end
total_time_at_last_sg() click to toggle source
# File lib/symian/incident.rb, line 97
def total_time_at_last_sg
  calculate_time_at_last_support_group(:all)
end
total_work_time() click to toggle source
# File lib/symian/incident.rb, line 85
def total_work_time
  calculate_time(:work)
end
ttr() click to toggle source
# File lib/symian/incident.rb, line 109
def ttr
  # if incident isn't closed yet, just return nil without raising an exception.
  @closure_time.nil? ? nil : (@closure_time - @arrival_time).to_int
end
with_tracking_information(type=:all) { |ti| ... } click to toggle source
# File lib/symian/incident.rb, line 73
def with_tracking_information(type=:all)
  selected_ti = if type == :all
    @tracking_information
  else
    @tracking_information.select{|el| el.type == type }
  end

  selected_ti.each do |ti|
    yield ti
  end
end

Private Instance Methods

calculate_time(type) click to toggle source
# File lib/symian/incident.rb, line 117
def calculate_time(type)
  return 0 unless @tracking_information
  @tracking_information.inject(0){|sum,x| sum += ((type == :all || type == x[:type]) ? x[:duration].to_i : 0) }
end
calculate_time_at_last_support_group(*types) click to toggle source
# File lib/symian/incident.rb, line 122
def calculate_time_at_last_support_group(*types)
  time = 0
  last_sg = nil
  @tracking_information.reverse_each do |ti|
    last_sg ||= ti[:sg]
    break unless ti[:sg] == last_sg
    time += ti[:duration].to_i if (types.include?(:all) || types.include?(ti[:type]))
  end
  time
end