Class: Symian::Operator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/symian/operator.rb

Constant Summary collapse

REQUIRED_ATTRIBUTES =
[
  :oid,
  :support_group_id,
]
OTHER_ATTRIBUTES =
[
  :workshift,
  :specialization,
  :work_record,
  :support_group_id,
]

Instance Method Summary collapse

Constructor Details

#initialize(oid, support_group_id, opts = {}) ⇒ Operator

Returns a new instance of Operator.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/symian/operator.rb', line 31

def initialize(oid, support_group_id, opts={})
  @oid = oid
  @support_group_id = support_group_id

  # 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

  # support :workshift => :all_day_long shortcut
  if @workshift == :all_day_long
    @workshift = WorkShift::WORKSHIFT_24x7
  end

  # default workshift is 24x7
  @workshift ||= WorkShift::WORKSHIFT_24x7

  @specialization ||= {}
  @work_record ||= []
end

Instance Method Details

#assign(incident, incident_info, time) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/symian/operator.rb', line 54

def assign(incident, incident_info, time)

  # initialize incident start work time if needed
  incident.start_work_time ||= time

  # calculate time to end of shift
  tteos = @workshift.secs_to_end_of_shift(time)
  raise "tteos: #{tteos}" if tteos < 0.0

  # specialization
  specialization = @specialization[incident.category] || 1.0

  # calculate time to incident escalation
  ttie = incident_info[:needed_work_time] / specialization.to_f
  raise "ttie: #{ttie}" if ttie < 0.0

  # handle incident
  if tteos < ttie # end of shift first
    work_time = tteos
    reason = :operator_off_duty
  else # escalation first
    work_time = ttie
    reason = :incident_escalation
  end

  # update needed (effective) incident work time
  incident_info[:needed_work_time] -= work_time * specialization

  # update incident tracking
  incident.add_tracking_information(:type => :work,
                                    :at => time,
                                    :duration => work_time,
                                    :sg => @support_group_id,
                                    :operator => @oid)

  # update operator work record
  @work_record << Activity.new(incident.iid, time, time + work_time)

  # return [ reason, time_when_operator_stops_working ]
  [ reason, time + work_time ]
end