discourse/app/models/concerns/reports/consolidated_api_requests.rb
Martin Brennan 4580844c56
UX: Change consolidated pageview experimental report colors (#27240)
Followup 94fe31e5b37c6dc9296a191cf2f7013419a3f50e,
change the color of the "Known Crawler" bar on the
new "Consolidated Pageviews with Browser Detection (Experimental)"
report to be purple, like it was on the original
"Consolidated Pageviews" report to allow for easier
visual comparison.

Also removes the report colors to named keys in a hash
for easier reference than having to look up the
index of the array all the time.
2024-05-29 17:01:30 +10:00

37 lines
982 B
Ruby

# frozen_string_literal: true
module Reports::ConsolidatedApiRequests
extend ActiveSupport::Concern
class_methods do
def report_consolidated_api_requests(report)
filters = %w[api user_api]
report.modes = [:stacked_chart]
requests =
filters.map do |filter|
color = filter == "api" ? report.colors[:turquoise] : report.colors[:lime]
{
req: filter,
label: I18n.t("reports.consolidated_api_requests.xaxis.#{filter}"),
color: color,
data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]),
}
end
requests.each do |request|
request[:data] = request[:data]
.where("date >= ? AND date <= ?", report.start_date, report.end_date)
.order(date: :asc)
.group(:date)
.sum(:count)
.map { |date, count| { x: date, y: count } }
end
report.data = requests
end
end
end