Fixed issue #645 - Dashboard widget "Waiting time today" is not counting.

This commit is contained in:
Rolf Schmidt 2017-04-20 12:04:20 +02:00
parent 7c3e530233
commit de7fef8c18
2 changed files with 17 additions and 6 deletions

View file

@ -54,20 +54,26 @@ class Stats::TicketWaitingTime
end end
def self.calculate_average(tickets, start_time) def self.calculate_average(tickets, start_time)
average_time = 0 average_time = 0
count_time = 0 count_articles = 0
tickets.each { |ticket| tickets.each { |ticket|
count_time = 0
ticket.articles.joins(:type).where('ticket_articles.created_at > ? AND ticket_articles.internal = ? AND ticket_article_types.communication = ?', start_time, false, true).each { |article| ticket.articles.joins(:type).where('ticket_articles.created_at > ? AND ticket_articles.internal = ? AND ticket_article_types.communication = ?', start_time, false, true).each { |article|
if article.sender.name == 'Customer' if article.sender.name == 'Customer'
count_time = article.created_at.to_i count_time = article.created_at.to_i
else elsif count_time.positive?
average_time += article.created_at.to_i - count_time average_time += article.created_at.to_i - count_time
count_time = 0 count_articles += 1
count_time = 0
end end
} }
} }
if count_articles.positive?
average_time = average_time / count_articles
end
average_time average_time
end end
end end

View file

@ -144,7 +144,12 @@ class StatsTicketWaitingTimeTest < ActiveSupport::TestCase
) )
average_time = Stats::TicketWaitingTime.calculate_average([ticket1, ticket1], '2017-04-13 00:00:00') average_time = Stats::TicketWaitingTime.calculate_average([ticket1, ticket1], '2017-04-13 00:00:00')
assert_equal(60 * 60 * 6 * 2, average_time)
expected_average_time = 60 * 60 * 2 # for communication 2
expected_average_time += 60 * 60 * 4 # for communication 3
expected_average_time = expected_average_time / 2 # for average
assert_equal(expected_average_time, average_time)
end end
end end