Added more tests for pending->close or pending->open->pending-close. Thanks to Katia for some hints to improved the logic.

This commit is contained in:
Martin Edenhofer 2013-07-19 22:10:35 +02:00
parent 2db0959477
commit 9224a183e7
2 changed files with 83 additions and 96 deletions

View file

@ -619,7 +619,7 @@ class Ticket < ApplicationModel
self.first_response_escal_date = TimeCalculation.dest_time( self.created_at, sla_selected.first_response_time, sla_selected.data, sla_selected.timezone )
# get pending time between created and first response escal. time
time_in_pending = escalation_suspend( self.created_at, self.first_response_escal_date, 'relative', sla_selected )
time_in_pending = escalation_suspend( self.created_at, self.first_response_escal_date, 'relative', sla_selected, sla_selected.first_response_time )
# get new escalation time (original escal_date + time_in_pending)
self.first_response_escal_date = TimeCalculation.dest_time( self.first_response_escal_date, time_in_pending.to_i, sla_selected.data, sla_selected.timezone )
@ -648,6 +648,12 @@ class Ticket < ApplicationModel
if sla_selected.update_time
self.update_time_escal_date = TimeCalculation.dest_time( last_update, sla_selected.update_time, sla_selected.data, sla_selected.timezone )
# get pending time between created and update escal. time
time_in_pending = escalation_suspend( last_update, self.update_time_escal_date, 'relative', sla_selected, sla_selected.update_time )
# get new escalation time (original escal_date + time_in_pending)
self.update_time_escal_date = TimeCalculation.dest_time( self.update_time_escal_date, time_in_pending.to_i, sla_selected.data, sla_selected.timezone )
# set ticket escalation
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false )
end
@ -668,7 +674,7 @@ class Ticket < ApplicationModel
self.close_time_escal_date = TimeCalculation.dest_time( self.created_at, sla_selected.close_time, sla_selected.data, sla_selected.timezone )
# get pending time between created and close escal. time
extended_escalation = escalation_suspend( self.created_at, self.close_time_escal_date, 'relative', sla_selected )
extended_escalation = escalation_suspend( self.created_at, self.close_time_escal_date, 'relative', sla_selected, sla_selected.close_time )
# get new escalation time (original escal_date + time_in_pending)
self.close_time_escal_date = TimeCalculation.dest_time( self.close_time_escal_date, extended_escalation.to_i, sla_selected.data, sla_selected.timezone )
@ -731,7 +737,10 @@ class Ticket < ApplicationModel
# real - time without supsend state
# relative - only suspend time
def escalation_suspend (start_time, end_time, type, sla_selected)
def escalation_suspend (start_time, end_time, type, sla_selected, sla_time = 0)
if type == 'relative'
end_time += sla_time * 60
end
total_time_without_pending = 0
total_time = 0
#get history for ticket
@ -748,6 +757,9 @@ class Ticket < ApplicationModel
history_attribute = History::Attribute.lookup( :id => history_item.history_attribute_id );
next if history_attribute.name != 'ticket_state'
# ignore all newer state before start_time
next if history_item.created_at < start_time
# ignore all older state changes after end_time
next if last_state_change && last_state_change > end_time
@ -762,29 +774,26 @@ class Ticket < ApplicationModel
last_state_change = start_time
end
# use time if ticket got from e. g. open to pending
if history_item.value_from != 'pending' && history_item.value_to == 'pending'
diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected )
puts "Diff count !=pending -> ==pending #{diff.to_s} - #{last_state_change} - #{history_item.created_at}"
total_time_without_pending = total_time_without_pending + diff
total_time = total_time + diff
last_state_is_pending = true
# check if time need to be counted
counted = true
if history_item.value_from == 'pending'
counted = false
elsif history_item.value_from == 'close'
counted = false
end
# use time if ticket got from e. g. open to open
elsif history_item.value_from != 'pending' && history_item.value_to != 'pending'
diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected )
puts "Diff count !=pending -> !=pending #{diff.to_s} - #{last_state_change} - #{history_item.created_at}"
if counted
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 = total_time + diff
last_state_is_pending = false
elsif history_item.value_from == 'pending' && history_item.value_to != 'pending'
diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected )
puts "Diff not count ==pending -> !=pending #{diff.to_s} - #{last_state_change} - #{history_item.created_at}"
total_time = total_time + diff
last_state_is_pending = false
# no pending state, do not count
else
puts "Diff do not count #{history_item.value_from}->#{history_item.value_to} -> #{history_item.created_at}"
puts "Diff not count #{history_item.value_from} -> #{history_item.value_to} / #{last_state_change} -> #{history_item.created_at}"
end
total_time = total_time + diff
if history_item.value_to == 'pending'
last_state_is_pending = true
else
last_state_is_pending = false
end
@ -810,9 +819,9 @@ class Ticket < ApplicationModel
end
#return sum
if (type == 'real')
if type == 'real'
return total_time_without_pending
elsif (type == 'relative')
elsif type == 'relative'
relative = total_time - total_time_without_pending
return relative
else

