2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-10-29 02:33:36 +00:00
|
|
|
class Report::TicketFirstSolution
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = Report::TicketFirstSolution.aggs(
|
2019-03-26 00:17:17 +00:00
|
|
|
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
|
|
|
|
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
|
2015-10-29 02:33:36 +00:00
|
|
|
interval: 'month', # quarter, month, week, day, hour, minute, second
|
|
|
|
selector: selector, # ticket selector to get only a collection of tickets
|
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
[4,5,1,5,0,51,5,56,7,4]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
def self.aggs(params_origin)
|
|
|
|
params = params_origin.dup
|
2015-10-29 02:33:36 +00:00
|
|
|
|
|
|
|
result = []
|
2020-07-13 12:46:08 +00:00
|
|
|
case params[:interval]
|
|
|
|
when 'month'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 12
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'week'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 7
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'day'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 31
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'hour'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 24
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'minute'
|
2015-10-29 02:33:36 +00:00
|
|
|
stop_interval = 60
|
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
(1..stop_interval).each do |_counter|
|
2020-07-13 12:46:08 +00:00
|
|
|
case params[:interval]
|
|
|
|
when 'month'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start].next_month
|
2020-11-12 11:42:44 +00:00
|
|
|
when 'week', 'day'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start].next_day
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'hour'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start] + 1.hour
|
2020-07-13 12:46:08 +00:00
|
|
|
when 'minute'
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_end] = params[:range_start] + 1.minute
|
2015-10-29 02:33:36 +00:00
|
|
|
end
|
2018-02-07 09:15:00 +00:00
|
|
|
|
|
|
|
without_merged_tickets = {
|
|
|
|
'ticket_state.name' => {
|
|
|
|
'operator' => 'is not',
|
|
|
|
'value' => 'merged'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params[:selector].merge!(without_merged_tickets)
|
2015-10-29 02:33:36 +00:00
|
|
|
query, bind_params, tables = Ticket.selector2sql(params[:selector])
|
2016-09-14 07:15:30 +00:00
|
|
|
ticket_list = Ticket.select('tickets.id, tickets.close_at, tickets.created_at').where(
|
|
|
|
'tickets.close_at IS NOT NULL AND tickets.close_at >= ? AND tickets.close_at < ?',
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_start],
|
|
|
|
params[:range_end],
|
2015-10-29 02:33:36 +00:00
|
|
|
).where(query, *bind_params).joins(tables)
|
|
|
|
count = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
ticket_list.each do |ticket|
|
2016-09-14 07:15:30 +00:00
|
|
|
closed_at = ticket.close_at
|
2015-10-29 02:33:36 +00:00
|
|
|
created_at = ticket.created_at
|
2021-07-16 13:38:01 +00:00
|
|
|
if (closed_at - (60 * 15)) < created_at
|
2015-10-29 02:33:36 +00:00
|
|
|
count += 1
|
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-10-29 02:33:36 +00:00
|
|
|
result.push count
|
2019-03-26 00:17:17 +00:00
|
|
|
params[:range_start] = params[:range_end]
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-10-29 02:33:36 +00:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
result = Report::TicketFirstSolution.items(
|
2019-03-26 00:17:17 +00:00
|
|
|
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
|
|
|
|
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
|
2015-10-29 02:33:36 +00:00
|
|
|
selector: selector, # ticket selector to get only a collection of tickets
|
2019-03-26 00:17:17 +00:00
|
|
|
timezone: 'Europe/Berlin',
|
2015-10-29 02:33:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
count: 123,
|
|
|
|
ticket_ids: [4,5,1,5,0,51,5,56,7,4],
|
|
|
|
assets: assets,
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.items(params)
|
2018-02-07 09:15:00 +00:00
|
|
|
without_merged_tickets = {
|
|
|
|
'ticket_state.name' => {
|
|
|
|
'operator' => 'is not',
|
|
|
|
'value' => 'merged'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selector = params[:selector].merge!(without_merged_tickets)
|
|
|
|
query, bind_params, tables = Ticket.selector2sql(selector)
|
2016-09-14 07:15:30 +00:00
|
|
|
ticket_list = Ticket.select('tickets.id, tickets.close_at, tickets.created_at').where(
|
|
|
|
'tickets.close_at IS NOT NULL AND tickets.close_at >= ? AND tickets.close_at < ?',
|
2015-10-29 02:33:36 +00:00
|
|
|
params[:range_start],
|
|
|
|
params[:range_end],
|
2016-12-16 12:27:16 +00:00
|
|
|
).where(query, *bind_params).joins(tables).order(close_at: :asc)
|
2015-10-29 02:33:36 +00:00
|
|
|
count = 0
|
|
|
|
assets = {}
|
|
|
|
ticket_ids = []
|
2017-10-01 12:25:52 +00:00
|
|
|
ticket_list.each do |ticket|
|
2016-09-14 07:15:30 +00:00
|
|
|
closed_at = ticket.close_at
|
2015-10-29 02:33:36 +00:00
|
|
|
created_at = ticket.created_at
|
2021-07-16 13:38:01 +00:00
|
|
|
if (closed_at - (60 * 15)) < created_at
|
2015-10-29 02:33:36 +00:00
|
|
|
count += 1
|
|
|
|
ticket_ids.push ticket.id
|
|
|
|
end
|
|
|
|
ticket_full = Ticket.find(ticket.id)
|
|
|
|
assets = ticket_full.assets(assets)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-10-29 02:33:36 +00:00
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
count: count,
|
2015-10-29 02:33:36 +00:00
|
|
|
ticket_ids: ticket_ids,
|
2018-12-19 17:31:51 +00:00
|
|
|
assets: assets,
|
2015-10-29 02:33:36 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|