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 ) 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 # 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) # 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 ) 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 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 ) 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 # set ticket escalation
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false ) self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.update_time_escal_date, false )
end 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 ) 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 # 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) # 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 ) 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 # real - time without supsend state
# relative - only suspend time # 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_without_pending = 0
total_time = 0 total_time = 0
#get history for ticket #get history for ticket
@ -748,6 +757,9 @@ class Ticket < ApplicationModel
history_attribute = History::Attribute.lookup( :id => history_item.history_attribute_id ); history_attribute = History::Attribute.lookup( :id => history_item.history_attribute_id );
next if history_attribute.name != 'ticket_state' 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 # 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
@ -762,29 +774,26 @@ class Ticket < ApplicationModel
last_state_change = start_time last_state_change = start_time
end end
# use time if ticket got from e. g. open to pending # check if time need to be counted
if history_item.value_from != 'pending' && history_item.value_to == 'pending' counted = true
diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected ) if history_item.value_from == 'pending'
puts "Diff count !=pending -> ==pending #{diff.to_s} - #{last_state_change} - #{history_item.created_at}" counted = false
total_time_without_pending = total_time_without_pending + diff elsif history_item.value_from == 'close'
total_time = total_time + diff counted = false
last_state_is_pending = true 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 ) 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_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 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 last_state_is_pending = false
end end
@ -810,9 +819,9 @@ class Ticket < ApplicationModel
end end
#return sum #return sum
if (type == 'real') if type == 'real'
return total_time_without_pending return total_time_without_pending
elsif (type == 'relative') elsif type == 'relative'
relative = total_time - total_time_without_pending relative = total_time - total_time_without_pending
return relative return relative
else else

View file

