Moved to new history api.
This commit is contained in:
parent
097b24a07e
commit
0f9eda18be
1 changed files with 15 additions and 16 deletions
|
@ -167,7 +167,7 @@ def escalation_calculation_get_sla
|
||||||
sla_selected = nil
|
sla_selected = nil
|
||||||
sla_list = Cache.get( 'SLA::List::Active' )
|
sla_list = Cache.get( 'SLA::List::Active' )
|
||||||
if sla_list == nil
|
if sla_list == nil
|
||||||
sla_list = Sla.where( :active => true ).all
|
sla_list = Sla.where( :active => true )
|
||||||
Cache.write( 'SLA::List::Active', sla_list, { :expires_in => 1.hour } )
|
Cache.write( 'SLA::List::Active', sla_list, { :expires_in => 1.hour } )
|
||||||
end
|
end
|
||||||
sla_list.each {|sla|
|
sla_list.each {|sla|
|
||||||
|
@ -221,53 +221,52 @@ def escalation_calculation_get_sla
|
||||||
history_list.each { |history_item|
|
history_list.each { |history_item|
|
||||||
|
|
||||||
# ignore if it isn't a state change
|
# ignore if it isn't a state change
|
||||||
next if !history_item.history_attribute_id
|
next if !history_item['attribute']
|
||||||
history_attribute = History::Attribute.lookup( :id => history_item.history_attribute_id );
|
next if history_item['attribute'] != 'ticket_state'
|
||||||
next if history_attribute.name != 'ticket_state'
|
|
||||||
|
|
||||||
# ignore all newer state before start_time
|
# ignore all newer state before start_time
|
||||||
next if history_item.created_at < start_time
|
next if history_item['created_at'] < start_time
|
||||||
|
|
||||||
# ignore all older state changes after end_time
|
# ignore all older state changes after end_time
|
||||||
next if last_state_change && last_state_change > end_time
|
next if last_state_change && last_state_change > end_time
|
||||||
|
|
||||||
# if created_at is later then end_time, use end_time as last time
|
# if created_at is later then end_time, use end_time as last time
|
||||||
if history_item.created_at > end_time
|
if history_item['created_at'] > end_time
|
||||||
history_item.created_at = end_time
|
history_item['created_at'] = end_time
|
||||||
end
|
end
|
||||||
|
|
||||||
# get initial state and time
|
# get initial state and time
|
||||||
if !last_state
|
if !last_state
|
||||||
last_state = history_item.value_from
|
last_state = history_item['value_from']
|
||||||
last_state_change = start_time
|
last_state_change = start_time
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if time need to be counted
|
# check if time need to be counted
|
||||||
counted = true
|
counted = true
|
||||||
if history_item.value_from == 'pending'
|
if history_item['value_from'] == 'pending'
|
||||||
counted = false
|
counted = false
|
||||||
elsif history_item.value_from == 'close'
|
elsif history_item['value_from'] == 'close'
|
||||||
counted = false
|
counted = false
|
||||||
end
|
end
|
||||||
|
|
||||||
diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected )
|
diff = escalation_time_diff( last_state_change, history_item['created_at'], sla_selected )
|
||||||
if counted
|
if counted
|
||||||
puts "Diff count #{history_item.value_from} -> #{history_item.value_to} / #{last_state_change} -> #{history_item.created_at}"
|
puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
|
||||||
total_time_without_pending = total_time_without_pending + diff
|
total_time_without_pending = total_time_without_pending + diff
|
||||||
else
|
else
|
||||||
puts "Diff not count #{history_item.value_from} -> #{history_item.value_to} / #{last_state_change} -> #{history_item.created_at}"
|
puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
|
||||||
end
|
end
|
||||||
total_time = total_time + diff
|
total_time = total_time + diff
|
||||||
|
|
||||||
if history_item.value_to == 'pending'
|
if history_item['value_to'] == 'pending'
|
||||||
last_state_is_pending = true
|
last_state_is_pending = true
|
||||||
else
|
else
|
||||||
last_state_is_pending = false
|
last_state_is_pending = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# remember for next loop last state
|
# remember for next loop last state
|
||||||
last_state = history_item.value_to
|
last_state = history_item['value_to']
|
||||||
last_state_change = history_item.created_at
|
last_state_change = history_item['created_at']
|
||||||
}
|
}
|
||||||
|
|
||||||
# if last state isnt pending, count rest
|
# if last state isnt pending, count rest
|
||||||
|
|
Loading…
Reference in a new issue