From 18893526d99eeec648a42631a53d906f4a8f9f77 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 7 Sep 2015 01:52:54 +0200 Subject: [PATCH] Small improvements. --- lib/stats.rb | 1 + lib/stats/ticket_escalation.rb | 22 +++++++++++----------- lib/stats/ticket_in_process.rb | 10 ++++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/stats.rb b/lib/stats.rb index 72221517c..b1a64ab7b 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -28,6 +28,7 @@ returns users = User.of_role('Agent') users.each {|user| + next if user.id == 1 data = {} backends.each {|backend| data[backend.to_app_model] = backend.generate(user) diff --git a/lib/stats/ticket_escalation.rb b/lib/stats/ticket_escalation.rb index a945d7104..e50ae0b21 100644 --- a/lib/stats/ticket_escalation.rb +++ b/lib/stats/ticket_escalation.rb @@ -21,17 +21,17 @@ class Stats::TicketEscalation average = '-' state = 'supergood' - # if in_process_precent > 80 - # state = 'supergood' - # elsif in_process_precent > 60 - # state = 'good' - # elsif in_process_precent > 40 - # state = 'ok' - # elsif in_process_precent > 20 - # state = 'bad' - # elsif in_process_precent > 5 - # state = 'superbad' - # end + if own_escalated == 0 + state = 'supergood' + elsif own_escalated > 1 + state = 'good' + elsif own_escalated > 2 + state = 'ok' + elsif own_escalated > 5 + state = 'bad' + elsif own_escalated > 10 + state = 'superbad' + end { average: average, diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index 1983f6a13..bd383dabc 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -4,13 +4,19 @@ class Stats::TicketInProcess def self.generate(user) - open_state_ids = Ticket::State.by_category('open').map(&:id) + open_state_ids = Ticket::State.by_category('work_on').map(&:id) + pending_state_ids = Ticket::State.by_category('pending_reminder').map(&:id) # get history entries of tickets worked on today history_object = History::Object.lookup(name: 'Ticket') - own_ticket_ids = Ticket.select('id').where(owner_id: user.id, state_id: open_state_ids).map(&:id) + # get own tickets which are "workable" + own_ticket_ids = Ticket.select('id').where( + 'owner_id = ? AND (state_id IN (?) OR (state_id IN (?) AND pending_time < ?))', + user.id, open_state_ids, pending_state_ids, Time.zone.now + ).limit(1000).map(&:id) + # 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 ).count