ticket_first_solution.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Report::TicketFirstSolution
  3. =begin
  4. result = Report::TicketFirstSolution.aggs(
  5. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  6. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  7. interval: 'month', # quarter, month, week, day, hour, minute, second
  8. selector: selector, # ticket selector to get only a collection of tickets
  9. )
  10. returns
  11. [4,5,1,5,0,51,5,56,7,4]
  12. =end
  13. def self.aggs(params_origin)
  14. params = params_origin.deep_dup
  15. result = []
  16. case params[:interval]
  17. when 'month'
  18. stop_interval = 12
  19. when 'week'
  20. stop_interval = 7
  21. when 'day'
  22. stop_interval = 31
  23. when 'hour'
  24. stop_interval = 24
  25. when 'minute'
  26. stop_interval = 60
  27. end
  28. (1..stop_interval).each do |_counter|
  29. case params[:interval]
  30. when 'month'
  31. params[:range_end] = params[:range_start].next_month
  32. when 'week', 'day'
  33. params[:range_end] = params[:range_start].next_day
  34. when 'hour'
  35. params[:range_end] = params[:range_start] + 1.hour
  36. when 'minute'
  37. params[:range_end] = params[:range_start] + 1.minute
  38. end
  39. query, bind_params, tables = Ticket.selector2sql(params[:selector], { exclude_merged: true })
  40. ticket_list = Ticket.select('tickets.id, tickets.close_at, tickets.created_at').where(
  41. 'tickets.close_at IS NOT NULL AND tickets.close_at >= ? AND tickets.close_at < ?',
  42. params[:range_start],
  43. params[:range_end],
  44. ).where(query, *bind_params).joins(tables)
  45. count = 0
  46. ticket_list.each do |ticket|
  47. closed_at = ticket.close_at
  48. created_at = ticket.created_at
  49. if (closed_at - (60 * 15)) < created_at
  50. count += 1
  51. end
  52. end
  53. result.push count
  54. params[:range_start] = params[:range_end]
  55. end
  56. result
  57. end
  58. =begin
  59. result = Report::TicketFirstSolution.items(
  60. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  61. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  62. selector: selector, # ticket selector to get only a collection of tickets
  63. timezone: 'Europe/Berlin',
  64. )
  65. returns
  66. {
  67. count: 123,
  68. ticket_ids: [4,5,1,5,0,51,5,56,7,4],
  69. assets: assets,
  70. }
  71. =end
  72. def self.items(params)
  73. query, bind_params, tables = Ticket.selector2sql(params[:selector], { exclude_merged: true })
  74. ticket_list = Ticket.select('tickets.id, tickets.close_at, tickets.created_at').where(
  75. 'tickets.close_at IS NOT NULL AND tickets.close_at >= ? AND tickets.close_at < ?',
  76. params[:range_start],
  77. params[:range_end],
  78. ).where(query, *bind_params).joins(tables).reorder(close_at: :asc)
  79. count = 0
  80. assets = {}
  81. ticket_ids = []
  82. ticket_list.each do |ticket|
  83. closed_at = ticket.close_at
  84. created_at = ticket.created_at
  85. if (closed_at - (60 * 15)) < created_at
  86. count += 1
  87. ticket_ids.push ticket.id
  88. end
  89. ticket_full = Ticket.find(ticket.id)
  90. assets = ticket_full.assets(assets)
  91. end
  92. {
  93. count: count,
  94. ticket_ids: ticket_ids,
  95. assets: assets,
  96. }
  97. end
  98. end