trabajo-afectivo/lib/stats/ticket_escalation.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

2015-09-06 22:42:11 +00:00
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
class Stats::TicketEscalation
def self.generate(user)
2015-09-06 23:17:54 +00:00
open_state_ids = Ticket::State.by_category('open').map(&:id)
2015-09-06 22:42:11 +00:00
# get users groups
group_ids = user.groups.map(&:id)
# owned tickets
own_escalated = Ticket.where(
2015-09-06 23:17:54 +00:00
'owner_id = ? AND group_id IN (?) AND state_id IN (?) AND escalation_time < ?', 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(
2015-09-06 23:17:54 +00:00
'group_id IN (?) AND state_id IN (?) AND escalation_time < ?', group_ids, open_state_ids, Time.zone.now
2015-09-06 22:42:11 +00:00
).count
average = '-'
state = 'supergood'
2015-09-06 23:52:54 +00:00
if own_escalated == 0
state = 'supergood'
2015-09-07 00:19:32 +00:00
elsif own_escalated <= 1
2015-09-06 23:52:54 +00:00
state = 'good'
2015-09-07 00:19:32 +00:00
elsif own_escalated <= 4
2015-09-06 23:52:54 +00:00
state = 'ok'
2015-09-07 00:08:15 +00:00
else
2015-09-07 00:19:32 +00:00
state = 'bad'
2015-09-06 23:52:54 +00:00
end
2015-09-06 22:42:11 +00:00
{
used_for_average: own_escalated,
average_per_agent: average,
2015-09-07 00:08:15 +00:00
state: state,
2015-09-06 22:42:11 +00:00
own: own_escalated,
total: all_escalated,
}
end
def self.average_state(result, _user_id)
result
end
2015-09-06 22:42:11 +00:00
end