Revert changes unrelated to performance
This commit is contained in:
@@ -46,6 +46,14 @@ class V2::ReportBuilder
|
||||
}
|
||||
end
|
||||
|
||||
def short_summary
|
||||
{
|
||||
conversations_count: conversations.count,
|
||||
avg_first_response_time: avg_first_response_time_summary,
|
||||
avg_resolution_time: avg_resolution_time_summary
|
||||
}
|
||||
end
|
||||
|
||||
def bot_summary
|
||||
{
|
||||
bot_resolutions_count: bot_resolutions.count,
|
||||
@@ -53,6 +61,14 @@ class V2::ReportBuilder
|
||||
}
|
||||
end
|
||||
|
||||
def conversation_metrics
|
||||
if params[:type].equal?(:account)
|
||||
live_conversations
|
||||
else
|
||||
agent_metrics.sort_by { |hash| hash[:metric][:open] }.reverse
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def metric_valid?
|
||||
@@ -91,4 +107,30 @@ class V2::ReportBuilder
|
||||
time_zone: @timezone
|
||||
)
|
||||
end
|
||||
|
||||
def agent_metrics
|
||||
account_users = @account.account_users.page(params[:page]).per(AGENT_RESULTS_PER_PAGE)
|
||||
account_users.each_with_object([]) do |account_user, arr|
|
||||
@user = account_user.user
|
||||
arr << {
|
||||
id: @user.id,
|
||||
name: @user.name,
|
||||
email: @user.email,
|
||||
thumbnail: @user.avatar_url,
|
||||
availability: account_user.availability_status,
|
||||
metric: live_conversations
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def live_conversations
|
||||
@open_conversations = scope.conversations.where(account_id: @account.id).open
|
||||
metric = {
|
||||
open: @open_conversations.count,
|
||||
unattended: @open_conversations.unattended.count
|
||||
}
|
||||
metric[:unassigned] = @open_conversations.unassigned.count if params[:type].equal?(:account)
|
||||
metric[:pending] = @open_conversations.pending.count if params[:type].equal?(:account)
|
||||
metric
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
class V2::Reports::LiveReports::AccountReportsBuilder
|
||||
pattr_initialize :account
|
||||
|
||||
def build
|
||||
open_conversations = account.conversations.open
|
||||
metric = {
|
||||
open: open_conversations.count,
|
||||
unattended: open_conversations.unattended.count
|
||||
}
|
||||
metric[:unassigned] = open_conversations.unassigned.count
|
||||
metric[:pending] = open_conversations.pending.count
|
||||
metric
|
||||
end
|
||||
end
|
||||
@@ -1,29 +0,0 @@
|
||||
class V2::Reports::LiveReports::AgentReportsBuilder
|
||||
pattr_initialize :account, :params
|
||||
AGENT_RESULTS_PER_PAGE = 25
|
||||
|
||||
def build
|
||||
account_users = account.account_users.page(params[:page]).per(AGENT_RESULTS_PER_PAGE)
|
||||
account_users.each_with_object([]) do |account_user, arr|
|
||||
user = account_user.user
|
||||
arr << {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
thumbnail: user.avatar_url,
|
||||
availability: account_user.availability_status,
|
||||
metric: live_conversations(user)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def live_conversations(user)
|
||||
open_conversations = user.conversations.where(account_id: @account.id).open
|
||||
{
|
||||
open: open_conversations.count,
|
||||
unattended: open_conversations.unattended.count
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -47,14 +47,9 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def conversations
|
||||
case params[:type].to_sym
|
||||
when :account
|
||||
render json: V2::Reports::LiveReports::AccountReportsBuilder.new(Current.account).build
|
||||
when :agent
|
||||
render json: V2::Reports::LiveReports::AgentReportsBuilder.new(Current.account, conversation_params).build
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
return head :unprocessable_entity if params[:type].blank?
|
||||
|
||||
render json: conversation_metrics
|
||||
end
|
||||
|
||||
def bot_metrics
|
||||
@@ -109,7 +104,11 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def conversation_params
|
||||
{ page: params[:page].presence || 1 }
|
||||
{
|
||||
type: params[:type].to_sym,
|
||||
user_id: params[:user_id],
|
||||
page: params[:page].presence || 1
|
||||
}
|
||||
end
|
||||
|
||||
def range
|
||||
@@ -131,4 +130,8 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
previous_summary = builder.new(Current.account, previous_summary_params).send(method)
|
||||
current_summary.merge(previous: previous_summary)
|
||||
end
|
||||
|
||||
def conversation_metrics
|
||||
V2::ReportBuilder.new(Current.account, conversation_params).conversation_metrics
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,17 +66,18 @@ module Api::V2::Accounts::HeatmapHelper
|
||||
end
|
||||
|
||||
def generate_heatmap_data(date, offset)
|
||||
V2::NewReportBuilder.new(
|
||||
Current.account, {
|
||||
type: :account,
|
||||
group_by: 'hour',
|
||||
metric: 'conversations_count',
|
||||
business_hours: false,
|
||||
since: since_timestamp(date),
|
||||
until: until_timestamp(date),
|
||||
timezone_offset: offset
|
||||
}
|
||||
).timeseries
|
||||
report_params = {
|
||||
type: :account,
|
||||
group_by: 'hour',
|
||||
metric: 'conversations_count',
|
||||
business_hours: false
|
||||
}
|
||||
|
||||
V2::ReportBuilder.new(Current.account, report_params.merge({
|
||||
since: since_timestamp(date),
|
||||
until: until_timestamp(date),
|
||||
timezone_offset: offset
|
||||
})).build
|
||||
end
|
||||
|
||||
def transform_data(data, zone_transform)
|
||||
|
||||
Reference in New Issue
Block a user