2020-10-29 11:49:09 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Reports::TimeToFirstResponse
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def report_time_to_first_response(report)
|
|
|
|
category_filter = report.filters.dig(:category)
|
|
|
|
category_id, include_subcategories = report.add_category_filter
|
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
report.icon = "reply"
|
2020-10-29 11:49:09 -05:00
|
|
|
report.higher_is_better = false
|
|
|
|
report.data = []
|
2021-06-21 03:35:11 -05:00
|
|
|
report.average = true
|
2020-10-29 11:49:09 -05:00
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
Topic
|
|
|
|
.time_to_first_response_per_day(
|
|
|
|
report.start_date,
|
|
|
|
report.end_date,
|
|
|
|
category_id: category_id,
|
|
|
|
include_subcategories: include_subcategories,
|
|
|
|
)
|
|
|
|
.each { |r| report.data << { x: r["date"], y: r["hours"].to_f.round(2) } }
|
2020-10-29 11:49:09 -05:00
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
report.prev30Days =
|
|
|
|
Topic.time_to_first_response_total(
|
|
|
|
start_date: report.start_date - 30.days,
|
|
|
|
end_date: report.start_date,
|
|
|
|
category_id: category_id,
|
|
|
|
include_subcategories: include_subcategories,
|
|
|
|
)
|
2020-10-29 11:49:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|