Some dashboard calculation improvements.

This commit is contained in:
Martin Edenhofer 2015-09-08 12:59:46 +02:00
parent 8452012af0
commit e7d9bf53f8
7 changed files with 126 additions and 34 deletions

View file

@ -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,
)
}

View file

@ -86,4 +86,8 @@ class Stats::TicketChannelDistribution
{ channels: result }
end
def self.average_state(result, _user_id)
result
end
end

View file

@ -40,4 +40,8 @@ class Stats::TicketEscalation
}
end
def self.average_state(result, _user_id)
result
end
end

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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