2017-04-18 08:06:22 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class Stats::TicketWaitingTime
|
|
|
|
|
|
|
|
def self.generate(user)
|
|
|
|
|
|
|
|
# get users groups
|
2017-06-16 20:43:09 +00:00
|
|
|
group_ids = user.group_ids_access('full')
|
2017-04-18 08:06:22 +00:00
|
|
|
|
|
|
|
own_waiting = Ticket.where(
|
2017-04-20 15:12:39 +00:00
|
|
|
'owner_id = ? AND group_id IN (?) AND updated_at > ?', user.id, group_ids, Time.zone.today
|
2017-04-18 08:06:22 +00:00
|
|
|
)
|
|
|
|
all_waiting = Ticket.where(
|
2017-04-20 15:12:39 +00:00
|
|
|
'group_id IN (?) AND updated_at > ?', group_ids, Time.zone.today
|
2017-04-18 08:06:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
handling_time = calculate_average(own_waiting, Time.zone.today)
|
|
|
|
if handling_time.positive?
|
|
|
|
handling_time = (handling_time / 60).round
|
|
|
|
end
|
|
|
|
average_per_agent = calculate_average(all_waiting, Time.zone.today)
|
|
|
|
if average_per_agent.positive?
|
|
|
|
average_per_agent = (average_per_agent / 60).round
|
|
|
|
end
|
|
|
|
|
|
|
|
state = 'supergood'
|
|
|
|
percent = 0
|
|
|
|
state = if handling_time <= 60
|
|
|
|
percent = handling_time.to_f / 60
|
|
|
|
'supergood'
|
|
|
|
elsif handling_time <= 60 * 4
|
|
|
|
percent = (handling_time.to_f - 60) / (60 * 3)
|
|
|
|
'good'
|
|
|
|
elsif handling_time <= 60 * 8
|
|
|
|
percent = (handling_time.to_f - 60 * 4) / (60 * 4)
|
|
|
|
'ok'
|
|
|
|
else
|
|
|
|
percent = 1.00
|
|
|
|
'bad'
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
handling_time: handling_time,
|
|
|
|
average_per_agent: average_per_agent,
|
|
|
|
state: state,
|
|
|
|
percent: percent,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.average_state(result, _user_id)
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.calculate_average(tickets, start_time)
|
2017-04-20 10:04:20 +00:00
|
|
|
average_time = 0
|
|
|
|
count_articles = 0
|
2017-04-18 08:06:22 +00:00
|
|
|
|
|
|
|
tickets.each { |ticket|
|
2017-04-20 10:04:20 +00:00
|
|
|
count_time = 0
|
2017-04-18 08:06:22 +00:00
|
|
|
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
|
2017-04-20 10:04:20 +00:00
|
|
|
elsif count_time.positive?
|
|
|
|
average_time += article.created_at.to_i - count_time
|
|
|
|
count_articles += 1
|
|
|
|
count_time = 0
|
2017-04-18 08:06:22 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 10:04:20 +00:00
|
|
|
if count_articles.positive?
|
|
|
|
average_time = average_time / count_articles
|
|
|
|
end
|
|
|
|
|
2017-04-18 08:06:22 +00:00
|
|
|
average_time
|
|
|
|
end
|
|
|
|
end
|