From e7d9bf53f83bfe8e9ec9de598601d6ffad27b457 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 8 Sep 2015 12:59:46 +0200 Subject: [PATCH] Some dashboard calculation improvements. --- lib/stats.rb | 23 ++++++++------ lib/stats/ticket_channel_distribution.rb | 4 +++ lib/stats/ticket_escalation.rb | 4 +++ lib/stats/ticket_in_process.rb | 37 ++++++++++++++-------- lib/stats/ticket_load_measure.rb | 39 ++++++++++++++++-------- lib/stats/ticket_reopen.rb | 28 ++++++++++++++++- lib/stats/ticket_response_time.rb | 25 +++++++++++++++ 7 files changed, 126 insertions(+), 34 deletions(-) diff --git a/lib/stats.rb b/lib/stats.rb index ac5dddd99..5b659068a 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -36,7 +36,7 @@ returns agent_count += 1 data = {} backends.each {|backend| - data[backend.to_app_model] = backend.generate(user) + data[backend] = backend.generate(user) } user_result[user.id] = data } @@ -53,24 +53,29 @@ returns } } - # generate average stats + # generate average param and icon state backend_average_sum.each {|backend_model_average, result| average = ( result.to_f / agent_count.to_f ).round(1) - user_result.each {|_user_id, data| - data.each {|backend_model_data, backend_result| - next if backend_model_data != backend_model_average - next if !backend_result.key?(:used_for_average) - backend_result[:average_per_agent] = average - } + user_result.each {|user_id, data| + next if !data[backend_model_average] + next if !data[backend_model_average].key?(:used_for_average) + data[backend_model_average][:average_per_agent] = average + + # generate icon state + backend_model_average.to_s.constantize.average_state(data[backend_model_average], user_id) } } user_result.each {|user_id, data| + data_for_user = {} + data.each {|backend, result| + data_for_user[backend.to_app_model] = result + } StatsStore.sync( object: 'User', o_id: user_id, key: 'dashboard', - data: data, + data: data_for_user, ) } diff --git a/lib/stats/ticket_channel_distribution.rb b/lib/stats/ticket_channel_distribution.rb index 8f6b2ebcd..ebc58e868 100644 --- a/lib/stats/ticket_channel_distribution.rb +++ b/lib/stats/ticket_channel_distribution.rb @@ -86,4 +86,8 @@ class Stats::TicketChannelDistribution { channels: result } end + def self.average_state(result, _user_id) + result + end + end diff --git a/lib/stats/ticket_escalation.rb b/lib/stats/ticket_escalation.rb index 3b59f9274..81cbaa5f0 100644 --- a/lib/stats/ticket_escalation.rb +++ b/lib/stats/ticket_escalation.rb @@ -40,4 +40,8 @@ class Stats::TicketEscalation } end + def self.average_state(result, _user_id) + result + end + end diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index a17270b11..97ede41d7 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -43,18 +43,7 @@ class Stats::TicketInProcess average_in_percent = '-' if total != 0 - in_process_precent = (count * 1000) / ((total * 1000) / 100) - if in_process_precent >= 75 - state = 'supergood' - elsif in_process_precent >= 55 - state = 'good' - elsif in_process_precent >= 40 - state = 'ok' - elsif in_process_precent >= 20 - state = 'bad' - else - state = 'superbad' - end + in_process_precent = ( count.to_f / (total.to_f/100) ).round(1) end { @@ -67,4 +56,28 @@ class Stats::TicketInProcess } end + def self.average_state(result, _user_id) + + return result if !result.key?(:used_for_average) + + if result[:total] < 1 + result[:state] = 'supergood' + return result + end + + in_percent = ( result[:used_for_average].to_f / (result[:total].to_f/100) ).round(1) + if in_percent >= 90 + result[:state] = 'supergood' + elsif in_percent >= 65 + result[:state] = 'good' + elsif in_percent >= 40 + result[:state] = 'ok' + elsif in_percent >= 20 + result[:state] = 'bad' + else + result[:state] = 'superbad' + end + + result + end end diff --git a/lib/stats/ticket_load_measure.rb b/lib/stats/ticket_load_measure.rb index 87b642cbd..5b53f42b4 100644 --- a/lib/stats/ticket_load_measure.rb +++ b/lib/stats/ticket_load_measure.rb @@ -15,24 +15,13 @@ class Stats::TicketLoadMeasure average = '-' state = 'good' load_measure_precent = 0 - # 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 count > total total = count end if total != 0 - load_measure_precent = (count * 1000) / ((total * 1000) / 100) + load_measure_precent = ( count.to_f / (total.to_f/100) ).round(1) end { used_for_average: load_measure_precent, @@ -44,4 +33,30 @@ class Stats::TicketLoadMeasure } end + def self.average_state(result, _user_id) + + return result if !result.key?(:used_for_average) + + if result[:total] < 1 + result[:state] = 'supergood' + return result + end + + 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 + if in_percent >= 90 + result[:state] = 'supergood' + elsif in_percent >= 65 + result[:state] = 'good' + elsif in_percent >= 40 + result[:state] = 'ok' + elsif in_percent >= 20 + result[:state] = 'bad' + else + result[:state] = 'superbad' + end + + result + end + end diff --git a/lib/stats/ticket_reopen.rb b/lib/stats/ticket_reopen.rb index 6f0f11c72..a75e16b96 100644 --- a/lib/stats/ticket_reopen.rb +++ b/lib/stats/ticket_reopen.rb @@ -12,14 +12,40 @@ class Stats::TicketReopen ) { used_for_average: 0, - average_per_agent: '', + average_per_agent: '-', state: 'good', own: count, total: 0, percent: 0, + its_me: true, } end + def self.average_state(result, _user_id) + + return result if !result.key?(:used_for_average) + + if result[:total] < 1 + result[:state] = 'supergood' + return result + end + + in_percent = ( result[:used_for_average].to_f / (result[:total].to_f/100) ).round(1) + if in_percent >= 90 + result[:state] = 'supergood' + elsif in_percent >= 65 + result[:state] = 'good' + elsif in_percent >= 40 + result[:state] = 'ok' + elsif in_percent >= 20 + result[:state] = 'bad' + else + result[:state] = 'superbad' + end + + result + end + def self.log(object, o_id, changes, updated_by_id) return if object != 'Ticket' ticket = Ticket.lookup(id: o_id) diff --git a/lib/stats/ticket_response_time.rb b/lib/stats/ticket_response_time.rb index aae573f81..df56573ea 100644 --- a/lib/stats/ticket_response_time.rb +++ b/lib/stats/ticket_response_time.rb @@ -46,4 +46,29 @@ class Stats::TicketResponseTime } end + def self.average_state(result, _user_id) + + return result if !result.key?(:used_for_average) + + if result[:total] < 1 + result[:state] = 'supergood' + return result + end + + in_percent = ( result[:used_for_average].to_f / (result[:total].to_f/100) ).round(1) + if in_percent >= 90 + result[:state] = 'supergood' + elsif in_percent >= 65 + result[:state] = 'good' + elsif in_percent >= 40 + result[:state] = 'ok' + elsif in_percent >= 20 + result[:state] = 'bad' + else + result[:state] = 'superbad' + end + + result + end + end