Update records
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
class V2::BaseConversationReportBuilder
|
||||
pattr_initialize :account, :params
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
|
||||
def builder_class(metric)
|
||||
case metric
|
||||
when *AVG_METRICS
|
||||
V2::Reports::Timeseries::AverageReportBuilder
|
||||
when *COUNT_METRICS
|
||||
V2::Reports::Timeseries::CountReportBuilder
|
||||
end
|
||||
end
|
||||
|
||||
def log_invalid_metric
|
||||
Rails.logger.error "ReportBuilder: Invalid metric - #{params[:metric]}"
|
||||
|
||||
{}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
class V2::ConversationMetricBuilder < V2::BaseConversationReportBuilder
|
||||
def summary
|
||||
{
|
||||
conversations_count: count('conversations_count'),
|
||||
incoming_messages_count: count('incoming_messages_count'),
|
||||
outgoing_messages_count: count('outgoing_messages_count'),
|
||||
avg_first_response_time: count('avg_first_response_time'),
|
||||
avg_resolution_time: count('avg_resolution_time'),
|
||||
resolutions_count: count('resolutions_count'),
|
||||
reply_time: count('reply_time')
|
||||
}
|
||||
end
|
||||
|
||||
def bot_summary
|
||||
{
|
||||
bot_resolutions_count: count('bot_resolutions_count'),
|
||||
bot_handoffs_count: count('bot_handoffs_count')
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def count(metric)
|
||||
builder_class(metric).new(account, builder_params(metric)).aggregate_value
|
||||
end
|
||||
|
||||
def builder_params(metric)
|
||||
params.merge({ metric: metric })
|
||||
end
|
||||
end
|
||||
@@ -1,47 +1,25 @@
|
||||
class V2::NewReportBuilder
|
||||
class V2::NewReportBuilder < V2::BaseConversationReportBuilder
|
||||
include DateRangeHelper
|
||||
|
||||
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
|
||||
|
||||
DEFAULT_GROUP_BY = 'day'.freeze
|
||||
AGENT_RESULTS_PER_PAGE = 25
|
||||
|
||||
def timeseries
|
||||
return builder_class.new(account, params).timeseries if builder_class.present?
|
||||
|
||||
log_invalid_metric
|
||||
perform_action(:timeseries)
|
||||
end
|
||||
|
||||
def aggregate_value
|
||||
return builder_class.new(account, params).aggregate_value if builder_class.present?
|
||||
|
||||
log_invalid_metric
|
||||
perform_action(:aggregate_value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def builder_class
|
||||
case params[:metric]
|
||||
when *AVG_METRICS
|
||||
V2::Reports::Timeseries::AverageReportBuilder
|
||||
when *COUNT_METRICS
|
||||
V2::Reports::Timeseries::MetricCountReportBuilder
|
||||
end
|
||||
def perform_action(method_name)
|
||||
return builder.new(account, params).public_send(method_name) if builder.present?
|
||||
|
||||
log_invalid_metric
|
||||
end
|
||||
|
||||
def log_invalid_metric
|
||||
Rails.logger.error "ReportBuilder: Invalid metric - #{params[:metric]}"
|
||||
|
||||
{}
|
||||
def builder
|
||||
builder_class(params[:metric])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class V2::LiveReports::AccountReportsBuilder
|
||||
class V2::Reports::LiveReports::AccountReportsBuilder
|
||||
pattr_initialize :account
|
||||
|
||||
def build
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class V2::LiveReports::AgentReportsBuilder
|
||||
class V2::Reports::LiveReports::AgentReportsBuilder
|
||||
pattr_initialize :account, :params
|
||||
AGENT_RESULTS_PER_PAGE = 25
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ class V2::Reports::Timeseries::AverageReportBuilder < V2::Reports::Timeseries::B
|
||||
metric_to_event_name[params[:metric].to_sym]
|
||||
end
|
||||
|
||||
def object_scope
|
||||
scope.reporting_events.where(name: event_name, created_at: range)
|
||||
end
|
||||
|
||||
def reporting_events
|
||||
object_scope = scope.reporting_events.where(name: event_name)
|
||||
@grouped_values = object_scope.group_by_period(
|
||||
group_by,
|
||||
:created_at,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class V2::Reports::Timeseries::MetricCountReportBuilder < V2::Reports::Timeseries::BaseTimeseriesBuilder
|
||||
class V2::Reports::Timeseries::CountReportBuilder < V2::Reports::Timeseries::BaseTimeseriesBuilder
|
||||
def timeseries
|
||||
grouped_count.each_with_object([]) do |element, arr|
|
||||
event_date, event_count = element
|
||||
@@ -11,13 +11,11 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def summary
|
||||
render json: summary_metrics
|
||||
render json: build_summary(:summary)
|
||||
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
|
||||
render json: build_summary(:bot_summary)
|
||||
end
|
||||
|
||||
def agents
|
||||
@@ -51,9 +49,9 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
def conversations
|
||||
case params[:type].to_sym
|
||||
when :account
|
||||
render json: V2::LiveReports::AccountReportsBuilder.new(Current.account).build
|
||||
render json: V2::Reports::LiveReports::AccountReportsBuilder.new(Current.account).build
|
||||
when :agent
|
||||
render json: V2::LiveReports::AgentReportsBuilder.new(Current.account, conversation_params).build
|
||||
render json: V2::Reports::LiveReports::AgentReportsBuilder.new(Current.account, conversation_params).build
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
@@ -127,9 +125,10 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
}
|
||||
end
|
||||
|
||||
def summary_metrics
|
||||
summary = V2::ReportBuilder.new(Current.account, current_summary_params).summary
|
||||
summary[:previous] = V2::ReportBuilder.new(Current.account, previous_summary_params).summary
|
||||
summary
|
||||
def build_summary(method)
|
||||
builder = V2::ConversationMetricBuilder
|
||||
current_summary = builder.new(Current.account, current_summary_params).send(method)
|
||||
previous_summary = builder.new(Current.account, previous_summary_params).send(method)
|
||||
current_summary.merge(previous: previous_summary)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,18 +66,17 @@ module Api::V2::Accounts::HeatmapHelper
|
||||
end
|
||||
|
||||
def generate_heatmap_data(date, offset)
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
def transform_data(data, zone_transform)
|
||||
|
||||
Reference in New Issue
Block a user