@ -572,8 +572,6 @@ class TicketTest < ActiveSupport::TestCase
end end
test 'ticket escalation suspend' do test 'ticket escalation suspend' do
ticket = Ticket.create( ticket = Ticket.create(
:title => 'some title äöüß3', :title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'), :group => Group.lookup( :name => 'Users'),
@ -598,8 +596,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open', :value_from => 'open',
:value_to => 'pending', :value_to => 'pending',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 10:00:00', :created_at => '2013-06-04 10:00:00 UTC',
:updated_at => '2013-06-04 10:00:00' :updated_at => '2013-06-04 10:00:00 UTC',
) )
# set ticket at 10:30 to open # set ticket at 10:30 to open
@ -613,30 +611,16 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'open', :value_to => 'open',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 10:30:00', :created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00' :updated_at => '2013-06-04 10:30:00 UTC'
) )
# set ticket from 11:00 to pending # set update time
#History.add( ticket.update_attributes(
# :history_type => 'updated', :last_contact_agent => '2013-06-04 10:15:00 UTC',
# :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 first response time
ticket.update_attributes( ticket.update_attributes(
:first_response => '2013-06-04 10:45:00 UTC', :first_response => '2013-06-04 10:45:00 UTC',
) )
@ -652,8 +636,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open', :value_from => 'open',
:value_to => 'closed', :value_to => 'closed',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 12:00:00', :created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00' :updated_at => '2013-06-04 12:00:00 UTC'
) )
ticket.update_attributes( ticket.update_attributes(
@ -672,28 +656,27 @@ class TicketTest < ActiveSupport::TestCase
:timezone => 'Europe/Berlin', :timezone => 'Europe/Berlin',
:first_response_time => 120, :first_response_time => 120,
:update_time => 180, :update_time => 180,
:close_time => 240, :close_time => 250,
:active => true, :active => true,
:updated_by_id => 1, :updated_by_id => 1,
:created_by_id => 1, :created_by_id => 1,
) )
ticket = Ticket.find(ticket.id) 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_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_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.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.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:30:00 UTC', 'ticket.close_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_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 delete = sla.destroy
assert( delete, "sla destroy" ) assert( delete, "sla destroy" )
delete = ticket.destroy delete = ticket.destroy
assert( 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( ticket = Ticket.create(
:title => 'some title äöüß3', :title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'), :group => Group.lookup( :name => 'Users'),
@ -719,8 +702,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'closed', :value_to => 'closed',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 12:00:00', :created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00' :updated_at => '2013-06-04 12:00:00 UTC',
) )
ticket.update_attributes( ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC', :close_time => '2013-06-04 12:00:00 UTC',
@ -734,7 +717,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00", "beginning_of_workday" => "9:00",
"end_of_workday" => "18:00", "end_of_workday" => "18:00",
}, },
#:timezone => 'Europe/Berlin',
:first_response_time => 120, :first_response_time => 120,
:update_time => 180, :update_time => 180,
:close_time => 240, :close_time => 240,
@ -744,7 +726,7 @@ class TicketTest < ActiveSupport::TestCase
) )
ticket = Ticket.find(ticket.id) 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_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_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' ) 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" ) 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( ticket = Ticket.create(
:title => 'some title äöüß3', :title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'), :group => Group.lookup( :name => 'Users'),
@ -774,7 +756,7 @@ class TicketTest < ActiveSupport::TestCase
) )
assert( ticket, 'ticket created' ) assert( ticket, 'ticket created' )
#state change to open 10:30 # state change to open 10:30
History.add( History.add(
:history_type => 'updated', :history_type => 'updated',
:history_object => 'Ticket', :history_object => 'Ticket',
@ -785,11 +767,11 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'open', :value_to => 'open',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 10:30:00', :created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00' :updated_at => '2013-06-04 10:30:00 UTC',
) )
#state change to pending 11:00 # state change to pending 11:00
History.add( History.add(
:history_type => 'updated', :history_type => 'updated',
:history_object => 'Ticket', :history_object => 'Ticket',
@ -800,8 +782,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open', :value_from => 'open',
:value_to => 'pending', :value_to => 'pending',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 11:00:00', :created_at => '2013-06-04 11:00:00 UTC',
:updated_at => '2013-06-04 11:00:00' :updated_at => '2013-06-04 11:00:00 UTC',
) )
# set ticket from 12:00 to closed # set ticket from 12:00 to closed
@ -815,8 +797,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'closed', :value_to => 'closed',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 12:00:00', :created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00' :updated_at => '2013-06-04 12:00:00 UTC',
) )
ticket.update_attributes( ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC', :close_time => '2013-06-04 12:00:00 UTC',
@ -830,7 +812,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00", "beginning_of_workday" => "9:00",
"end_of_workday" => "18:00", "end_of_workday" => "18:00",
}, },
#:timezone => 'Europe/Berlin',
:first_response_time => 120, :first_response_time => 120,
:update_time => 180, :update_time => 180,
:close_time => 240, :close_time => 240,
@ -840,7 +821,7 @@ class TicketTest < ActiveSupport::TestCase
) )
ticket = Ticket.find(ticket.id) 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_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_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' ) assert_equal( ticket.first_response_diff_in_min, nil, 'ticket.first_response_diff_in_min verify 3' )
@ -870,7 +851,7 @@ class TicketTest < ActiveSupport::TestCase
) )
assert( ticket, 'ticket created' ) assert( ticket, 'ticket created' )
#state change to open from pending # state change to open from pending
History.add( History.add(
:history_type => 'updated', :history_type => 'updated',
:history_object => 'Ticket', :history_object => 'Ticket',
@ -881,11 +862,11 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'open', :value_to => 'open',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 10:30:00', :created_at => '2013-06-04 10:30:00 UTC',
:updated_at => '2013-06-04 10:30:00' :updated_at => '2013-06-04 10:30:00 UTC',
) )
#state change to pending from open 11:00 # state change to pending from open 11:00
History.add( History.add(
:history_type => 'updated', :history_type => 'updated',
:history_object => 'Ticket', :history_object => 'Ticket',
@ -896,11 +877,11 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'open', :value_from => 'open',
:value_to => 'pending', :value_to => 'pending',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 11:00:00', :created_at => '2013-06-04 11:00:00 UTC',
:updated_at => '2013-06-04 11:00:00' :updated_at => '2013-06-04 11:00:00 UTC',
) )
#state change to open 11:30 # state change to open 11:30
History.add( History.add(
:history_type => 'updated', :history_type => 'updated',
:history_object => 'Ticket', :history_object => 'Ticket',
@ -911,8 +892,8 @@ class TicketTest < ActiveSupport::TestCase
:value_from => 'pending', :value_from => 'pending',
:value_to => 'open', :value_to => 'open',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 11:30:00', :created_at => '2013-06-04 11:30:00 UTC',
:updated_at => '2013-06-04 11:30:00' :updated_at => '2013-06-04 11:30:00 UTC',
) )
# set ticket from open to closed 12:00 # set ticket from open to closed 12:00
@ -923,11 +904,11 @@ class TicketTest < ActiveSupport::TestCase
:o_id => ticket.id, :o_id => ticket.id,
:id_to => 4, :id_to => 4,
:id_from => 3, :id_from => 3,
:value_from => 'pending', :value_from => 'open',
:value_to => 'closed', :value_to => 'closed',
:created_by_id => 1, :created_by_id => 1,
:created_at => '2013-06-04 12:00:00', :created_at => '2013-06-04 12:00:00 UTC',
:updated_at => '2013-06-04 12:00:00' :updated_at => '2013-06-04 12:00:00 UTC',
) )
ticket.update_attributes( ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC', :close_time => '2013-06-04 12:00:00 UTC',
@ -941,7 +922,6 @@ class TicketTest < ActiveSupport::TestCase
"beginning_of_workday" => "9:00", "beginning_of_workday" => "9:00",
"end_of_workday" => "18:00", "end_of_workday" => "18:00",
}, },
#:timezone => 'Europe/Berlin',
:first_response_time => 120, :first_response_time => 120,
:update_time => 180, :update_time => 180,
:close_time => 240, :close_time => 240,
@ -951,7 +931,7 @@ class TicketTest < ActiveSupport::TestCase
) )
ticket = Ticket.find(ticket.id) 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_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_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' ) 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 delete = ticket.destroy
assert( delete, "ticket destroy" ) assert( delete, "ticket destroy" )
end end
end end