2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
class Stats::TicketReopen
|
|
|
|
|
|
|
|
def self.generate(user)
|
2015-09-09 06:49:08 +00:00
|
|
|
|
|
|
|
# get my closed tickets
|
|
|
|
total = Ticket.select('id').where(
|
2016-09-14 07:15:30 +00:00
|
|
|
'owner_id = ? AND close_at > ?',
|
2015-09-09 06:49:08 +00:00
|
|
|
user.id, Time.zone.now - 7.days
|
|
|
|
).count
|
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
# get count of reopens
|
2020-10-06 13:13:50 +00:00
|
|
|
count = StatsStore.where(
|
|
|
|
stats_storable: user,
|
|
|
|
key: 'ticket:reopen',
|
|
|
|
).where('created_at > ? AND created_at < ?', 7.days.ago, Time.zone.now).count
|
2015-09-09 06:49:08 +00:00
|
|
|
|
|
|
|
if count > total
|
|
|
|
total = count
|
|
|
|
end
|
|
|
|
|
|
|
|
reopen_in_precent = 0
|
2016-07-26 22:02:28 +00:00
|
|
|
if total.nonzero?
|
2021-07-16 13:38:01 +00:00
|
|
|
reopen_in_precent = (count.to_f / (total.to_f / 100)).round(1)
|
2015-09-09 06:49:08 +00:00
|
|
|
end
|
2015-09-06 22:42:11 +00:00
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
used_for_average: reopen_in_precent,
|
|
|
|
percent: reopen_in_precent,
|
2015-09-08 10:59:46 +00:00
|
|
|
average_per_agent: '-',
|
2018-12-19 17:31:51 +00:00
|
|
|
state: 'good',
|
|
|
|
count: count,
|
|
|
|
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)
|
|
|
|
|
2021-12-27 14:50:27 +00:00
|
|
|
if result[:total] < 1 || result[:average_per_agent].to_d == BigDecimal('0.0')
|
2015-09-08 10:59:46 +00:00
|
|
|
result[:state] = 'supergood'
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2021-07-16 13:44:10 +00:00
|
|
|
# in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
|
|
|
|
# result[:average_per_agent_in_percent] = in_percent
|
2021-07-16 13:38:01 +00:00
|
|
|
in_percent = (result[:count].to_f / (result[:total].to_f / 100)).round(1)
|
2016-01-15 17:22:57 +00:00
|
|
|
result[:state] = if in_percent >= 90
|
|
|
|
'superbad'
|
|
|
|
elsif in_percent >= 65
|
|
|
|
'bad'
|
|
|
|
elsif in_percent >= 40
|
|
|
|
'ok'
|
|
|
|
elsif in_percent >= 20
|
|
|
|
'good'
|
|
|
|
else
|
|
|
|
'supergood'
|
|
|
|
end
|
2015-09-08 10:59:46 +00:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2015-09-06 22:42:11 +00:00
|
|
|
def self.log(object, o_id, changes, updated_by_id)
|
|
|
|
return if object != 'Ticket'
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-09-06 22:42:11 +00:00
|
|
|
ticket = Ticket.lookup(id: o_id)
|
2017-07-19 05:29:52 +00:00
|
|
|
return if !ticket
|
2015-09-06 22:42:11 +00:00
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
# check if close_at is already set / if not, ticket is not reopened
|
2016-09-14 07:15:30 +00:00
|
|
|
return if !ticket.close_at
|
2015-09-06 22:42:11 +00:00
|
|
|
|
2015-10-12 14:07:21 +00:00
|
|
|
# only if state id has changed
|
2015-09-06 22:42:11 +00:00
|
|
|
return if !changes['state_id']
|
2015-10-12 14:07:21 +00:00
|
|
|
|
|
|
|
# only if ticket is not created in closed state
|
|
|
|
return if !changes['state_id'][0]
|
|
|
|
|
|
|
|
# only if current owner is not 1
|
2015-09-06 22:42:11 +00:00
|
|
|
return if ticket.owner_id == 1
|
|
|
|
|
|
|
|
state_before = Ticket::State.lookup(id: changes['state_id'][0])
|
|
|
|
state_type_before = Ticket::StateType.lookup(id: state_before.state_type_id)
|
|
|
|
return if state_type_before.name != 'closed'
|
|
|
|
|
|
|
|
state_now = Ticket::State.lookup(id: changes['state_id'][1])
|
|
|
|
state_type_now = Ticket::StateType.lookup(id: state_now.state_type_id)
|
|
|
|
return if state_type_now.name == 'closed'
|
|
|
|
|
2020-10-06 13:13:50 +00:00
|
|
|
StatsStore.create(
|
|
|
|
stats_storable: ticket.owner,
|
|
|
|
key: 'ticket:reopen',
|
|
|
|
data: { ticket_id: ticket.id },
|
|
|
|
created_at: Time.zone.now,
|
|
|
|
created_by_id: updated_by_id,
|
2015-09-06 22:42:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|