From ab4d98aacb43740c35f8db76eb260c4a002c7a41 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 7 Sep 2015 01:17:54 +0200 Subject: [PATCH] Small bugfixes. --- lib/stats/ticket_escalation.rb | 12 ++++-------- lib/stats/ticket_in_process.rb | 4 +++- lib/stats/ticket_load_measure.rb | 11 ++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/stats/ticket_escalation.rb b/lib/stats/ticket_escalation.rb index 77a633df0..a945d7104 100644 --- a/lib/stats/ticket_escalation.rb +++ b/lib/stats/ticket_escalation.rb @@ -4,23 +4,19 @@ class Stats::TicketEscalation def self.generate(user) + open_state_ids = Ticket::State.by_category('open').map(&:id) + # get users groups group_ids = user.groups.map(&:id) # owned tickets own_escalated = Ticket.where( - owner_id: user.id, - group_id: group_ids, - escalation_time: Time.zone.now, - state_id: Ticket::State.by_category('open').map(&:id) + 'owner_id = ? AND group_id IN (?) AND state_id IN (?) AND escalation_time < ?', user.id, group_ids, open_state_ids, Time.zone.now ).count # all tickets all_escalated = Ticket.where( - owner_id: user.id, - group_id: group_ids, - escalation_time: Time.zone.now, - state_id: Ticket::State.by_category('open').map(&:id) + 'group_id IN (?) AND state_id IN (?) AND escalation_time < ?', group_ids, open_state_ids, Time.zone.now ).count average = '-' diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index ad9348a01..1983f6a13 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -4,10 +4,12 @@ class Stats::TicketInProcess def self.generate(user) + open_state_ids = Ticket::State.by_category('open').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).map(&:id) + own_ticket_ids = Ticket.select('id').where(owner_id: user.id, state_id: open_state_ids).map(&:id) 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 diff --git a/lib/stats/ticket_load_measure.rb b/lib/stats/ticket_load_measure.rb index c26a9bac8..a70d0e139 100644 --- a/lib/stats/ticket_load_measure.rb +++ b/lib/stats/ticket_load_measure.rb @@ -4,14 +4,17 @@ class Stats::TicketLoadMeasure def self.generate(user) + open_state_ids = Ticket::State.by_category('open').map(&:id) + # owned tickets - count = Ticket.where(owner_id: user.id).count + count = Ticket.where(owner_id: user.id, state_id: open_state_ids).count # get total open - total = Ticket.where(group_id: user.groups.map(&:id), state_id: Ticket::State.by_category('open').map(&:id) ).count + total = Ticket.where(group_id: user.groups.map(&:id), state_id: open_state_ids).count average = '-' state = 'good' + load_measure_precent = 0 # if in_process_precent > 80 # state = 'supergood' # elsif in_process_precent > 60 @@ -27,8 +30,10 @@ class Stats::TicketLoadMeasure if count > total total = count end - load_measure_precent = (count * 1000) / ((total * 1000) / 100) + if count != 0 && total != 0 + load_measure_precent = (count * 1000) / ((total * 1000) / 100) + end { average: average, percent: load_measure_precent,