Update
This commit is contained in:
+14
-11
@@ -316,15 +316,15 @@ GEM
|
||||
google-cloud-translate-v3 (0.6.0)
|
||||
gapic-common (>= 0.17.1, < 2.a)
|
||||
google-cloud-errors (~> 1.0)
|
||||
google-protobuf (3.25.2)
|
||||
google-protobuf (3.25.2-arm64-darwin)
|
||||
google-protobuf (3.25.2-x86_64-darwin)
|
||||
google-protobuf (3.25.2-x86_64-linux)
|
||||
google-protobuf (3.25.3)
|
||||
google-protobuf (3.25.3-arm64-darwin)
|
||||
google-protobuf (3.25.3-x86_64-darwin)
|
||||
google-protobuf (3.25.3-x86_64-linux)
|
||||
googleapis-common-protos (1.4.0)
|
||||
google-protobuf (~> 3.14)
|
||||
googleapis-common-protos-types (~> 1.2)
|
||||
grpc (~> 1.27)
|
||||
googleapis-common-protos-types (1.11.0)
|
||||
googleapis-common-protos-types (1.14.0)
|
||||
google-protobuf (~> 3.18)
|
||||
googleauth (1.5.2)
|
||||
faraday (>= 0.17.3, < 3.a)
|
||||
@@ -335,14 +335,17 @@ GEM
|
||||
signet (>= 0.16, < 2.a)
|
||||
groupdate (6.2.1)
|
||||
activesupport (>= 5.2)
|
||||
grpc (1.54.3)
|
||||
google-protobuf (~> 3.21)
|
||||
grpc (1.63.0)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
grpc (1.54.3-x86_64-darwin)
|
||||
google-protobuf (~> 3.21)
|
||||
grpc (1.63.0-arm64-darwin)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
grpc (1.54.3-x86_64-linux)
|
||||
google-protobuf (~> 3.21)
|
||||
grpc (1.63.0-x86_64-darwin)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
grpc (1.63.0-x86_64-linux)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
haikunator (1.1.1)
|
||||
hairtrigger (1.0.0)
|
||||
|
||||
@@ -4,29 +4,44 @@ class V2::NewReportBuilder
|
||||
pattr_initialize :account, :params
|
||||
|
||||
AVG_METRICS = %w[avg_first_response_time avg_resolution_time reply_time].freeze
|
||||
COUNT_METRICS = %w[conversations_count incoming_messages_count outgoing_messages_count resolutions_count bot_resolutions_count
|
||||
bot_handoffs_count].freeze
|
||||
COUNT_METRICS = %w[
|
||||
conversations_count
|
||||
incoming_messages_count
|
||||
outgoing_messages_count
|
||||
resolutions_count
|
||||
bot_resolutions_count
|
||||
bot_handoffs_count
|
||||
].freeze
|
||||
|
||||
DEFAULT_GROUP_BY = 'day'.freeze
|
||||
AGENT_RESULTS_PER_PAGE = 25
|
||||
|
||||
def build
|
||||
builder_class = case params[:metric]
|
||||
when *AVG_METRICS
|
||||
V2::Reports::Timeseries::AverageReportBuilder
|
||||
when *COUNT_METRICS
|
||||
V2::Reports::Timeseries::MetricCountReportBuilder
|
||||
else
|
||||
log_invalid_metric
|
||||
return {}
|
||||
end
|
||||
def timeseries
|
||||
return builder_class.new(account, params).timeseries if builder_class.present?
|
||||
|
||||
builder_class.new(account, params).build
|
||||
log_invalid_metric
|
||||
end
|
||||
|
||||
def aggregate_value
|
||||
return builder_class.new(account, params).aggregate_value if builder_class.present?
|
||||
|
||||
log_invalid_metric
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def builder_class
|
||||
case params[:metric]
|
||||
when *AVG_METRICS
|
||||
V2::Reports::Timeseries::AverageReportBuilder
|
||||
when *COUNT_METRICS
|
||||
V2::Reports::Timeseries::MetricCountReportBuilder
|
||||
end
|
||||
end
|
||||
|
||||
def log_invalid_metric
|
||||
Rails.logger.error "ReportBuilder: Invalid metric - #{params[:metric]}"
|
||||
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,11 +46,10 @@ class V2::ReportBuilder
|
||||
}
|
||||
end
|
||||
|
||||
def short_summary
|
||||
def bot_summary
|
||||
{
|
||||
conversations_count: conversations.count,
|
||||
avg_first_response_time: avg_first_response_time_summary,
|
||||
avg_resolution_time: avg_resolution_time_summary
|
||||
bot_resolutions_count: bot_resolutions.count,
|
||||
bot_handoffs_count: bot_handoffs.count
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class V2::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
|
||||
@@ -0,0 +1,29 @@
|
||||
class V2::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
|
||||
@@ -1,5 +1,5 @@
|
||||
class V2::Reports::Timeseries::AverageReportBuilder < V2::Reports::Timeseries::BaseTimeseriesBuilder
|
||||
def build
|
||||
def timeseries
|
||||
grouped_average_time = reporting_events.average(average_value_key)
|
||||
grouped_event_count = reporting_events.count
|
||||
grouped_average_time.each_with_object([]) do |element, arr|
|
||||
@@ -12,6 +12,10 @@ class V2::Reports::Timeseries::AverageReportBuilder < V2::Reports::Timeseries::B
|
||||
end
|
||||
end
|
||||
|
||||
def aggregate_value
|
||||
object_scope.average(average_value_key)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def event_name
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
class V2::Reports::Timeseries::MetricCountReportBuilder < V2::Reports::Timeseries::BaseTimeseriesBuilder
|
||||
def build
|
||||
def timeseries
|
||||
grouped_count.each_with_object([]) do |element, arr|
|
||||
event_date, event_count = element
|
||||
arr << { value: event_count, timestamp: event_date.to_time.to_i }
|
||||
end
|
||||
end
|
||||
|
||||
def aggregate_value
|
||||
object_scope.count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def metric
|
||||
|
||||
@@ -6,7 +6,7 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
|
||||
def index
|
||||
builder = V2::NewReportBuilder.new(Current.account, report_params)
|
||||
data = builder.build
|
||||
data = builder.timeseries
|
||||
render json: data
|
||||
end
|
||||
|
||||
@@ -14,6 +14,12 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
render json: summary_metrics
|
||||
end
|
||||
|
||||
def bot_summary
|
||||
summary = V2::NewReportBuilder.new(Current.account, current_summary_params).bot_summary
|
||||
summary[:previous] = V2::ReportBuilder.new(Current.account, previous_summary_params).bot_summary
|
||||
render json: summary
|
||||
end
|
||||
|
||||
def agents
|
||||
@report_data = generate_agents_report
|
||||
generate_csv('agents_report', 'api/v2/accounts/reports/agents')
|
||||
@@ -42,6 +48,22 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
generate_csv('conversation_traffic_reports', 'api/v2/accounts/reports/conversation_traffic')
|
||||
end
|
||||
|
||||
def conversations
|
||||
case params[:type].to_sym
|
||||
when :account
|
||||
render json: V2::LiveReports::AccountReportsBuilder.new(Current.account).build
|
||||
when :agent
|
||||
render json: V2::LiveReports::AgentReportsBuilder.new(Current.account, conversation_params).build
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def bot_metrics
|
||||
bot_metrics = V2::Reports::BotMetricsBuilder.new(Current.account, params).metrics
|
||||
render json: bot_metrics
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_csv(filename, template)
|
||||
@@ -89,11 +111,7 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def conversation_params
|
||||
{
|
||||
type: params[:type].to_sym,
|
||||
user_id: params[:user_id],
|
||||
page: params[:page].presence || 1
|
||||
}
|
||||
{ page: params[:page].presence || 1 }
|
||||
end
|
||||
|
||||
def range
|
||||
|
||||
@@ -37,7 +37,7 @@ module Api::V2::Accounts::ReportsHelper
|
||||
business_hours: ActiveModel::Type::Boolean.new.cast(params[:business_hours])
|
||||
}
|
||||
)
|
||||
).short_summary
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user