ticket_load_measure.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Stats::TicketLoadMeasure
  3. def self.generate(user)
  4. open_state_ids = Ticket::State.by_category(:open).pluck(:id)
  5. # owned tickets
  6. count = Ticket.where(owner_id: user.id, state_id: open_state_ids).count
  7. # get total open
  8. total = Ticket.where(group_id: user.group_ids_access('full'), state_id: open_state_ids).count
  9. average = '-'
  10. state = 'good'
  11. load_measure_precent = 0
  12. if count > total
  13. total = count
  14. end
  15. if total.nonzero?
  16. load_measure_precent = ( count.to_f / (total.to_f / 100) ).round(1)
  17. end
  18. {
  19. used_for_average: load_measure_precent,
  20. average_per_agent: average,
  21. percent: load_measure_precent,
  22. state: state,
  23. own: count,
  24. total: total,
  25. }
  26. end
  27. def self.average_state(result, _user_id)
  28. return result if !result.key?(:used_for_average)
  29. if result[:total] < 1 || result[:average_per_agent] == 0.0
  30. result[:state] = 'supergood'
  31. return result
  32. end
  33. in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
  34. result[:average_per_agent_in_percent] = in_percent
  35. result[:state] = if in_percent >= 90
  36. 'supergood'
  37. elsif in_percent >= 65
  38. 'good'
  39. elsif in_percent >= 40
  40. 'ok'
  41. elsif in_percent >= 20
  42. 'bad'
  43. else
  44. 'superbad'
  45. end
  46. # convert result[:used_for_average] in percent to related total
  47. result[:average_per_agent] = ( (result[:total].to_f / 100) * result[:average_per_agent] ).round(1)
  48. result
  49. end
  50. end