View file

@ -572,8 +572,6 @@ class TicketTest < ActiveSupport::TestCase
end
test 'ticket escalation suspend' do
ticket = Ticket.create(
:title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'),
@ -598,8 +596,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open',
:value_to => 'pending',
:created_by_id => 1,
:created_at => '2013-06-04 10:00:00',
:updated_at => '2013-06-04 10:00:00'
:created_at => '2013-06-04 10:00:00 UTC',
:updated_at => '2013-06-04 10:00:00 UTC',
)
# set ticket at 10:30 to open
@ -613,30 +611,16 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'open',
:created_by_id => 1,
:created_at => '2013-06-04 10:30:00',
:updated_at => '2013-06-04 10:30:00'
:created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00 UTC'
)
# set ticket from 11:00 to pending
#History.add(
# :history_type => 'updated',
# :history_object => 'Ticket',
# :history_attribute => 'ticket_state',
# :o_id => ticket.id,
# :id_to => 3,
# :id_from => 2,
# :value_from => 'open',
# :value_to => 'pending',
# :created_by_id => 1,
# :created_at => '2013-06-04 11:00:00',
# :updated_at => '2013-06-04 11:00:00'
#)
# set first response in time
#ticket.update_attributes(
# :last_contact_agent => '2013-06-04 10:30:00 UTC',
#)
# set update time
ticket.update_attributes(
:last_contact_agent => '2013-06-04 10:15:00 UTC',
)
# set first response time
ticket.update_attributes(
:first_response => '2013-06-04 10:45:00 UTC',
)
@ -652,8 +636,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open',
:value_to => 'closed',
:created_by_id => 1,
:created_at => '2013-06-04 12:00:00',
:updated_at => '2013-06-04 12:00:00'
:created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00 UTC'
)
ticket.update_attributes(
@ -672,28 +656,27 @@ class TicketTest < ActiveSupport::TestCase
:timezone => 'Europe/Berlin',
:first_response_time => 120,
:update_time => 180,
:close_time => 240,
:close_time => 250,
:active => true,
:updated_by_id => 1,
:created_by_id => 1,
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 12:00:00 UTC', 'ticket.escalation_time verify 1' ) #check escal. time because first resp. is already done
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
assert_equal( ticket.first_response_in_min, 75, 'ticket.first_response_in_min verify 3' )
assert_equal( ticket.first_response_diff_in_min, 45, 'ticket.first_response_diff_in_min verify 3' )
#assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 13:45:00 UTC', 'ticket.update_time_escal_date verify 1' )
assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 13:40:00 UTC', 'ticket.close_time_escal_date verify 1' )
assert_equal( ticket.close_time_in_min, 150, 'ticket.close_time_in_min verify 3' )
assert_equal( ticket.close_time_diff_in_min, 90, 'ticket.close_time_diff_in_min# verify 3' )
assert_equal( ticket.close_time_diff_in_min, 100, 'ticket.close_time_diff_in_min# verify 3' )
delete = sla.destroy
assert( delete, "sla destroy" )
delete = ticket.destroy
assert( delete, "ticket destroy" )
###test Ticket created in state pending and closed without reopen or state change
# test Ticket created in state pending and closed without reopen or state change
ticket = Ticket.create(
:title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'),
@ -719,8 +702,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'closed',
:created_by_id => 1,
:created_at => '2013-06-04 12:00:00',
:updated_at => '2013-06-04 12:00:00'
:created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00 UTC',
)
ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC',
@ -734,7 +717,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00",
"end_of_workday" => "18:00",
},
#:timezone => 'Europe/Berlin',
:first_response_time => 120,
:update_time => 180,
:close_time => 240,
@ -744,7 +726,7 @@ class TicketTest < ActiveSupport::TestCase
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.escalation_time verify 1' ) #check escal. time because first resp. is already done
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.escalation_time verify 1' )
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 14:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
@ -760,7 +742,7 @@ class TicketTest < ActiveSupport::TestCase
assert( delete, "ticket destroy" )
###test Ticket created in state pending, changed state to openen, back to pending and closed
# test Ticket created in state pending, changed state to openen, back to pending and closed
ticket = Ticket.create(
:title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'),
@ -785,8 +767,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'open',
:created_by_id => 1,
:created_at => '2013-06-04 10:30:00',
:updated_at => '2013-06-04 10:30:00'
:created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00 UTC',
)
# state change to pending 11:00
@ -800,8 +782,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open',
:value_to => 'pending',
:created_by_id => 1,
:created_at => '2013-06-04 11:00:00',
:updated_at => '2013-06-04 11:00:00'
:created_at => '2013-06-04 11:00:00 UTC',
:updated_at => '2013-06-04 11:00:00 UTC',
)
# set ticket from 12:00 to closed
@ -815,8 +797,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'closed',
:created_by_id => 1,
:created_at => '2013-06-04 12:00:00',
:updated_at => '2013-06-04 12:00:00'
:created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00 UTC',
)
ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC',
@ -830,7 +812,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00",
"end_of_workday" => "18:00",
},
#:timezone => 'Europe/Berlin',
:first_response_time => 120,
:update_time => 180,
:close_time => 240,
@ -840,7 +821,7 @@ class TicketTest < ActiveSupport::TestCase
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' ) #check escal. time because first resp. is already done
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
@ -881,8 +862,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'open',
:created_by_id => 1,
:created_at => '2013-06-04 10:30:00',
:updated_at => '2013-06-04 10:30:00'
:created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00 UTC',
)
# state change to pending from open 11:00
@ -896,8 +877,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open',
:value_to => 'pending',
:created_by_id => 1,
:created_at => '2013-06-04 11:00:00',
:updated_at => '2013-06-04 11:00:00'
:created_at => '2013-06-04 11:00:00 UTC',
:updated_at => '2013-06-04 11:00:00 UTC',
)
# state change to open 11:30
@ -911,8 +892,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending',
:value_to => 'open',
:created_by_id => 1,
:created_at => '2013-06-04 11:30:00',
:updated_at => '2013-06-04 11:30:00'
:created_at => '2013-06-04 11:30:00 UTC',
:updated_at => '2013-06-04 11:30:00 UTC',
)
# set ticket from open to closed 12:00
@ -923,11 +904,11 @@ class TicketTest < ActiveSupport::TestCase
:o_id => ticket.id,
:id_to => 4,
:id_from => 3,
:value_from => 'pending',
:value_from => 'open',
:value_to => 'closed',
:created_by_id => 1,
:created_at => '2013-06-04 12:00:00',
:updated_at => '2013-06-04 12:00:00'
:created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00 UTC',
)
ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC',
@ -941,7 +922,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00",
"end_of_workday" => "18:00",
},
#:timezone => 'Europe/Berlin',
:first_response_time => 120,
:update_time => 180,
:close_time => 240,
@ -951,7 +931,7 @@ class TicketTest < ActiveSupport::TestCase
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.escalation_time verify 1' ) #check escal. time because first resp. is already done
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.escalation_time verify 1' )
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
@ -966,7 +946,5 @@ class TicketTest < ActiveSupport::TestCase
delete = ticket.destroy
assert( delete, "ticket destroy" )
end
end