Added reopen dashboard stats.

This commit is contained in:
Martin Edenhofer 2015-09-09 08:49:08 +02:00
parent b921b8782a
commit b170312d8e
4 changed files with 53 additions and 13 deletions

View file

@ -0,0 +1,22 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
require 'stats/ticket_reopen'
class Observer::Ticket::StatsReopen < ActiveRecord::Observer
observe 'ticket'
def after_create(record)
_check(record)
end
def after_update(record)
_check(record)
end
private
def _check(record)
# return if we run import mode
return if Setting.get('import_mode')
Stats::TicketReopen.log('Ticket', record.id, record.changes, record.updated_by_id)
end
end

View file

@ -23,7 +23,7 @@ class StatsStore < ApplicationModel
end
StatsStore.where(stats_store_object_id: object_id, o_id: data[:o_id], key: data[:key])
.where('created_at < ? AND created_at > ?', data[:start], data[:end]).count
.where('created_at > ? AND created_at < ?', data[:start], data[:end]).count
end
=begin

View file

@ -39,6 +39,7 @@ module Zammad
'observer::_ticket::_escalation_calculation',
'observer::_ticket::_ref_object_touch',
'observer::_ticket::_online_notification_seen',
'observer::_ticket::_stats_reopen',
'observer::_tag::_ticket_history',
'observer::_user::_ref_object_touch',
'observer::_user::_ticket_organization',

View file

@ -3,6 +3,14 @@
class Stats::TicketReopen
def self.generate(user)
# get my closed tickets
total = Ticket.select('id').where(
'owner_id = ? AND close_time > ?',
user.id, Time.zone.now - 7.days
).count
# get count of repoens
count = StatsStore.count_by_search(
object: 'User',
o_id: user.id,
@ -10,14 +18,22 @@ class Stats::TicketReopen
start: Time.zone.now - 7.days,
end: Time.zone.now,
)
if count > total
total = count
end
reopen_in_precent = 0
if total != 0
reopen_in_precent = ( count.to_f / (total.to_f / 100) ).round(3)
end
{
used_for_average: 0,
used_for_average: reopen_in_precent,
percent: reopen_in_precent,
average_per_agent: '-',
state: 'good',
own: count,
total: 0,
percent: 0,
its_me: true,
count: count,
total: total,
}
end
@ -25,24 +41,25 @@ class Stats::TicketReopen
return result if !result.key?(:used_for_average)
if result[:total] < 1
if result[:total] < 1 || result[:average_per_agent] == 0.0
result[:state] = 'supergood'
return result
end
in_percent = ( result[:used_for_average].to_f / (result[:total].to_f/100) ).round(1)
#in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
#result[:average_per_agent_in_percent] = in_percent
in_percent = ( result[:count].to_f / (result[:total].to_f / 100) ).round(1)
if in_percent >= 90
result[:state] = 'supergood'
result[:state] = 'superbad'
elsif in_percent >= 65
result[:state] = 'good'
result[:state] = 'bad'
elsif in_percent >= 40
result[:state] = 'ok'
elsif in_percent >= 20
result[:state] = 'bad'
result[:state] = 'good'
else
result[:state] = 'superbad'
result[:state] = 'supergood'
end
result
end