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::TicketLoadMeasure
|
|
|
|
|
|
|
|
def self.generate(user)
|
|
|
|
|
2017-03-27 14:06:18 +00:00
|
|
|
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
|
|
|
# owned tickets
|
2015-09-06 23:17:54 +00:00
|
|
|
count = Ticket.where(owner_id: user.id, state_id: open_state_ids).count
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
# get total open
|
2017-06-16 20:43:09 +00:00
|
|
|
total = Ticket.where(group_id: user.group_ids_access('full'), state_id: open_state_ids).count
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
average = '-'
|
|
|
|
state = 'good'
|
2015-09-06 23:17:54 +00:00
|
|
|
load_measure_precent = 0
|
2015-09-06 22:42:11 +00:00
|
|
|
|
|
|
|
if count > total
|
|
|
|
total = count
|
|
|
|
end
|
|
|
|
|
2016-07-26 22:02:28 +00:00
|
|
|
if total.nonzero?
|
2021-07-16 13:38:01 +00:00
|
|
|
load_measure_precent = (count.to_f / (total.to_f / 100)).round(1)
|
2015-09-06 23:17:54 +00:00
|
|
|
end
|
2015-09-06 22:42:11 +00:00
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
used_for_average: load_measure_precent,
|
2015-09-08 06:55:09 +00:00
|
|
|
average_per_agent: average,
|
2018-12-19 17:31:51 +00:00
|
|
|
percent: load_measure_precent,
|
|
|
|
state: state,
|
|
|
|
own: 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:38:01 +00:00
|
|
|
in_percent = (result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100)).round(1)
|
2015-09-08 10:59:46 +00:00
|
|
|
result[:average_per_agent_in_percent] = in_percent
|
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
|
|
|
|
2015-09-08 13:10:29 +00:00
|
|
|
# convert result[:used_for_average] in percent to related total
|
2021-07-16 13:38:01 +00:00
|
|
|
result[:average_per_agent] = ((result[:total].to_f / 100) * result[:average_per_agent]).round(1)
|
2015-09-08 13:10:29 +00:00
|
|
|
|
2015-09-08 10:59:46 +00:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2015-09-06 22:42:11 +00:00
|
|
|
end
|