From 27472e387722d740d2e331abcc38328b342ec877 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 8 Sep 2015 09:45:56 +0200 Subject: [PATCH] Also count closed and pending action tickets. --- lib/stats/ticket_in_process.rb | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index 481b80f98..aaa7ecb96 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -16,25 +16,41 @@ class Stats::TicketInProcess user.id, open_state_ids, pending_state_ids, Time.zone.now ).limit(1000).map(&:id) + # get all tickets where I worked on today (owner & closed today) + closed_state_ids = Ticket::State.by_category('closed').map(&:id) + closed_ticket_ids = Ticket.select('id').where( + 'owner_id = ? AND state_id IN (?) AND close_time > ?', + user.id, closed_state_ids, Time.zone.now-1.day + ).limit(100).map(&:id) + + # get all tickets which I changed to pending action + pending_action_state_ids = Ticket::State.by_category('pending_action').map(&:id) + pending_action_ticket_ids = Ticket.select('id').where( + 'owner_id = ? AND state_id IN (?) AND updated_at > ?', + user.id, pending_action_state_ids, Time.zone.now-1.day + ).limit(100).map(&:id) + + all_ticket_ids = own_ticket_ids.concat(closed_ticket_ids).concat(pending_action_ticket_ids).uniq + # get count where user worked on count = History.select('DISTINCT(o_id)').where( - 'histories.created_at >= ? AND histories.history_object_id = ? AND histories.created_by_id = ? AND histories.o_id IN (?)', Time.zone.now - 1.day, history_object.id, user.id, own_ticket_ids + 'histories.created_at >= ? AND histories.history_object_id = ? AND histories.created_by_id = ? AND histories.o_id IN (?)', Time.zone.now - 1.day, history_object.id, user.id, all_ticket_ids ).count - total = own_ticket_ids.count + total = all_ticket_ids.count in_process_precent = 0 state = 'supergood' average_in_percent = '-' if total != 0 in_process_precent = (count * 1000) / ((total * 1000) / 100) - if in_process_precent > 80 + if in_process_precent >= 75 state = 'supergood' - elsif in_process_precent > 60 + elsif in_process_precent >= 55 state = 'good' - elsif in_process_precent > 40 + elsif in_process_precent >= 40 state = 'ok' - elsif in_process_precent > 20 + elsif in_process_precent >= 20 state = 'bad' else state = 'superbad'