trabajo-afectivo/lib/stats/ticket_escalation.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

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::TicketEscalation
def self.generate(user)
open_state_ids = Ticket::State.by_category(:open).pluck(:id)
2015-09-06 23:17:54 +00:00
2015-09-06 22:42:11 +00:00
# get users groups
group_ids = user.group_ids_access('full')
2015-09-06 22:42:11 +00:00
# owned tickets
own_escalated = Ticket.where(
'owner_id = ? AND group_id IN (?) AND state_id IN (?) AND escalation_at < ?', user.id, group_ids, open_state_ids, Time.zone.now
2015-09-06 22:42:11 +00:00
).count
# all tickets
all_escalated = Ticket.where(
'group_id IN (?) AND state_id IN (?) AND escalation_at < ?', group_ids, open_state_ids, Time.zone.now
2015-09-06 22:42:11 +00:00
).count
average = '-'
state = if own_escalated.zero?
'supergood'
elsif own_escalated <= 1
'good'
elsif own_escalated <= 4
'ok'
else
'bad'
end
2015-09-06 22:42:11 +00:00
{
used_for_average: own_escalated,
average_per_agent: average,
state: state,
own: own_escalated,
total: all_escalated,
2015-09-06 22:42:11 +00:00
}
end
def self.average_state(result, _user_id)
result
end
2015-09-06 22:42:11 +00:00
end