mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 14:46:28 +08:00
4580844c56
Followup 94fe31e5b3
,
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.
37 lines
982 B
Ruby
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
|