trabajo-afectivo/lib/report/ticket_reopened.rb

131 lines
3.4 KiB
Ruby
Raw Normal View History

2015-10-29 02:33:36 +00:00
class Report::TicketReopened < Report::Base
=begin
result = Report::TicketReopened.aggs(
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
timezone: 'Europe/Berlin',
2015-10-29 02:33:36 +00:00
)
returns
[4,5,1,5,0,51,5,56,7,4]
=end
def self.aggs(params_origin)
params = params_origin.dup
2015-10-29 02:33:36 +00:00
ticket_state_ids = ticket_ids
result = []
case params[:interval]
when 'month'
2015-10-29 02:33:36 +00:00
stop_interval = 12
when 'week'
2015-10-29 02:33:36 +00:00
stop_interval = 7
when 'day'
2015-10-29 02:33:36 +00:00
stop_interval = 31
when 'hour'
2015-10-29 02:33:36 +00:00
stop_interval = 24
when 'minute'
2015-10-29 02:33:36 +00:00
stop_interval = 60
end
(1..stop_interval).each do |_counter|
case params[:interval]
when 'month'
params[:range_end] = params[:range_start].next_month
when 'week'
params[:range_end] = params[:range_start].next_day
when 'day'
params[:range_end] = params[:range_start].next_day
when 'hour'
params[:range_end] = params[:range_start] + 1.hour
when 'minute'
params[:range_end] = params[:range_start] + 1.minute
2015-10-29 02:33:36 +00:00
end
without_merged_tickets = {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged'
}
}
params[:selector].merge!(without_merged_tickets) # do not show merged tickets in reports
2015-10-29 02:33:36 +00:00
count = history_count(
object: 'Ticket',
type: 'updated',
2015-10-29 02:33:36 +00:00
attribute: 'state',
id_from: ticket_state_ids,
2015-10-29 02:33:36 +00:00
id_not_to: ticket_state_ids,
start: params[:range_start],
end: params[:range_end],
selector: params[:selector]
2015-10-29 02:33:36 +00:00
)
result.push count
params[:range_start] = params[:range_end]
end
2015-10-29 02:33:36 +00:00
result
end
=begin
result = Report::TicketReopened.items(
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
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)
ticket_state_ids = ticket_ids
result = history(
object: 'Ticket',
type: 'updated',
2015-10-29 02:33:36 +00:00
attribute: 'state',
id_from: ticket_state_ids,
2015-10-29 02:33:36 +00:00
id_not_to: ticket_state_ids,
start: params[:range_start],
end: params[:range_end],
selector: params[:selector]
2015-10-29 02:33:36 +00:00
)
return result if params[:sheet].present?
2015-10-29 02:33:36 +00:00
assets = {}
result[:ticket_ids].each do |ticket_id|
2015-10-29 02:33:36 +00:00
ticket_full = Ticket.find(ticket_id)
assets = ticket_full.assets(assets)
end
2015-10-29 02:33:36 +00:00
result[:assets] = assets
result
end
def self.ticket_ids
key = 'Report::TicketReopened::StateList'
ticket_state_ids = Cache.get(key)
2015-10-29 02:33:36 +00:00
return ticket_state_ids if ticket_state_ids
ticket_state_types = Ticket::StateType.where(name: %w[closed merged removed])
2015-10-29 02:33:36 +00:00
ticket_state_ids = []
ticket_state_types.each do |ticket_state_type|
ticket_state_type.states.each do |ticket_state|
2015-10-29 02:33:36 +00:00
ticket_state_ids.push ticket_state.id
end
end
Cache.write(key, ticket_state_ids, { expires_in: 2.days })
2015-10-29 02:33:36 +00:00
ticket_state_ids
end
end