2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
class Stats::TicketResponseTime
|
|
|
|
|
|
|
|
def self.log(object, o_id)
|
|
|
|
return if object != 'Ticket'
|
|
|
|
|
|
|
|
ticket = Ticket.lookup(id: o_id)
|
|
|
|
|
|
|
|
article_created_by_id = 3
|
|
|
|
|
|
|
|
# check if response was sent by owner
|
|
|
|
return if ticket.owner_id != 1 && ticket.owner_id != article_created_by_id
|
|
|
|
|
|
|
|
# return if customer send at least
|
2016-09-14 07:15:30 +00:00
|
|
|
return if ticket.last_contact_customer_at > ticket.last_contact_agent_at
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
# TODO: only business hours
|
2016-09-14 07:15:30 +00:00
|
|
|
response_time_taken = ticket.last_contact_agent_at - ticket.last_contact_customer_at
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
(response_time_taken / 60).round
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.generate(user)
|
2015-09-08 06:55:09 +00:00
|
|
|
items = StatsStore.where('created_at > ? AND created_at < ?', Time.zone.now - 7.days, Time.zone.now).where(key: 'ticket:response_time')
|
2015-09-06 22:42:11 +00:00
|
|
|
total = 0
|
|
|
|
count_own = 0
|
|
|
|
own = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
items.each do |_item|
|
2015-09-06 22:42:11 +00:00
|
|
|
ticket = Ticket.lookup(id: data[:ticket_id])
|
|
|
|
if ticket.owner_id == user.id
|
|
|
|
count_own += 1
|
|
|
|
own += data[:time]
|
|
|
|
end
|
|
|
|
total += data[:time]
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-07-26 22:02:28 +00:00
|
|
|
if total.nonzero?
|
2015-09-08 06:55:09 +00:00
|
|
|
own = (own / count_own).round
|
|
|
|
end
|
2015-09-06 22:42:11 +00:00
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
used_for_average: 0,
|
2015-09-08 06:55:09 +00:00
|
|
|
average_per_agent: '-',
|
2018-12-19 17:31:51 +00:00
|
|
|
own: own,
|
|
|
|
total: total,
|
2015-09-06 22:42:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-09-08 10:59:46 +00:00
|
|
|
def self.average_state(result, _user_id)
|
|
|
|
|
|
|
|
return result if !result.key?(:used_for_average)
|
|
|
|
|
|
|
|
if result[:total] < 1
|
|
|
|
result[:state] = 'supergood'
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2021-07-16 13:38:01 +00:00
|
|
|
in_percent = (result[:used_for_average].to_f / (result[:total].to_f / 100)).round(1)
|
2016-01-15 17:22:57 +00:00
|
|
|
result[:state] = if in_percent >= 90
|
|
|
|
'supergood'
|
|
|
|
elsif in_percent >= 65
|
|
|
|
'good'
|
|
|
|
elsif in_percent >= 40
|
|
|
|
'ok'
|
|
|
|
elsif in_percent >= 20
|
|
|
|
'bad'
|
|
|
|
else
|
|
|
|
'superbad'
|
|
|
|
end
|
2015-09-08 10:59:46 +00:00
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2015-09-06 22:42:11 +00:00
|
|
|
end
|