Fixed issue #645 - Dashboard widget "Waiting time today" is not counting.
This commit is contained in:
parent
7c3e530233
commit
de7fef8c18
2 changed files with 17 additions and 6 deletions
|
@ -55,19 +55,25 @@ class Stats::TicketWaitingTime
|
|||
|
||||
def self.calculate_average(tickets, start_time)
|
||||
average_time = 0
|
||||
count_time = 0
|
||||
count_articles = 0
|
||||
|
||||
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|
|
||||
if article.sender.name == 'Customer'
|
||||
count_time = article.created_at.to_i
|
||||
else
|
||||
elsif count_time.positive?
|
||||
average_time += article.created_at.to_i - count_time
|
||||
count_articles += 1
|
||||
count_time = 0
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
if count_articles.positive?
|
||||
average_time = average_time / count_articles
|
||||
end
|
||||
|
||||
average_time
|
||||
end
|
||||
end
|
||||
|
|
|
@ -144,7 +144,12 @@ class StatsTicketWaitingTimeTest < ActiveSupport::TestCase
|
|||
)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue