trabajo-afectivo/lib/stats/ticket_load_measure.rb

66 lines
1.6 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::TicketLoadMeasure
def self.generate(user)
2015-09-09 06:08:28 +00:00
open_state_ids = Ticket::State.by_category('open').map(&: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
2015-09-06 23:17:54 +00:00
total = Ticket.where(group_id: user.groups.map(&:id), 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
if total != 0
2015-09-08 14:03:11 +00:00
load_measure_precent = ( count.to_f / (total.to_f / 100) ).round(3)
2015-09-06 23:17:54 +00:00
end
2015-09-06 22:42:11 +00:00
{
used_for_average: load_measure_precent,
average_per_agent: average,
2015-09-06 22:42:11 +00:00
percent: load_measure_precent,
state: state,
own: count,
total: total,
}
end
def self.average_state(result, _user_id)
return result if !result.key?(:used_for_average)
2015-09-09 12:31:31 +00:00
if result[:total] < 1 || result[:average_per_agent] == 0.0
result[:state] = 'supergood'
return result
end
2015-09-08 14:03:11 +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
if in_percent >= 90
result[:state] = 'supergood'
elsif in_percent >= 65
result[:state] = 'good'
elsif in_percent >= 40
result[:state] = 'ok'
elsif in_percent >= 20
result[:state] = 'bad'
else
result[:state] = 'superbad'
end
# convert result[:used_for_average] in percent to related total
2015-09-08 14:03:11 +00:00
result[:average_per_agent] = ( (result[:total].to_f / 100) * result[:average_per_agent] ).round(1)
result
end
2015-09-06 22:42:11 +00:00
end