2019-05-02 18:17:27 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
|
class Report
|
2018-07-31 17:35:13 -04:00
|
|
|
|
# Change this line each time report format change
|
|
|
|
|
# and you want to ensure cache is reset
|
2019-04-26 06:17:10 -04:00
|
|
|
|
SCHEMA_VERSION = 4
|
2018-07-31 17:35:13 -04:00
|
|
|
|
|
2020-06-10 11:57:39 -04:00
|
|
|
|
FILTERS = [:name, :start_date, :end_date, :category, :group, :trust_level, :file_extension, :include_subcategories]
|
|
|
|
|
|
2018-05-03 09:41:41 -04:00
|
|
|
|
attr_accessor :type, :data, :total, :prev30Days, :start_date,
|
2019-04-26 06:17:10 -04:00
|
|
|
|
:end_date, :labels, :prev_period, :facets, :limit, :average,
|
|
|
|
|
:percent, :higher_is_better, :icon, :modes, :prev_data,
|
|
|
|
|
:prev_start_date, :prev_end_date, :dates_filtering, :error,
|
|
|
|
|
:primary_color, :secondary_color, :filters, :available_filters
|
2014-11-04 17:08:39 -05:00
|
|
|
|
|
|
|
|
|
def self.default_days
|
|
|
|
|
30
|
|
|
|
|
end
|
2013-02-27 22:39:42 -05:00
|
|
|
|
|
2019-06-28 02:50:31 -04:00
|
|
|
|
def self.default_labels
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
type: :date,
|
|
|
|
|
property: :x,
|
|
|
|
|
title: I18n.t("reports.default.labels.day")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: :number,
|
|
|
|
|
property: :y,
|
|
|
|
|
title: I18n.t("reports.default.labels.count")
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
|
def initialize(type)
|
|
|
|
|
@type = type
|
2018-08-17 10:19:25 -04:00
|
|
|
|
@start_date ||= Report.default_days.days.ago.utc.beginning_of_day
|
|
|
|
|
@end_date ||= Time.now.utc.end_of_day
|
2018-07-19 14:33:11 -04:00
|
|
|
|
@prev_end_date = @start_date
|
2018-05-17 16:44:33 -04:00
|
|
|
|
@average = false
|
|
|
|
|
@percent = false
|
|
|
|
|
@higher_is_better = true
|
2018-07-19 14:33:11 -04:00
|
|
|
|
@modes = [:table, :chart]
|
|
|
|
|
@prev_data = nil
|
|
|
|
|
@dates_filtering = true
|
2019-04-26 06:17:10 -04:00
|
|
|
|
@available_filters = {}
|
|
|
|
|
@filters = {}
|
2018-09-13 11:36:39 -04:00
|
|
|
|
|
|
|
|
|
tertiary = ColorScheme.hex_for_name('tertiary') || '0088cc'
|
|
|
|
|
@primary_color = rgba_color(tertiary)
|
|
|
|
|
@secondary_color = rgba_color(tertiary, 0.1)
|
2013-02-27 22:39:42 -05:00
|
|
|
|
end
|
|
|
|
|
|
2018-05-03 09:41:41 -04:00
|
|
|
|
def self.cache_key(report)
|
2018-05-10 23:30:21 -04:00
|
|
|
|
[
|
2020-04-22 04:52:50 -04:00
|
|
|
|
"reports",
|
2018-05-10 23:30:21 -04:00
|
|
|
|
report.type,
|
|
|
|
|
report.start_date.to_date.strftime("%Y%m%d"),
|
|
|
|
|
report.end_date.to_date.strftime("%Y%m%d"),
|
2018-05-15 01:08:23 -04:00
|
|
|
|
report.facets,
|
2018-07-31 17:35:13 -04:00
|
|
|
|
report.limit,
|
2019-04-26 06:17:10 -04:00
|
|
|
|
report.filters.blank? ? nil : MultiJson.dump(report.filters),
|
2018-07-31 17:35:13 -04:00
|
|
|
|
SCHEMA_VERSION,
|
|
|
|
|
].compact.map(&:to_s).join(':')
|
2018-05-03 09:41:41 -04:00
|
|
|
|
end
|
|
|
|
|
|
2019-04-26 06:17:10 -04:00
|
|
|
|
def add_filter(name, options = {})
|
2020-04-22 04:52:50 -04:00
|
|
|
|
if options[:type].blank?
|
|
|
|
|
options[:type] = name
|
|
|
|
|
Discourse.deprecate("#{name} filter should define a `:type` option. Temporarily setting type to #{name}.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
available_filters[name] = options
|
2019-04-26 06:17:10 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def remove_filter(name)
|
|
|
|
|
available_filters.delete(name)
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-22 04:52:50 -04:00
|
|
|
|
def add_category_filter
|
|
|
|
|
category_id = filters[:category].to_i if filters[:category].present?
|
|
|
|
|
add_filter('category', type: 'category', default: category_id)
|
|
|
|
|
return if category_id.blank?
|
|
|
|
|
|
2020-06-10 11:57:39 -04:00
|
|
|
|
include_subcategories = filters[:include_subcategories]
|
2020-04-22 04:52:50 -04:00
|
|
|
|
include_subcategories = !!ActiveRecord::Type::Boolean.new.cast(include_subcategories)
|
2020-06-10 11:57:39 -04:00
|
|
|
|
add_filter('include_subcategories', type: 'bool', default: include_subcategories)
|
2020-04-22 04:52:50 -04:00
|
|
|
|
|
|
|
|
|
[category_id, include_subcategories]
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-14 17:14:46 -05:00
|
|
|
|
def self.clear_cache(type = nil)
|
|
|
|
|
pattern = type ? "reports:#{type}:*" : "reports:*"
|
|
|
|
|
|
|
|
|
|
Discourse.cache.keys(pattern).each do |key|
|
2018-05-03 09:41:41 -04:00
|
|
|
|
Discourse.cache.redis.del(key)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
|
def self.wrap_slow_query(timeout = 20000)
|
2018-08-01 07:39:57 -04:00
|
|
|
|
ActiveRecord::Base.connection.transaction do
|
2019-08-15 03:27:53 -04:00
|
|
|
|
# Allows only read only transactions
|
|
|
|
|
DB.exec "SET TRANSACTION READ ONLY"
|
2018-08-01 07:39:57 -04:00
|
|
|
|
# Set a statement timeout so we can't tie up the server
|
|
|
|
|
DB.exec "SET LOCAL statement_timeout = #{timeout}"
|
|
|
|
|
yield
|
2018-07-19 14:33:11 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def prev_start_date
|
|
|
|
|
self.start_date - (self.end_date - self.start_date)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def prev_end_date
|
|
|
|
|
self.start_date
|
|
|
|
|
end
|
|
|
|
|
|
2015-06-24 09:19:39 -04:00
|
|
|
|
def as_json(options = nil)
|
2018-05-14 10:34:56 -04:00
|
|
|
|
description = I18n.t("reports.#{type}.description", default: "")
|
2020-03-02 14:30:51 -05:00
|
|
|
|
description_link = I18n.t("reports.#{type}.description_link", default: "")
|
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
|
{
|
2018-07-31 17:35:13 -04:00
|
|
|
|
type: type,
|
2018-12-14 17:14:46 -05:00
|
|
|
|
title: I18n.t("reports.#{type}.title", default: nil),
|
|
|
|
|
xaxis: I18n.t("reports.#{type}.xaxis", default: nil),
|
|
|
|
|
yaxis: I18n.t("reports.#{type}.yaxis", default: nil),
|
2018-07-31 17:35:13 -04:00
|
|
|
|
description: description.presence ? description : nil,
|
2020-03-02 14:30:51 -05:00
|
|
|
|
description_link: description_link.presence ? description_link : nil,
|
2018-07-31 17:35:13 -04:00
|
|
|
|
data: data,
|
|
|
|
|
start_date: start_date&.iso8601,
|
|
|
|
|
end_date: end_date&.iso8601,
|
|
|
|
|
prev_data: self.prev_data,
|
|
|
|
|
prev_start_date: prev_start_date&.iso8601,
|
|
|
|
|
prev_end_date: prev_end_date&.iso8601,
|
|
|
|
|
prev30Days: self.prev30Days,
|
|
|
|
|
dates_filtering: self.dates_filtering,
|
|
|
|
|
report_key: Report.cache_key(self),
|
2018-08-30 08:56:11 -04:00
|
|
|
|
primary_color: self.primary_color,
|
|
|
|
|
secondary_color: self.secondary_color,
|
2019-04-26 06:17:10 -04:00
|
|
|
|
available_filters: self.available_filters.map { |k, v| { id: k }.merge(v) },
|
2019-06-28 02:50:31 -04:00
|
|
|
|
labels: labels || Report.default_labels,
|
2018-07-31 17:35:13 -04:00
|
|
|
|
average: self.average,
|
|
|
|
|
percent: self.percent,
|
|
|
|
|
higher_is_better: self.higher_is_better,
|
|
|
|
|
modes: self.modes,
|
2018-03-15 17:10:45 -04:00
|
|
|
|
}.tap do |json|
|
2018-08-06 16:57:40 -04:00
|
|
|
|
json[:icon] = self.icon if self.icon
|
2018-07-31 21:23:28 -04:00
|
|
|
|
json[:error] = self.error if self.error
|
2018-07-19 14:33:11 -04:00
|
|
|
|
json[:total] = self.total if self.total
|
|
|
|
|
json[:prev_period] = self.prev_period if self.prev_period
|
2018-05-10 23:30:21 -04:00
|
|
|
|
json[:prev30Days] = self.prev30Days if self.prev30Days
|
2018-05-15 01:08:23 -04:00
|
|
|
|
json[:limit] = self.limit if self.limit
|
2018-05-10 23:30:21 -04:00
|
|
|
|
|
2018-03-15 17:10:45 -04:00
|
|
|
|
if type == 'page_view_crawler_reqs'
|
|
|
|
|
json[:related_report] = Report.find('web_crawlers', start_date: start_date, end_date: end_date)&.as_json
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-02-27 22:39:42 -05:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-24 20:42:08 -04:00
|
|
|
|
def Report.add_report(name, &block)
|
|
|
|
|
singleton_class.instance_eval { define_method("report_#{name}", &block) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-05-16 02:05:03 -04:00
|
|
|
|
def self._get(type, opts = nil)
|
2014-11-04 17:08:39 -05:00
|
|
|
|
opts ||= {}
|
2015-10-19 16:30:34 -04:00
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
|
# Load the report
|
|
|
|
|
report = Report.new(type)
|
2018-05-03 11:39:37 -04:00
|
|
|
|
report.start_date = opts[:start_date] if opts[:start_date]
|
|
|
|
|
report.end_date = opts[:end_date] if opts[:end_date]
|
2018-05-10 23:30:21 -04:00
|
|
|
|
report.facets = opts[:facets] || [:total, :prev30Days]
|
2018-05-15 01:08:23 -04:00
|
|
|
|
report.limit = opts[:limit] if opts[:limit]
|
2018-05-17 16:44:33 -04:00
|
|
|
|
report.average = opts[:average] if opts[:average]
|
|
|
|
|
report.percent = opts[:percent] if opts[:percent]
|
2019-04-26 06:17:10 -04:00
|
|
|
|
report.filters = opts[:filters] if opts[:filters]
|
2019-07-26 03:27:13 -04:00
|
|
|
|
report.labels = Report.default_labels
|
2019-04-26 06:17:10 -04:00
|
|
|
|
|
2018-05-16 02:05:03 -04:00
|
|
|
|
report
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.find_cached(type, opts = nil)
|
|
|
|
|
report = _get(type, opts)
|
|
|
|
|
Discourse.cache.read(cache_key(report))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.cache(report, duration)
|
2019-11-27 00:11:49 -05:00
|
|
|
|
Discourse.cache.write(cache_key(report), report.as_json, expires_in: duration)
|
2018-05-16 02:05:03 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.find(type, opts = nil)
|
2019-02-08 11:25:32 -05:00
|
|
|
|
opts ||= {}
|
|
|
|
|
|
2018-07-31 21:23:28 -04:00
|
|
|
|
begin
|
|
|
|
|
report = _get(type, opts)
|
|
|
|
|
report_method = :"report_#{type}"
|
2015-02-05 00:08:52 -05:00
|
|
|
|
|
2018-08-01 07:39:57 -04:00
|
|
|
|
begin
|
|
|
|
|
wrap_slow_query do
|
|
|
|
|
if respond_to?(report_method)
|
2019-05-06 21:57:55 -04:00
|
|
|
|
public_send(report_method, report)
|
2018-08-01 07:39:57 -04:00
|
|
|
|
elsif type =~ /_reqs$/
|
|
|
|
|
req_report(report, type.split(/_reqs$/)[0].to_sym)
|
|
|
|
|
else
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue ActiveRecord::QueryCanceled, PG::QueryCanceled => e
|
|
|
|
|
report.error = :timeout
|
2018-07-31 21:23:28 -04:00
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
2019-02-08 11:25:32 -05:00
|
|
|
|
# In test mode, don't swallow exceptions by default to help debug errors.
|
|
|
|
|
raise if Rails.env.test? && !opts[:wrap_exceptions_in_test]
|
|
|
|
|
|
2018-09-13 11:36:55 -04:00
|
|
|
|
# ensures that if anything unexpected prevents us from
|
|
|
|
|
# creating a report object we fail elegantly and log an error
|
|
|
|
|
if !report
|
|
|
|
|
Rails.logger.error("Couldn’t create report `#{type}`: <#{e.class} #{e.message}>")
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2018-07-31 21:23:28 -04:00
|
|
|
|
report.error = :exception
|
|
|
|
|
|
|
|
|
|
# given reports can be added by plugins we don’t want dashboard failures
|
|
|
|
|
# on report computation, however we do want to log which report is provoking
|
|
|
|
|
# an error
|
2018-10-10 05:43:27 -04:00
|
|
|
|
Rails.logger.error("Error while computing report `#{report.type}`: #{e.message}\n#{e.backtrace.join("\n")}")
|
2015-02-05 00:08:52 -05:00
|
|
|
|
end
|
2015-06-24 09:19:39 -04:00
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
|
report
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-04 19:18:11 -05:00
|
|
|
|
def self.req_report(report, filter = nil)
|
2015-02-05 22:39:04 -05:00
|
|
|
|
data =
|
|
|
|
|
if filter == :page_view_total
|
|
|
|
|
ApplicationRequest.where(req_type: [
|
2015-07-03 17:02:57 -04:00
|
|
|
|
ApplicationRequest.req_types.reject { |k, v| k =~ /mobile/ }.map { |k, v| v if k =~ /page_view/ }.compact
|
2015-09-23 01:24:30 -04:00
|
|
|
|
].flatten)
|
2015-02-05 22:39:04 -05:00
|
|
|
|
else
|
2018-07-31 17:35:13 -04:00
|
|
|
|
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
|
2015-02-05 22:39:04 -05:00
|
|
|
|
end
|
2015-02-04 19:18:11 -05:00
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
|
if filter == :page_view_total
|
|
|
|
|
report.icon = 'file'
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-04 19:18:11 -05:00
|
|
|
|
report.data = []
|
2018-05-03 09:41:41 -04:00
|
|
|
|
data.where('date >= ? AND date <= ?', report.start_date, report.end_date)
|
2015-07-06 14:57:11 -04:00
|
|
|
|
.order(date: :asc)
|
2015-04-12 13:46:13 -04:00
|
|
|
|
.group(:date)
|
2015-02-04 19:18:11 -05:00
|
|
|
|
.sum(:count)
|
|
|
|
|
.each do |date, count|
|
2015-06-24 09:19:39 -04:00
|
|
|
|
report.data << { x: date, y: count }
|
2015-02-04 19:18:11 -05:00
|
|
|
|
end
|
|
|
|
|
|
2018-02-01 15:50:41 -05:00
|
|
|
|
report.total = data.sum(:count)
|
|
|
|
|
|
|
|
|
|
report.prev30Days = data.where(
|
|
|
|
|
'date >= ? AND date < ?',
|
2018-05-03 09:41:41 -04:00
|
|
|
|
(report.start_date - 31.days), report.start_date
|
2018-02-01 15:50:41 -05:00
|
|
|
|
).sum(:count)
|
2015-02-04 19:18:11 -05:00
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 09:21:34 -04:00
|
|
|
|
def self.report_about(report, subject_class, report_method = :count_per_day)
|
2014-11-05 13:11:23 -05:00
|
|
|
|
basic_report_about report, subject_class, report_method, report.start_date, report.end_date
|
2014-12-30 09:06:15 -05:00
|
|
|
|
add_counts report, subject_class
|
2013-04-01 09:21:34 -04:00
|
|
|
|
end
|
|
|
|
|
|
2013-04-16 16:56:18 -04:00
|
|
|
|
def self.basic_report_about(report, subject_class, report_method, *args)
|
2013-03-07 11:07:59 -05:00
|
|
|
|
report.data = []
|
2018-05-03 11:39:37 -04:00
|
|
|
|
|
2019-05-06 21:27:05 -04:00
|
|
|
|
subject_class.public_send(report_method, *args).each do |date, count|
|
2015-06-24 09:19:39 -04:00
|
|
|
|
report.data << { x: date, y: count }
|
2013-03-07 11:07:59 -05:00
|
|
|
|
end
|
2013-04-01 09:21:34 -04:00
|
|
|
|
end
|
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
|
def self.add_prev_data(report, subject_class, report_method, *args)
|
|
|
|
|
if report.modes.include?(:chart) && report.facets.include?(:prev_period)
|
2019-05-06 21:27:05 -04:00
|
|
|
|
prev_data = subject_class.public_send(report_method, *args)
|
2018-07-19 14:33:11 -04:00
|
|
|
|
report.prev_data = prev_data.map { |k, v| { x: k, y: v } }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-30 09:06:15 -05:00
|
|
|
|
def self.add_counts(report, subject_class, query_column = 'created_at')
|
2018-05-10 23:30:21 -04:00
|
|
|
|
if report.facets.include?(:prev_period)
|
2018-07-19 14:33:11 -04:00
|
|
|
|
prev_data = subject_class
|
2018-05-10 23:30:21 -04:00
|
|
|
|
.where("#{query_column} >= ? and #{query_column} < ?",
|
2018-07-19 14:33:11 -04:00
|
|
|
|
report.prev_start_date,
|
|
|
|
|
report.prev_end_date)
|
|
|
|
|
|
|
|
|
|
report.prev_period = prev_data.count
|
2018-05-10 23:30:21 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if report.facets.include?(:total)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
report.total = subject_class.count
|
2018-05-10 23:30:21 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if report.facets.include?(:prev30Days)
|
|
|
|
|
report.prev30Days = subject_class
|
|
|
|
|
.where("#{query_column} >= ? and #{query_column} < ?",
|
|
|
|
|
report.start_date - 30.days,
|
|
|
|
|
report.start_date).count
|
|
|
|
|
end
|
2013-03-07 11:07:59 -05:00
|
|
|
|
end
|
|
|
|
|
|
2013-04-18 14:27:22 -04:00
|
|
|
|
def self.post_action_report(report, post_action_type)
|
2020-04-22 04:52:50 -04:00
|
|
|
|
category_id, include_subcategories = report.add_category_filter
|
2019-04-26 06:17:10 -04:00
|
|
|
|
|
2013-03-17 13:53:00 -04:00
|
|
|
|
report.data = []
|
2020-04-22 04:52:50 -04:00
|
|
|
|
PostAction.count_per_day_for_type(post_action_type, category_id: category_id, include_subcategories: include_subcategories, start_date: report.start_date, end_date: report.end_date).each do |date, count|
|
2014-07-28 13:17:37 -04:00
|
|
|
|
report.data << { x: date, y: count }
|
2013-03-17 13:53:00 -04:00
|
|
|
|
end
|
2020-04-22 04:52:50 -04:00
|
|
|
|
|
2015-06-24 09:19:39 -04:00
|
|
|
|
countable = PostAction.unscoped.where(post_action_type_id: post_action_type)
|
2020-04-22 04:52:50 -04:00
|
|
|
|
if category_id
|
|
|
|
|
if include_subcategories
|
|
|
|
|
countable = countable.joins(post: :topic).where('topics.category_id IN (?)', Category.subcategory_ids(category_id))
|
|
|
|
|
else
|
|
|
|
|
countable = countable.joins(post: :topic).where('topics.category_id = ?', category_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-06-24 09:19:39 -04:00
|
|
|
|
add_counts report, countable, 'post_actions.created_at'
|
2013-03-17 13:53:00 -04:00
|
|
|
|
end
|
2013-04-16 16:56:18 -04:00
|
|
|
|
|
|
|
|
|
def self.private_messages_report(report, topic_subtype)
|
2018-07-19 14:33:11 -04:00
|
|
|
|
report.icon = 'envelope'
|
2018-07-23 10:33:12 -04:00
|
|
|
|
subject = Topic.where('topics.user_id > 0')
|
|
|
|
|
basic_report_about report, subject, :private_message_topics_count_per_day, report.start_date, report.end_date, topic_subtype
|
|
|
|
|
subject = Topic.private_messages.where('topics.user_id > 0').with_subtype(topic_subtype)
|
|
|
|
|
add_counts report, subject, 'topics.created_at'
|
2013-04-16 16:56:18 -04:00
|
|
|
|
end
|
|
|
|
|
|
2019-05-07 12:14:13 -04:00
|
|
|
|
def lighten_color(hex, amount)
|
|
|
|
|
hex = adjust_hex(hex)
|
|
|
|
|
rgb = hex.scan(/../).map { |color| color.hex }
|
|
|
|
|
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min
|
|
|
|
|
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min
|
|
|
|
|
rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255].min
|
|
|
|
|
"#%02x%02x%02x" % rgb
|
|
|
|
|
end
|
|
|
|
|
|
2018-08-30 08:56:11 -04:00
|
|
|
|
def rgba_color(hex, opacity = 1)
|
2019-05-07 12:14:13 -04:00
|
|
|
|
rgbs = hex_to_rgbs(adjust_hex(hex))
|
|
|
|
|
"rgba(#{rgbs.join(',')},#{opacity})"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def adjust_hex(hex)
|
|
|
|
|
hex = hex.gsub('#', '')
|
|
|
|
|
|
2018-11-15 15:41:05 -05:00
|
|
|
|
if hex.size == 3
|
2018-11-14 18:52:47 -05:00
|
|
|
|
chars = hex.scan(/\w/)
|
2018-11-15 15:41:05 -05:00
|
|
|
|
hex = chars.zip(chars).flatten.join
|
2018-11-14 18:52:47 -05:00
|
|
|
|
end
|
|
|
|
|
|
2018-11-15 15:41:05 -05:00
|
|
|
|
if hex.size < 3
|
2018-11-14 18:52:47 -05:00
|
|
|
|
hex = hex.ljust(6, hex.last)
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-07 12:14:13 -04:00
|
|
|
|
hex
|
2018-08-30 08:56:11 -04:00
|
|
|
|
end
|
2019-01-21 09:17:04 -05:00
|
|
|
|
|
|
|
|
|
def hex_to_rgbs(hex_color)
|
|
|
|
|
hex_color = hex_color.gsub('#', '')
|
|
|
|
|
rgbs = hex_color.scan(/../)
|
|
|
|
|
rgbs
|
|
|
|
|
.map! { |color| color.hex }
|
|
|
|
|
.map! { |rgb| rgb.to_i }
|
|
|
|
|
end
|
2013-02-27 22:39:42 -05:00
|
|
|
|
end
|
2019-03-29 05:54:56 -04:00
|
|
|
|
|
|
|
|
|
require_relative "reports/visits"
|
|
|
|
|
require_relative "reports/visits_mobile"
|
|
|
|
|
require_relative "reports/consolidated_page_views"
|
|
|
|
|
require_relative "reports/top_ignored_users"
|
|
|
|
|
require_relative "reports/top_uploads"
|
|
|
|
|
require_relative "reports/moderators_activity"
|
|
|
|
|
require_relative "reports/signups"
|
|
|
|
|
require_relative "reports/storage_stats"
|
|
|
|
|
require_relative "reports/suspicious_logins"
|
|
|
|
|
require_relative "reports/new_contributors"
|
|
|
|
|
require_relative "reports/users_by_trust_level"
|
|
|
|
|
require_relative "reports/staff_logins"
|
|
|
|
|
require_relative "reports/users_by_type"
|
|
|
|
|
require_relative "reports/user_flagging_ratio"
|
|
|
|
|
require_relative "reports/post_edits"
|
|
|
|
|
require_relative "reports/daily_engaged_users"
|
|
|
|
|
require_relative "reports/flags_status"
|
|
|
|
|
require_relative "reports/trending_search"
|
|
|
|
|
require_relative "reports/top_referrers"
|
|
|
|
|
require_relative "reports/top_traffic_sources"
|
|
|
|
|
require_relative "reports/top_referred_topics"
|
|
|
|
|
require_relative "reports/notify_user_private_messages"
|
|
|
|
|
require_relative "reports/user_to_user_private_messages"
|
|
|
|
|
require_relative "reports/user_to_user_private_messages_with_replies"
|
|
|
|
|
require_relative "reports/system_private_messages"
|
|
|
|
|
require_relative "reports/moderator_warning_private_messages"
|
|
|
|
|
require_relative "reports/notify_moderators_private_messages"
|
|
|
|
|
require_relative "reports/flags"
|
|
|
|
|
require_relative "reports/likes"
|
|
|
|
|
require_relative "reports/bookmarks"
|
|
|
|
|
require_relative "reports/dau_by_mau"
|
|
|
|
|
require_relative "reports/profile_views"
|
|
|
|
|
require_relative "reports/topics"
|
|
|
|
|
require_relative "reports/posts"
|
|
|
|
|
require_relative "reports/time_to_first_response"
|
|
|
|
|
require_relative "reports/topics_with_no_response"
|
|
|
|
|
require_relative "reports/emails"
|
2019-04-09 03:26:22 -04:00
|
|
|
|
require_relative "reports/web_crawlers"
|
2020-02-06 13:44:30 -05:00
|
|
|
|
require_relative "reports/trust_level_growth"
|