ticket_escalation.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Stats::TicketEscalation
  3. def self.generate(user)
  4. open_state_ids = Ticket::State.by_category_ids(:open)
  5. # get users groups
  6. group_ids = user.group_ids_access('full')
  7. # owned tickets
  8. own_escalated = Ticket.where(
  9. 'owner_id = ? AND group_id IN (?) AND state_id IN (?) AND escalation_at < ?', user.id, group_ids, open_state_ids, Time.zone.now
  10. ).count
  11. # all tickets
  12. all_escalated = Ticket.where(
  13. 'group_id IN (?) AND state_id IN (?) AND escalation_at < ?', group_ids, open_state_ids, Time.zone.now
  14. ).count
  15. average = '-'
  16. state = if own_escalated.zero?
  17. 'supergood'
  18. elsif own_escalated <= 1
  19. 'good'
  20. elsif own_escalated <= 4
  21. 'ok'
  22. else
  23. 'bad'
  24. end
  25. {
  26. used_for_average: own_escalated,
  27. average_per_agent: average,
  28. state: state,
  29. own: own_escalated,
  30. total: all_escalated,
  31. }
  32. end
  33. def self.average_state(result, _user_id)
  34. result
  35. end
  36. end