mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to app/*
This commit is contained in:
@@ -5,20 +5,20 @@ module Reports::Bookmarks
|
||||
|
||||
class_methods do
|
||||
def report_bookmarks(report)
|
||||
report.icon = 'bookmark'
|
||||
report.icon = "bookmark"
|
||||
|
||||
category_filter = report.filters.dig(:category)
|
||||
report.add_filter('category', default: category_filter)
|
||||
report.add_filter("category", default: category_filter)
|
||||
|
||||
report.data = []
|
||||
Bookmark.count_per_day(
|
||||
category_id: category_filter,
|
||||
start_date: report.start_date,
|
||||
end_date: report.end_date
|
||||
).each do |date, count|
|
||||
report.data << { x: date, y: count }
|
||||
end
|
||||
add_counts report, Bookmark, 'bookmarks.created_at'
|
||||
Bookmark
|
||||
.count_per_day(
|
||||
category_id: category_filter,
|
||||
start_date: report.start_date,
|
||||
end_date: report.end_date,
|
||||
)
|
||||
.each { |date, count| report.data << { x: date, y: count } }
|
||||
add_counts report, Bookmark, "bookmarks.created_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,29 +5,28 @@ module Reports::ConsolidatedApiRequests
|
||||
|
||||
class_methods do
|
||||
def report_consolidated_api_requests(report)
|
||||
filters = %w[
|
||||
api
|
||||
user_api
|
||||
]
|
||||
filters = %w[api user_api]
|
||||
|
||||
report.modes = [:stacked_chart]
|
||||
|
||||
tertiary = ColorScheme.hex_for_name('tertiary') || '0088cc'
|
||||
danger = ColorScheme.hex_for_name('danger') || 'e45735'
|
||||
tertiary = ColorScheme.hex_for_name("tertiary") || "0088cc"
|
||||
danger = ColorScheme.hex_for_name("danger") || "e45735"
|
||||
|
||||
requests = filters.map do |filter|
|
||||
color = filter == "api" ? report.rgba_color(tertiary) : report.rgba_color(danger)
|
||||
requests =
|
||||
filters.map do |filter|
|
||||
color = filter == "api" ? report.rgba_color(tertiary) : report.rgba_color(danger)
|
||||
|
||||
{
|
||||
req: filter,
|
||||
label: I18n.t("reports.consolidated_api_requests.xaxis.#{filter}"),
|
||||
color: color,
|
||||
data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
|
||||
}
|
||||
end
|
||||
{
|
||||
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)
|
||||
request[:data] = request[:data]
|
||||
.where("date >= ? AND date <= ?", report.start_date, report.end_date)
|
||||
.order(date: :asc)
|
||||
.group(:date)
|
||||
.sum(:count)
|
||||
|
||||
@@ -5,38 +5,32 @@ module Reports::ConsolidatedPageViews
|
||||
|
||||
class_methods do
|
||||
def report_consolidated_page_views(report)
|
||||
filters = %w[
|
||||
page_view_logged_in
|
||||
page_view_anon
|
||||
page_view_crawler
|
||||
]
|
||||
filters = %w[page_view_logged_in page_view_anon page_view_crawler]
|
||||
|
||||
report.modes = [:stacked_chart]
|
||||
|
||||
tertiary = ColorScheme.hex_for_name('tertiary') || '0088cc'
|
||||
danger = ColorScheme.hex_for_name('danger') || 'e45735'
|
||||
tertiary = ColorScheme.hex_for_name("tertiary") || "0088cc"
|
||||
danger = ColorScheme.hex_for_name("danger") || "e45735"
|
||||
|
||||
requests = filters.map do |filter|
|
||||
color = report.rgba_color(tertiary)
|
||||
requests =
|
||||
filters.map do |filter|
|
||||
color = report.rgba_color(tertiary)
|
||||
|
||||
if filter == "page_view_anon"
|
||||
color = report.lighten_color(tertiary, 0.25)
|
||||
color = report.lighten_color(tertiary, 0.25) if filter == "page_view_anon"
|
||||
|
||||
color = report.rgba_color(danger, 0.75) if filter == "page_view_crawler"
|
||||
|
||||
{
|
||||
req: filter,
|
||||
label: I18n.t("reports.consolidated_page_views.xaxis.#{filter}"),
|
||||
color: color,
|
||||
data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]),
|
||||
}
|
||||
end
|
||||
|
||||
if filter == "page_view_crawler"
|
||||
color = report.rgba_color(danger, 0.75)
|
||||
end
|
||||
|
||||
{
|
||||
req: filter,
|
||||
label: I18n.t("reports.consolidated_page_views.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)
|
||||
request[:data] = request[:data]
|
||||
.where("date >= ? AND date <= ?", report.start_date, report.end_date)
|
||||
.order(date: :asc)
|
||||
.group(:date)
|
||||
.sum(:count)
|
||||
|
||||
@@ -12,27 +12,23 @@ module Reports::DailyEngagedUsers
|
||||
data = UserAction.count_daily_engaged_users(report.start_date, report.end_date)
|
||||
|
||||
if report.facets.include?(:prev30Days)
|
||||
prev30DaysData = UserAction.count_daily_engaged_users(report.start_date - 30.days, report.start_date)
|
||||
prev30DaysData =
|
||||
UserAction.count_daily_engaged_users(report.start_date - 30.days, report.start_date)
|
||||
report.prev30Days = prev30DaysData.sum { |k, v| v }
|
||||
end
|
||||
|
||||
if report.facets.include?(:total)
|
||||
report.total = UserAction.count_daily_engaged_users
|
||||
end
|
||||
report.total = UserAction.count_daily_engaged_users if report.facets.include?(:total)
|
||||
|
||||
if report.facets.include?(:prev_period)
|
||||
prev_data = UserAction.count_daily_engaged_users(report.prev_start_date, report.prev_end_date)
|
||||
prev_data =
|
||||
UserAction.count_daily_engaged_users(report.prev_start_date, report.prev_end_date)
|
||||
|
||||
prev = prev_data.sum { |k, v| v }
|
||||
if prev > 0
|
||||
prev = prev / ((report.end_date - report.start_date) / 1.day)
|
||||
end
|
||||
prev = prev / ((report.end_date - report.start_date) / 1.day) if prev > 0
|
||||
report.prev_period = prev
|
||||
end
|
||||
|
||||
data.each do |key, value|
|
||||
report.data << { x: key, y: value }
|
||||
end
|
||||
data.each { |key, value| report.data << { x: key, y: value } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,16 +6,8 @@ module Reports::DauByMau
|
||||
class_methods do
|
||||
def report_dau_by_mau(report)
|
||||
report.labels = [
|
||||
{
|
||||
type: :date,
|
||||
property: :x,
|
||||
title: I18n.t("reports.default.labels.day")
|
||||
},
|
||||
{
|
||||
type: :percent,
|
||||
property: :y,
|
||||
title: I18n.t("reports.default.labels.percent")
|
||||
},
|
||||
{ type: :date, property: :x, title: I18n.t("reports.default.labels.day") },
|
||||
{ type: :percent, property: :y, title: I18n.t("reports.default.labels.percent") },
|
||||
]
|
||||
|
||||
report.average = true
|
||||
@@ -25,21 +17,23 @@ module Reports::DauByMau
|
||||
|
||||
report.data = []
|
||||
|
||||
compute_dau_by_mau = Proc.new { |data_point|
|
||||
if data_point["mau"] == 0
|
||||
0
|
||||
else
|
||||
((data_point["dau"].to_f / data_point["mau"].to_f) * 100).ceil(2)
|
||||
compute_dau_by_mau =
|
||||
Proc.new do |data_point|
|
||||
if data_point["mau"] == 0
|
||||
0
|
||||
else
|
||||
((data_point["dau"].to_f / data_point["mau"].to_f) * 100).ceil(2)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
dau_avg = Proc.new { |start_date, end_date|
|
||||
data_points = UserVisit.count_by_active_users(start_date, end_date)
|
||||
if !data_points.empty?
|
||||
sum = data_points.sum { |data_point| compute_dau_by_mau.call(data_point) }
|
||||
(sum.to_f / data_points.count.to_f).ceil(2)
|
||||
dau_avg =
|
||||
Proc.new do |start_date, end_date|
|
||||
data_points = UserVisit.count_by_active_users(start_date, end_date)
|
||||
if !data_points.empty?
|
||||
sum = data_points.sum { |data_point| compute_dau_by_mau.call(data_point) }
|
||||
(sum.to_f / data_points.count.to_f).ceil(2)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
data_points.each do |data_point|
|
||||
report.data << { x: data_point["date"], y: compute_dau_by_mau.call(data_point) }
|
||||
|
||||
@@ -7,7 +7,7 @@ module Reports::Flags
|
||||
def report_flags(report)
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
|
||||
report.icon = 'flag'
|
||||
report.icon = "flag"
|
||||
report.higher_is_better = false
|
||||
|
||||
basic_report_about(
|
||||
@@ -17,20 +17,21 @@ module Reports::Flags
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
category_id,
|
||||
include_subcategories
|
||||
include_subcategories,
|
||||
)
|
||||
|
||||
countable = ReviewableFlaggedPost.scores_with_topics
|
||||
|
||||
if category_id
|
||||
if include_subcategories
|
||||
countable = countable.where('topics.category_id IN (?)', Category.subcategory_ids(category_id))
|
||||
countable =
|
||||
countable.where("topics.category_id IN (?)", Category.subcategory_ids(category_id))
|
||||
else
|
||||
countable = countable.where('topics.category_id = ?', category_id)
|
||||
countable = countable.where("topics.category_id = ?", category_id)
|
||||
end
|
||||
end
|
||||
|
||||
add_counts report, countable, 'reviewable_scores.created_at'
|
||||
add_counts report, countable, "reviewable_scores.created_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,42 +13,42 @@ module Reports::FlagsStatus
|
||||
properties: {
|
||||
topic_id: :topic_id,
|
||||
number: :post_number,
|
||||
truncated_raw: :post_type
|
||||
truncated_raw: :post_type,
|
||||
},
|
||||
title: I18n.t("reports.flags_status.labels.flag")
|
||||
title: I18n.t("reports.flags_status.labels.flag"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
properties: {
|
||||
username: :staff_username,
|
||||
id: :staff_id,
|
||||
avatar: :staff_avatar_template
|
||||
avatar: :staff_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.flags_status.labels.assigned")
|
||||
title: I18n.t("reports.flags_status.labels.assigned"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
properties: {
|
||||
username: :poster_username,
|
||||
id: :poster_id,
|
||||
avatar: :poster_avatar_template
|
||||
avatar: :poster_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.flags_status.labels.poster")
|
||||
title: I18n.t("reports.flags_status.labels.poster"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
properties: {
|
||||
username: :flagger_username,
|
||||
id: :flagger_id,
|
||||
avatar: :flagger_avatar_template
|
||||
},
|
||||
title: I18n.t("reports.flags_status.labels.flagger")
|
||||
avatar: :flagger_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.flags_status.labels.flagger"),
|
||||
},
|
||||
{
|
||||
type: :seconds,
|
||||
property: :response_time,
|
||||
title: I18n.t("reports.flags_status.labels.time_to_resolution")
|
||||
}
|
||||
title: I18n.t("reports.flags_status.labels.time_to_resolution"),
|
||||
},
|
||||
]
|
||||
|
||||
report.data = []
|
||||
@@ -70,7 +70,7 @@ module Reports::FlagsStatus
|
||||
user_id,
|
||||
COALESCE(disagreed_at, agreed_at, deferred_at) AS responded_at
|
||||
FROM post_actions
|
||||
WHERE post_action_type_id IN (#{flag_types.values.join(',')})
|
||||
WHERE post_action_type_id IN (#{flag_types.values.join(",")})
|
||||
AND created_at >= '#{report.start_date}'
|
||||
AND created_at <= '#{report.end_date}'
|
||||
ORDER BY created_at DESC
|
||||
@@ -136,43 +136,54 @@ module Reports::FlagsStatus
|
||||
ON pd.id = pa.id
|
||||
SQL
|
||||
|
||||
DB.query(sql).each do |row|
|
||||
data = {}
|
||||
DB
|
||||
.query(sql)
|
||||
.each do |row|
|
||||
data = {}
|
||||
|
||||
data[:post_type] = flag_types.key(row.post_action_type_id).to_s
|
||||
data[:post_number] = row.post_number
|
||||
data[:topic_id] = row.topic_id
|
||||
data[:post_type] = flag_types.key(row.post_action_type_id).to_s
|
||||
data[:post_number] = row.post_number
|
||||
data[:topic_id] = row.topic_id
|
||||
|
||||
if row.staff_id
|
||||
data[:staff_username] = row.staff_username
|
||||
data[:staff_id] = row.staff_id
|
||||
data[:staff_avatar_template] = User.avatar_template(row.staff_username, row.staff_avatar_id)
|
||||
if row.staff_id
|
||||
data[:staff_username] = row.staff_username
|
||||
data[:staff_id] = row.staff_id
|
||||
data[:staff_avatar_template] = User.avatar_template(
|
||||
row.staff_username,
|
||||
row.staff_avatar_id,
|
||||
)
|
||||
end
|
||||
|
||||
if row.poster_id
|
||||
data[:poster_username] = row.poster_username
|
||||
data[:poster_id] = row.poster_id
|
||||
data[:poster_avatar_template] = User.avatar_template(
|
||||
row.poster_username,
|
||||
row.poster_avatar_id,
|
||||
)
|
||||
end
|
||||
|
||||
if row.flagger_id
|
||||
data[:flagger_id] = row.flagger_id
|
||||
data[:flagger_username] = row.flagger_username
|
||||
data[:flagger_avatar_template] = User.avatar_template(
|
||||
row.flagger_username,
|
||||
row.flagger_avatar_id,
|
||||
)
|
||||
end
|
||||
|
||||
if row.agreed_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.agreed")
|
||||
elsif row.disagreed_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.disagreed")
|
||||
elsif row.deferred_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.deferred")
|
||||
else
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.no_action")
|
||||
end
|
||||
data[:response_time] = row.responded_at ? row.responded_at - row.created_at : nil
|
||||
report.data << data
|
||||
end
|
||||
|
||||
if row.poster_id
|
||||
data[:poster_username] = row.poster_username
|
||||
data[:poster_id] = row.poster_id
|
||||
data[:poster_avatar_template] = User.avatar_template(row.poster_username, row.poster_avatar_id)
|
||||
end
|
||||
|
||||
if row.flagger_id
|
||||
data[:flagger_id] = row.flagger_id
|
||||
data[:flagger_username] = row.flagger_username
|
||||
data[:flagger_avatar_template] = User.avatar_template(row.flagger_username, row.flagger_avatar_id)
|
||||
end
|
||||
|
||||
if row.agreed_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.agreed")
|
||||
elsif row.disagreed_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.disagreed")
|
||||
elsif row.deferred_by_id
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.deferred")
|
||||
else
|
||||
data[:resolution] = I18n.t("reports.flags_status.values.no_action")
|
||||
end
|
||||
data[:response_time] = row.responded_at ? row.responded_at - row.created_at : nil
|
||||
report.data << data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::Likes
|
||||
|
||||
class_methods do
|
||||
def report_likes(report)
|
||||
report.icon = 'heart'
|
||||
report.icon = "heart"
|
||||
|
||||
post_action_report report, PostActionType.types[:like]
|
||||
end
|
||||
|
||||
@@ -7,7 +7,15 @@ module Reports::MobileVisits
|
||||
def report_mobile_visits(report)
|
||||
basic_report_about report, UserVisit, :mobile_by_day, report.start_date, report.end_date
|
||||
report.total = UserVisit.where(mobile: true).count
|
||||
report.prev30Days = UserVisit.where(mobile: true).where("visited_at >= ? and visited_at < ?", report.start_date - 30.days, report.start_date).count
|
||||
report.prev30Days =
|
||||
UserVisit
|
||||
.where(mobile: true)
|
||||
.where(
|
||||
"visited_at >= ? and visited_at < ?",
|
||||
report.start_date - 30.days,
|
||||
report.start_date,
|
||||
)
|
||||
.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::ModeratorWarningPrivateMessages
|
||||
|
||||
class_methods do
|
||||
def report_moderator_warning_private_messages(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
private_messages_report report, TopicSubtype.moderator_warning
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,33 +18,33 @@ module Reports::ModeratorsActivity
|
||||
{
|
||||
property: :flag_count,
|
||||
type: :number,
|
||||
title: I18n.t("reports.moderators_activity.labels.flag_count")
|
||||
title: I18n.t("reports.moderators_activity.labels.flag_count"),
|
||||
},
|
||||
{
|
||||
type: :seconds,
|
||||
property: :time_read,
|
||||
title: I18n.t("reports.moderators_activity.labels.time_read")
|
||||
title: I18n.t("reports.moderators_activity.labels.time_read"),
|
||||
},
|
||||
{
|
||||
property: :topic_count,
|
||||
type: :number,
|
||||
title: I18n.t("reports.moderators_activity.labels.topic_count")
|
||||
title: I18n.t("reports.moderators_activity.labels.topic_count"),
|
||||
},
|
||||
{
|
||||
property: :pm_count,
|
||||
type: :number,
|
||||
title: I18n.t("reports.moderators_activity.labels.pm_count")
|
||||
title: I18n.t("reports.moderators_activity.labels.pm_count"),
|
||||
},
|
||||
{
|
||||
property: :post_count,
|
||||
type: :number,
|
||||
title: I18n.t("reports.moderators_activity.labels.post_count")
|
||||
title: I18n.t("reports.moderators_activity.labels.post_count"),
|
||||
},
|
||||
{
|
||||
property: :revision_count,
|
||||
type: :number,
|
||||
title: I18n.t("reports.moderators_activity.labels.revision_count")
|
||||
}
|
||||
title: I18n.t("reports.moderators_activity.labels.revision_count"),
|
||||
},
|
||||
]
|
||||
|
||||
report.modes = [:table]
|
||||
@@ -75,7 +75,7 @@ module Reports::ModeratorsActivity
|
||||
SELECT agreed_by_id,
|
||||
disagreed_by_id
|
||||
FROM post_actions
|
||||
WHERE post_action_type_id IN (#{PostActionType.flag_types_without_custom.values.join(',')})
|
||||
WHERE post_action_type_id IN (#{PostActionType.flag_types_without_custom.values.join(",")})
|
||||
AND created_at >= '#{report.start_date}'
|
||||
AND created_at <= '#{report.end_date}'
|
||||
),
|
||||
@@ -173,19 +173,21 @@ module Reports::ModeratorsActivity
|
||||
ORDER BY m.username
|
||||
SQL
|
||||
|
||||
DB.query(query).each do |row|
|
||||
mod = {}
|
||||
mod[:username] = row.username
|
||||
mod[:user_id] = row.user_id
|
||||
mod[:user_avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
mod[:time_read] = row.time_read
|
||||
mod[:flag_count] = row.flag_count
|
||||
mod[:revision_count] = row.revision_count
|
||||
mod[:topic_count] = row.topic_count
|
||||
mod[:post_count] = row.post_count
|
||||
mod[:pm_count] = row.pm_count
|
||||
report.data << mod
|
||||
end
|
||||
DB
|
||||
.query(query)
|
||||
.each do |row|
|
||||
mod = {}
|
||||
mod[:username] = row.username
|
||||
mod[:user_id] = row.user_id
|
||||
mod[:user_avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
mod[:time_read] = row.time_read
|
||||
mod[:flag_count] = row.flag_count
|
||||
mod[:revision_count] = row.revision_count
|
||||
mod[:topic_count] = row.topic_count
|
||||
mod[:post_count] = row.post_count
|
||||
mod[:pm_count] = row.pm_count
|
||||
report.data << mod
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,23 +10,21 @@ module Reports::NewContributors
|
||||
data = User.real.count_by_first_post(report.start_date, report.end_date)
|
||||
|
||||
if report.facets.include?(:prev30Days)
|
||||
prev30DaysData = User.real.count_by_first_post(report.start_date - 30.days, report.start_date)
|
||||
prev30DaysData =
|
||||
User.real.count_by_first_post(report.start_date - 30.days, report.start_date)
|
||||
report.prev30Days = prev30DaysData.sum { |k, v| v }
|
||||
end
|
||||
|
||||
if report.facets.include?(:total)
|
||||
report.total = User.real.count_by_first_post
|
||||
end
|
||||
report.total = User.real.count_by_first_post if report.facets.include?(:total)
|
||||
|
||||
if report.facets.include?(:prev_period)
|
||||
prev_period_data = User.real.count_by_first_post(report.prev_start_date, report.prev_end_date)
|
||||
prev_period_data =
|
||||
User.real.count_by_first_post(report.prev_start_date, report.prev_end_date)
|
||||
report.prev_period = prev_period_data.sum { |k, v| v }
|
||||
# report.prev_data = prev_period_data.map { |k, v| { x: k, y: v } }
|
||||
end
|
||||
|
||||
data.each do |key, value|
|
||||
report.data << { x: key, y: value }
|
||||
end
|
||||
data.each { |key, value| report.data << { x: key, y: value } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::NotifyModeratorsPrivateMessages
|
||||
|
||||
class_methods do
|
||||
def report_notify_moderators_private_messages(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
private_messages_report report, TopicSubtype.notify_moderators
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::NotifyUserPrivateMessages
|
||||
|
||||
class_methods do
|
||||
def report_notify_user_private_messages(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
private_messages_report report, TopicSubtype.notify_user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ module Reports::PostEdits
|
||||
class_methods do
|
||||
def report_post_edits(report)
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
editor_username = report.filters['editor']
|
||||
editor_username = report.filters["editor"]
|
||||
|
||||
report.modes = [:table]
|
||||
|
||||
@@ -14,16 +14,16 @@ module Reports::PostEdits
|
||||
{
|
||||
type: :date,
|
||||
property: :created_at,
|
||||
title: I18n.t("reports.post_edits.labels.edited_at")
|
||||
title: I18n.t("reports.post_edits.labels.edited_at"),
|
||||
},
|
||||
{
|
||||
type: :post,
|
||||
properties: {
|
||||
topic_id: :topic_id,
|
||||
number: :post_number,
|
||||
truncated_raw: :post_raw
|
||||
truncated_raw: :post_raw,
|
||||
},
|
||||
title: I18n.t("reports.post_edits.labels.post")
|
||||
title: I18n.t("reports.post_edits.labels.post"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
@@ -32,7 +32,7 @@ module Reports::PostEdits
|
||||
id: :editor_id,
|
||||
avatar: :editor_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.post_edits.labels.editor")
|
||||
title: I18n.t("reports.post_edits.labels.editor"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
@@ -41,12 +41,12 @@ module Reports::PostEdits
|
||||
id: :author_id,
|
||||
avatar: :author_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.post_edits.labels.author")
|
||||
title: I18n.t("reports.post_edits.labels.author"),
|
||||
},
|
||||
{
|
||||
type: :text,
|
||||
property: :edit_reason,
|
||||
title: I18n.t("reports.post_edits.labels.edit_reason")
|
||||
title: I18n.t("reports.post_edits.labels.edit_reason"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -105,10 +105,16 @@ module Reports::PostEdits
|
||||
revision = {}
|
||||
revision[:editor_id] = r.editor_id
|
||||
revision[:editor_username] = r.editor_username
|
||||
revision[:editor_avatar_template] = User.avatar_template(r.editor_username, r.editor_avatar_id)
|
||||
revision[:editor_avatar_template] = User.avatar_template(
|
||||
r.editor_username,
|
||||
r.editor_avatar_id,
|
||||
)
|
||||
revision[:author_id] = r.author_id
|
||||
revision[:author_username] = r.author_username
|
||||
revision[:author_avatar_template] = User.avatar_template(r.author_username, r.author_avatar_id)
|
||||
revision[:author_avatar_template] = User.avatar_template(
|
||||
r.author_username,
|
||||
r.author_avatar_id,
|
||||
)
|
||||
revision[:edit_reason] = r.revision_version == r.post_version ? r.edit_reason : nil
|
||||
revision[:created_at] = r.created_at
|
||||
revision[:post_raw] = r.post_raw
|
||||
|
||||
@@ -5,22 +5,32 @@ module Reports::Posts
|
||||
|
||||
class_methods do
|
||||
def report_posts(report)
|
||||
report.modes = [:table, :chart]
|
||||
report.modes = %i[table chart]
|
||||
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
|
||||
basic_report_about report, Post, :public_posts_count_per_day, report.start_date, report.end_date, category_id, include_subcategories
|
||||
basic_report_about report,
|
||||
Post,
|
||||
:public_posts_count_per_day,
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
category_id,
|
||||
include_subcategories
|
||||
|
||||
countable = Post.public_posts.where(post_type: Post.types[:regular])
|
||||
if category_id
|
||||
if include_subcategories
|
||||
countable = countable.joins(:topic).where('topics.category_id IN (?)', Category.subcategory_ids(category_id))
|
||||
countable =
|
||||
countable.joins(:topic).where(
|
||||
"topics.category_id IN (?)",
|
||||
Category.subcategory_ids(category_id),
|
||||
)
|
||||
else
|
||||
countable = countable.joins(:topic).where('topics.category_id = ?', category_id)
|
||||
countable = countable.joins(:topic).where("topics.category_id = ?", category_id)
|
||||
end
|
||||
end
|
||||
|
||||
add_counts report, countable, 'posts.created_at'
|
||||
add_counts report, countable, "posts.created_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,14 +6,24 @@ module Reports::ProfileViews
|
||||
class_methods do
|
||||
def report_profile_views(report)
|
||||
group_filter = report.filters.dig(:group)
|
||||
report.add_filter('group', type: 'group', default: group_filter)
|
||||
report.add_filter("group", type: "group", default: group_filter)
|
||||
|
||||
start_date = report.start_date
|
||||
end_date = report.end_date
|
||||
basic_report_about report, UserProfileView, :profile_views_by_day, start_date, end_date, group_filter
|
||||
basic_report_about report,
|
||||
UserProfileView,
|
||||
:profile_views_by_day,
|
||||
start_date,
|
||||
end_date,
|
||||
group_filter
|
||||
|
||||
report.total = UserProfile.sum(:views)
|
||||
report.prev30Days = UserProfileView.where('viewed_at >= ? AND viewed_at < ?', start_date - 30.days, start_date + 1).count
|
||||
report.prev30Days =
|
||||
UserProfileView.where(
|
||||
"viewed_at >= ? AND viewed_at < ?",
|
||||
start_date - 30.days,
|
||||
start_date + 1,
|
||||
).count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,14 +5,19 @@ module Reports::Signups
|
||||
|
||||
class_methods do
|
||||
def report_signups(report)
|
||||
report.icon = 'user-plus'
|
||||
report.icon = "user-plus"
|
||||
|
||||
group_filter = report.filters.dig(:group)
|
||||
report.add_filter('group', type: 'group', default: group_filter)
|
||||
report.add_filter("group", type: "group", default: group_filter)
|
||||
|
||||
if group_filter
|
||||
basic_report_about report, User.real, :count_by_signup_date, report.start_date, report.end_date, group_filter
|
||||
add_counts report, User.real, 'users.created_at'
|
||||
basic_report_about report,
|
||||
User.real,
|
||||
:count_by_signup_date,
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
group_filter
|
||||
add_counts report, User.real, "users.created_at"
|
||||
else
|
||||
report_about report, User.real, :count_by_signup_date
|
||||
end
|
||||
|
||||
@@ -17,17 +17,14 @@ module Reports::StaffLogins
|
||||
id: :user_id,
|
||||
avatar: :avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.staff_logins.labels.user")
|
||||
},
|
||||
{
|
||||
property: :location,
|
||||
title: I18n.t("reports.staff_logins.labels.location")
|
||||
title: I18n.t("reports.staff_logins.labels.user"),
|
||||
},
|
||||
{ property: :location, title: I18n.t("reports.staff_logins.labels.location") },
|
||||
{
|
||||
property: :created_at,
|
||||
type: :precise_date,
|
||||
title: I18n.t("reports.staff_logins.labels.login_at")
|
||||
}
|
||||
title: I18n.t("reports.staff_logins.labels.login_at"),
|
||||
},
|
||||
]
|
||||
|
||||
sql = <<~SQL
|
||||
@@ -40,7 +37,7 @@ module Reports::StaffLogins
|
||||
FROM (
|
||||
SELECT DISTINCT ON (t.client_ip, t.user_id) t.client_ip, t.user_id, t.created_at
|
||||
FROM user_auth_token_logs t
|
||||
WHERE t.user_id IN (#{User.admins.pluck(:id).join(',')})
|
||||
WHERE t.user_id IN (#{User.admins.pluck(:id).join(",")})
|
||||
AND t.created_at >= :start_date
|
||||
AND t.created_at <= :end_date
|
||||
ORDER BY t.client_ip, t.user_id, t.created_at DESC
|
||||
@@ -50,16 +47,18 @@ module Reports::StaffLogins
|
||||
ORDER BY created_at DESC
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
data = {}
|
||||
data[:avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
data[:user_id] = row.user_id
|
||||
data[:username] = row.username
|
||||
data[:location] = DiscourseIpInfo.get(row.client_ip)[:location]
|
||||
data[:created_at] = row.created_at
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
data = {}
|
||||
data[:avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
data[:user_id] = row.user_id
|
||||
data[:username] = row.username
|
||||
data[:location] = DiscourseIpInfo.get(row.client_ip)[:location]
|
||||
data[:created_at] = row.created_at
|
||||
|
||||
report.data << data
|
||||
end
|
||||
report.data << data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,18 +5,19 @@ module Reports::StorageStats
|
||||
|
||||
class_methods do
|
||||
def report_storage_stats(report)
|
||||
backup_stats = begin
|
||||
BackupRestore::BackupStore.create.stats
|
||||
rescue BackupRestore::BackupStore::StorageError
|
||||
nil
|
||||
end
|
||||
backup_stats =
|
||||
begin
|
||||
BackupRestore::BackupStore.create.stats
|
||||
rescue BackupRestore::BackupStore::StorageError
|
||||
nil
|
||||
end
|
||||
|
||||
report.data = {
|
||||
backups: backup_stats,
|
||||
uploads: {
|
||||
used_bytes: DiskSpace.uploads_used_bytes,
|
||||
free_bytes: DiskSpace.uploads_free_bytes
|
||||
}
|
||||
free_bytes: DiskSpace.uploads_free_bytes,
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,32 +15,17 @@ module Reports::SuspiciousLogins
|
||||
id: :user_id,
|
||||
avatar: :avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.suspicious_logins.labels.user")
|
||||
},
|
||||
{
|
||||
property: :client_ip,
|
||||
title: I18n.t("reports.suspicious_logins.labels.client_ip")
|
||||
},
|
||||
{
|
||||
property: :location,
|
||||
title: I18n.t("reports.suspicious_logins.labels.location")
|
||||
},
|
||||
{
|
||||
property: :browser,
|
||||
title: I18n.t("reports.suspicious_logins.labels.browser")
|
||||
},
|
||||
{
|
||||
property: :device,
|
||||
title: I18n.t("reports.suspicious_logins.labels.device")
|
||||
},
|
||||
{
|
||||
property: :os,
|
||||
title: I18n.t("reports.suspicious_logins.labels.os")
|
||||
title: I18n.t("reports.suspicious_logins.labels.user"),
|
||||
},
|
||||
{ property: :client_ip, title: I18n.t("reports.suspicious_logins.labels.client_ip") },
|
||||
{ property: :location, title: I18n.t("reports.suspicious_logins.labels.location") },
|
||||
{ property: :browser, title: I18n.t("reports.suspicious_logins.labels.browser") },
|
||||
{ property: :device, title: I18n.t("reports.suspicious_logins.labels.device") },
|
||||
{ property: :os, title: I18n.t("reports.suspicious_logins.labels.os") },
|
||||
{
|
||||
type: :date,
|
||||
property: :login_time,
|
||||
title: I18n.t("reports.suspicious_logins.labels.login_time")
|
||||
title: I18n.t("reports.suspicious_logins.labels.login_time"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -56,26 +41,28 @@ module Reports::SuspiciousLogins
|
||||
ORDER BY t.created_at DESC
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
data = {}
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
data = {}
|
||||
|
||||
ipinfo = DiscourseIpInfo.get(row.client_ip)
|
||||
browser = BrowserDetection.browser(row.user_agent)
|
||||
device = BrowserDetection.device(row.user_agent)
|
||||
os = BrowserDetection.os(row.user_agent)
|
||||
ipinfo = DiscourseIpInfo.get(row.client_ip)
|
||||
browser = BrowserDetection.browser(row.user_agent)
|
||||
device = BrowserDetection.device(row.user_agent)
|
||||
os = BrowserDetection.os(row.user_agent)
|
||||
|
||||
data[:username] = row.username
|
||||
data[:user_id] = row.user_id
|
||||
data[:avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
data[:client_ip] = row.client_ip.to_s
|
||||
data[:location] = ipinfo[:location]
|
||||
data[:browser] = I18n.t("user_auth_tokens.browser.#{browser}")
|
||||
data[:device] = I18n.t("user_auth_tokens.device.#{device}")
|
||||
data[:os] = I18n.t("user_auth_tokens.os.#{os}")
|
||||
data[:login_time] = row.login_time
|
||||
data[:username] = row.username
|
||||
data[:user_id] = row.user_id
|
||||
data[:avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
data[:client_ip] = row.client_ip.to_s
|
||||
data[:location] = ipinfo[:location]
|
||||
data[:browser] = I18n.t("user_auth_tokens.browser.#{browser}")
|
||||
data[:device] = I18n.t("user_auth_tokens.device.#{device}")
|
||||
data[:os] = I18n.t("user_auth_tokens.os.#{os}")
|
||||
data[:login_time] = row.login_time
|
||||
|
||||
report.data << data
|
||||
end
|
||||
report.data << data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::SystemPrivateMessages
|
||||
|
||||
class_methods do
|
||||
def report_system_private_messages(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
private_messages_report report, TopicSubtype.system_message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,16 +8,27 @@ module Reports::TimeToFirstResponse
|
||||
category_filter = report.filters.dig(:category)
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
|
||||
report.icon = 'reply'
|
||||
report.icon = "reply"
|
||||
report.higher_is_better = false
|
||||
report.data = []
|
||||
report.average = true
|
||||
|
||||
Topic.time_to_first_response_per_day(report.start_date, report.end_date, category_id: category_id, include_subcategories: include_subcategories).each do |r|
|
||||
report.data << { x: r['date'], y: r['hours'].to_f.round(2) }
|
||||
end
|
||||
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) } }
|
||||
|
||||
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)
|
||||
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,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,22 +15,18 @@ module Reports::TopIgnoredUsers
|
||||
username: :ignored_username,
|
||||
avatar: :ignored_user_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_ignored_users.labels.ignored_user")
|
||||
title: I18n.t("reports.top_ignored_users.labels.ignored_user"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
properties: [
|
||||
:ignores_count,
|
||||
],
|
||||
title: I18n.t("reports.top_ignored_users.labels.ignores_count")
|
||||
properties: [:ignores_count],
|
||||
title: I18n.t("reports.top_ignored_users.labels.ignores_count"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
properties: [
|
||||
:mutes_count,
|
||||
],
|
||||
title: I18n.t("reports.top_ignored_users.labels.mutes_count")
|
||||
}
|
||||
properties: [:mutes_count],
|
||||
title: I18n.t("reports.top_ignored_users.labels.mutes_count"),
|
||||
},
|
||||
]
|
||||
|
||||
report.data = []
|
||||
@@ -69,15 +65,18 @@ module Reports::TopIgnoredUsers
|
||||
ORDER BY total DESC
|
||||
SQL
|
||||
|
||||
DB.query(sql, limit: report.limit || 250).each do |row|
|
||||
report.data << {
|
||||
ignored_user_id: row.user_id,
|
||||
ignored_username: row.username,
|
||||
ignored_user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
ignores_count: row.ignores_count,
|
||||
mutes_count: row.mutes_count,
|
||||
}
|
||||
end
|
||||
DB
|
||||
.query(sql, limit: report.limit || 250)
|
||||
.each do |row|
|
||||
report.data << {
|
||||
ignored_user_id: row.user_id,
|
||||
ignored_username: row.username,
|
||||
ignored_user_avatar_template:
|
||||
User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
ignores_count: row.ignores_count,
|
||||
mutes_count: row.mutes_count,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,15 +14,15 @@ module Reports::TopReferredTopics
|
||||
type: :topic,
|
||||
properties: {
|
||||
title: :topic_title,
|
||||
id: :topic_id
|
||||
id: :topic_id,
|
||||
},
|
||||
title: I18n.t('reports.top_referred_topics.labels.topic')
|
||||
title: I18n.t("reports.top_referred_topics.labels.topic"),
|
||||
},
|
||||
{
|
||||
property: :num_clicks,
|
||||
type: :number,
|
||||
title: I18n.t('reports.top_referred_topics.labels.num_clicks')
|
||||
}
|
||||
title: I18n.t("reports.top_referred_topics.labels.num_clicks"),
|
||||
},
|
||||
]
|
||||
|
||||
options = {
|
||||
@@ -30,7 +30,7 @@ module Reports::TopReferredTopics
|
||||
start_date: report.start_date,
|
||||
limit: report.limit || 8,
|
||||
category_id: category_id,
|
||||
include_subcategories: include_subcategories
|
||||
include_subcategories: include_subcategories,
|
||||
}
|
||||
result = nil
|
||||
result = IncomingLinksReport.find(:top_referred_topics, options)
|
||||
|
||||
@@ -15,24 +15,24 @@ module Reports::TopReferrers
|
||||
id: :user_id,
|
||||
avatar: :user_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_referrers.labels.user")
|
||||
title: I18n.t("reports.top_referrers.labels.user"),
|
||||
},
|
||||
{
|
||||
property: :num_clicks,
|
||||
type: :number,
|
||||
title: I18n.t("reports.top_referrers.labels.num_clicks")
|
||||
title: I18n.t("reports.top_referrers.labels.num_clicks"),
|
||||
},
|
||||
{
|
||||
property: :num_topics,
|
||||
type: :number,
|
||||
title: I18n.t("reports.top_referrers.labels.num_topics")
|
||||
}
|
||||
title: I18n.t("reports.top_referrers.labels.num_topics"),
|
||||
},
|
||||
]
|
||||
|
||||
options = {
|
||||
end_date: report.end_date,
|
||||
start_date: report.start_date,
|
||||
limit: report.limit || 8
|
||||
limit: report.limit || 8,
|
||||
}
|
||||
|
||||
result = IncomingLinksReport.find(:top_referrers, options)
|
||||
|
||||
@@ -10,20 +10,17 @@ module Reports::TopTrafficSources
|
||||
report.modes = [:table]
|
||||
|
||||
report.labels = [
|
||||
{
|
||||
property: :domain,
|
||||
title: I18n.t('reports.top_traffic_sources.labels.domain')
|
||||
},
|
||||
{ property: :domain, title: I18n.t("reports.top_traffic_sources.labels.domain") },
|
||||
{
|
||||
property: :num_clicks,
|
||||
type: :number,
|
||||
title: I18n.t('reports.top_traffic_sources.labels.num_clicks')
|
||||
title: I18n.t("reports.top_traffic_sources.labels.num_clicks"),
|
||||
},
|
||||
{
|
||||
property: :num_topics,
|
||||
type: :number,
|
||||
title: I18n.t('reports.top_traffic_sources.labels.num_topics')
|
||||
}
|
||||
title: I18n.t("reports.top_traffic_sources.labels.num_topics"),
|
||||
},
|
||||
]
|
||||
|
||||
options = {
|
||||
@@ -31,7 +28,7 @@ module Reports::TopTrafficSources
|
||||
start_date: report.start_date,
|
||||
limit: report.limit || 8,
|
||||
category_id: category_id,
|
||||
include_subcategories: include_subcategories
|
||||
include_subcategories: include_subcategories,
|
||||
}
|
||||
|
||||
result = IncomingLinksReport.find(:top_traffic_sources, options)
|
||||
|
||||
@@ -8,20 +8,18 @@ module Reports::TopUploads
|
||||
report.modes = [:table]
|
||||
|
||||
extension_filter = report.filters.dig(:file_extension)
|
||||
report.add_filter('file_extension',
|
||||
type: 'list',
|
||||
default: extension_filter || 'any',
|
||||
choices: (SiteSetting.authorized_extensions.split('|') + Array(extension_filter)).uniq
|
||||
report.add_filter(
|
||||
"file_extension",
|
||||
type: "list",
|
||||
default: extension_filter || "any",
|
||||
choices: (SiteSetting.authorized_extensions.split("|") + Array(extension_filter)).uniq,
|
||||
)
|
||||
|
||||
report.labels = [
|
||||
{
|
||||
type: :link,
|
||||
properties: [
|
||||
:file_url,
|
||||
:file_name,
|
||||
],
|
||||
title: I18n.t("reports.top_uploads.labels.filename")
|
||||
properties: %i[file_url file_name],
|
||||
title: I18n.t("reports.top_uploads.labels.filename"),
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
@@ -30,18 +28,14 @@ module Reports::TopUploads
|
||||
id: :author_id,
|
||||
avatar: :author_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_uploads.labels.author")
|
||||
title: I18n.t("reports.top_uploads.labels.author"),
|
||||
},
|
||||
{
|
||||
type: :text,
|
||||
property: :extension,
|
||||
title: I18n.t("reports.top_uploads.labels.extension")
|
||||
},
|
||||
{
|
||||
type: :bytes,
|
||||
property: :filesize,
|
||||
title: I18n.t("reports.top_uploads.labels.filesize")
|
||||
title: I18n.t("reports.top_uploads.labels.extension"),
|
||||
},
|
||||
{ type: :bytes, property: :filesize, title: I18n.t("reports.top_uploads.labels.filesize") },
|
||||
]
|
||||
|
||||
report.data = []
|
||||
@@ -64,12 +58,15 @@ module Reports::TopUploads
|
||||
SQL
|
||||
|
||||
builder = DB.build(sql)
|
||||
builder.where("up.id > :seeded_id_threshold", seeded_id_threshold: Upload::SEEDED_ID_THRESHOLD)
|
||||
builder.where(
|
||||
"up.id > :seeded_id_threshold",
|
||||
seeded_id_threshold: Upload::SEEDED_ID_THRESHOLD,
|
||||
)
|
||||
builder.where("up.created_at >= :start_date", start_date: report.start_date)
|
||||
builder.where("up.created_at < :end_date", end_date: report.end_date)
|
||||
|
||||
if extension_filter
|
||||
builder.where("up.extension = :extension", extension: extension_filter.sub(/^\./, ''))
|
||||
builder.where("up.extension = :extension", extension: extension_filter.sub(/^\./, ""))
|
||||
end
|
||||
|
||||
builder.query.each do |row|
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::TopUsersByLikesReceived
|
||||
|
||||
class_methods do
|
||||
def report_top_users_by_likes_received(report)
|
||||
report.icon = 'heart'
|
||||
report.icon = "heart"
|
||||
report.data = []
|
||||
|
||||
report.modes = [:table]
|
||||
@@ -20,12 +20,12 @@ module Reports::TopUsersByLikesReceived
|
||||
username: :username,
|
||||
avatar: :user_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_users_by_likes_received.labels.user")
|
||||
title: I18n.t("reports.top_users_by_likes_received.labels.user"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :qtt_like,
|
||||
title: I18n.t("reports.top_users_by_likes_received.labels.qtt_like")
|
||||
title: I18n.t("reports.top_users_by_likes_received.labels.qtt_like"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -44,15 +44,16 @@ module Reports::TopUsersByLikesReceived
|
||||
LIMIT 10
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::TopUsersByLikesReceivedFromAVarietyOfPeople
|
||||
|
||||
class_methods do
|
||||
def report_top_users_by_likes_received_from_a_variety_of_people(report)
|
||||
report.icon = 'heart'
|
||||
report.icon = "heart"
|
||||
report.data = []
|
||||
|
||||
report.modes = [:table]
|
||||
@@ -20,12 +20,13 @@ module Reports::TopUsersByLikesReceivedFromAVarietyOfPeople
|
||||
username: :username,
|
||||
avatar: :user_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_a_variety_of_people.labels.user")
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_a_variety_of_people.labels.user"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :qtt_like,
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_a_variety_of_people.labels.qtt_like")
|
||||
title:
|
||||
I18n.t("reports.top_users_by_likes_received_from_a_variety_of_people.labels.qtt_like"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -46,15 +47,16 @@ module Reports::TopUsersByLikesReceivedFromAVarietyOfPeople
|
||||
LIMIT 10
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::TopUsersByLikesReceivedFromInferiorTrustLevel
|
||||
|
||||
class_methods do
|
||||
def report_top_users_by_likes_received_from_inferior_trust_level(report)
|
||||
report.icon = 'heart'
|
||||
report.icon = "heart"
|
||||
report.data = []
|
||||
|
||||
report.modes = [:table]
|
||||
@@ -20,17 +20,22 @@ module Reports::TopUsersByLikesReceivedFromInferiorTrustLevel
|
||||
username: :username,
|
||||
avatar: :user_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_inferior_trust_level.labels.user")
|
||||
title:
|
||||
I18n.t("reports.top_users_by_likes_received_from_inferior_trust_level.labels.user"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :trust_level,
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_inferior_trust_level.labels.trust_level")
|
||||
title:
|
||||
I18n.t(
|
||||
"reports.top_users_by_likes_received_from_inferior_trust_level.labels.trust_level",
|
||||
),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :qtt_like,
|
||||
title: I18n.t("reports.top_users_by_likes_received_from_inferior_trust_level.labels.qtt_like")
|
||||
title:
|
||||
I18n.t("reports.top_users_by_likes_received_from_inferior_trust_level.labels.qtt_like"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -56,16 +61,17 @@ module Reports::TopUsersByLikesReceivedFromInferiorTrustLevel
|
||||
WHERE rank <= 10
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
trust_level: row.trust_level,
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
report.data << {
|
||||
user_id: row.user_id,
|
||||
username: row.username,
|
||||
user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
trust_level: row.trust_level,
|
||||
qtt_like: row.qtt_like,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,12 +7,21 @@ module Reports::Topics
|
||||
def report_topics(report)
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
|
||||
basic_report_about report, Topic, :listable_count_per_day, report.start_date, report.end_date, category_id, include_subcategories
|
||||
basic_report_about report,
|
||||
Topic,
|
||||
:listable_count_per_day,
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
category_id,
|
||||
include_subcategories
|
||||
|
||||
countable = Topic.listable_topics
|
||||
countable = countable.where(category_id: include_subcategories ? Category.subcategory_ids(category_id) : category_id) if category_id
|
||||
countable =
|
||||
countable.where(
|
||||
category_id: include_subcategories ? Category.subcategory_ids(category_id) : category_id,
|
||||
) if category_id
|
||||
|
||||
add_counts report, countable, 'topics.created_at'
|
||||
add_counts report, countable, "topics.created_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,13 +8,28 @@ module Reports::TopicsWithNoResponse
|
||||
category_id, include_subcategories = report.add_category_filter
|
||||
|
||||
report.data = []
|
||||
Topic.with_no_response_per_day(report.start_date, report.end_date, category_id, include_subcategories).each do |r|
|
||||
report.data << { x: r['date'], y: r['count'].to_i }
|
||||
end
|
||||
Topic
|
||||
.with_no_response_per_day(
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
category_id,
|
||||
include_subcategories,
|
||||
)
|
||||
.each { |r| report.data << { x: r["date"], y: r["count"].to_i } }
|
||||
|
||||
report.total = Topic.with_no_response_total(category_id: category_id, include_subcategories: include_subcategories)
|
||||
report.total =
|
||||
Topic.with_no_response_total(
|
||||
category_id: category_id,
|
||||
include_subcategories: include_subcategories,
|
||||
)
|
||||
|
||||
report.prev30Days = Topic.with_no_response_total(start_date: report.start_date - 30.days, end_date: report.start_date, category_id: category_id, include_subcategories: include_subcategories)
|
||||
report.prev30Days =
|
||||
Topic.with_no_response_total(
|
||||
start_date: report.start_date - 30.days,
|
||||
end_date: report.start_date,
|
||||
category_id: category_id,
|
||||
include_subcategories: include_subcategories,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,38 +6,28 @@ module Reports::TrendingSearch
|
||||
class_methods do
|
||||
def report_trending_search(report)
|
||||
report.labels = [
|
||||
{
|
||||
property: :term,
|
||||
type: :text,
|
||||
title: I18n.t("reports.trending_search.labels.term")
|
||||
},
|
||||
{ property: :term, type: :text, title: I18n.t("reports.trending_search.labels.term") },
|
||||
{
|
||||
property: :searches,
|
||||
type: :number,
|
||||
title: I18n.t("reports.trending_search.labels.searches")
|
||||
title: I18n.t("reports.trending_search.labels.searches"),
|
||||
},
|
||||
{
|
||||
type: :percent,
|
||||
property: :ctr,
|
||||
title: I18n.t("reports.trending_search.labels.click_through")
|
||||
}
|
||||
title: I18n.t("reports.trending_search.labels.click_through"),
|
||||
},
|
||||
]
|
||||
|
||||
report.data = []
|
||||
|
||||
report.modes = [:table]
|
||||
|
||||
trends = SearchLog.trending_from(report.start_date,
|
||||
end_date: report.end_date,
|
||||
limit: report.limit
|
||||
)
|
||||
trends =
|
||||
SearchLog.trending_from(report.start_date, end_date: report.end_date, limit: report.limit)
|
||||
|
||||
trends.each do |trend|
|
||||
report.data << {
|
||||
term: trend.term,
|
||||
searches: trend.searches,
|
||||
ctr: trend.ctr
|
||||
}
|
||||
report.data << { term: trend.term, searches: trend.searches, ctr: trend.ctr }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,12 +7,7 @@ module Reports::TrustLevelGrowth
|
||||
def report_trust_level_growth(report)
|
||||
report.modes = [:stacked_chart]
|
||||
|
||||
filters = %w[
|
||||
tl1_reached
|
||||
tl2_reached
|
||||
tl3_reached
|
||||
tl4_reached
|
||||
]
|
||||
filters = %w[tl1_reached tl2_reached tl3_reached tl4_reached]
|
||||
|
||||
sql = <<~SQL
|
||||
SELECT
|
||||
@@ -42,41 +37,36 @@ module Reports::TrustLevelGrowth
|
||||
ORDER BY date(created_at)
|
||||
SQL
|
||||
|
||||
data = Hash[ filters.collect { |x| [x, []] } ]
|
||||
data = Hash[filters.collect { |x| [x, []] }]
|
||||
|
||||
builder = DB.build(sql)
|
||||
builder.query.each do |row|
|
||||
filters.each do |filter|
|
||||
data[filter] << {
|
||||
x: row.date.strftime("%Y-%m-%d"),
|
||||
y: row.instance_variable_get("@#{filter}")
|
||||
y: row.instance_variable_get("@#{filter}"),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
tertiary = ColorScheme.hex_for_name('tertiary') || '0088cc'
|
||||
quaternary = ColorScheme.hex_for_name('quaternary') || 'e45735'
|
||||
tertiary = ColorScheme.hex_for_name("tertiary") || "0088cc"
|
||||
quaternary = ColorScheme.hex_for_name("quaternary") || "e45735"
|
||||
|
||||
requests = filters.map do |filter|
|
||||
color = report.rgba_color(quaternary)
|
||||
requests =
|
||||
filters.map do |filter|
|
||||
color = report.rgba_color(quaternary)
|
||||
|
||||
if filter == "tl1_reached"
|
||||
color = report.lighten_color(tertiary, 0.25)
|
||||
end
|
||||
if filter == "tl2_reached"
|
||||
color = report.rgba_color(tertiary)
|
||||
end
|
||||
if filter == "tl3_reached"
|
||||
color = report.lighten_color(quaternary, 0.25)
|
||||
end
|
||||
color = report.lighten_color(tertiary, 0.25) if filter == "tl1_reached"
|
||||
color = report.rgba_color(tertiary) if filter == "tl2_reached"
|
||||
color = report.lighten_color(quaternary, 0.25) if filter == "tl3_reached"
|
||||
|
||||
{
|
||||
req: filter,
|
||||
label: I18n.t("reports.trust_level_growth.xaxis.#{filter}"),
|
||||
color: color,
|
||||
data: data[filter]
|
||||
}
|
||||
end
|
||||
{
|
||||
req: filter,
|
||||
label: I18n.t("reports.trust_level_growth.xaxis.#{filter}"),
|
||||
color: color,
|
||||
data: data[filter],
|
||||
}
|
||||
end
|
||||
|
||||
report.data = requests
|
||||
end
|
||||
|
||||
@@ -19,27 +19,27 @@ module Reports::UserFlaggingRatio
|
||||
id: :user_id,
|
||||
avatar: :avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.user")
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.user"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :disagreed_flags,
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.disagreed_flags")
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.disagreed_flags"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :agreed_flags,
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.agreed_flags")
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.agreed_flags"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :ignored_flags,
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.ignored_flags")
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.ignored_flags"),
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
property: :score,
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.score")
|
||||
title: I18n.t("reports.user_flagging_ratio.labels.score"),
|
||||
},
|
||||
]
|
||||
|
||||
@@ -74,18 +74,20 @@ module Reports::UserFlaggingRatio
|
||||
LIMIT 100
|
||||
SQL
|
||||
|
||||
DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row|
|
||||
flagger = {}
|
||||
flagger[:user_id] = row.id
|
||||
flagger[:username] = row.username
|
||||
flagger[:avatar_template] = User.avatar_template(row.username, row.avatar_id)
|
||||
flagger[:disagreed_flags] = row.disagreed_flags
|
||||
flagger[:ignored_flags] = row.ignored_flags
|
||||
flagger[:agreed_flags] = row.agreed_flags
|
||||
flagger[:score] = row.score
|
||||
DB
|
||||
.query(sql, start_date: report.start_date, end_date: report.end_date)
|
||||
.each do |row|
|
||||
flagger = {}
|
||||
flagger[:user_id] = row.id
|
||||
flagger[:username] = row.username
|
||||
flagger[:avatar_template] = User.avatar_template(row.username, row.avatar_id)
|
||||
flagger[:disagreed_flags] = row.disagreed_flags
|
||||
flagger[:ignored_flags] = row.ignored_flags
|
||||
flagger[:agreed_flags] = row.agreed_flags
|
||||
flagger[:score] = row.score
|
||||
|
||||
report.data << flagger
|
||||
end
|
||||
report.data << flagger
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Reports::UserToUserPrivateMessages
|
||||
|
||||
class_methods do
|
||||
def report_user_to_user_private_messages(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
private_messages_report report, TopicSubtype.user_to_user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,12 +5,17 @@ module Reports::UserToUserPrivateMessagesWithReplies
|
||||
|
||||
class_methods do
|
||||
def report_user_to_user_private_messages_with_replies(report)
|
||||
report.icon = 'envelope'
|
||||
report.icon = "envelope"
|
||||
topic_subtype = TopicSubtype.user_to_user
|
||||
subject = Post.where('posts.user_id > 0')
|
||||
basic_report_about report, subject, :private_messages_count_per_day, report.start_date, report.end_date, topic_subtype
|
||||
subject = Post.private_posts.where('posts.user_id > 0').with_topic_subtype(topic_subtype)
|
||||
add_counts report, subject, 'posts.created_at'
|
||||
subject = Post.where("posts.user_id > 0")
|
||||
basic_report_about report,
|
||||
subject,
|
||||
:private_messages_count_per_day,
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
topic_subtype
|
||||
subject = Post.private_posts.where("posts.user_id > 0").with_topic_subtype(topic_subtype)
|
||||
add_counts report, subject, "posts.created_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,22 +12,20 @@ module Reports::UsersByTrustLevel
|
||||
report.dates_filtering = false
|
||||
|
||||
report.labels = [
|
||||
{
|
||||
property: :key,
|
||||
title: I18n.t("reports.users_by_trust_level.labels.level")
|
||||
},
|
||||
{
|
||||
property: :y,
|
||||
type: :number,
|
||||
title: I18n.t("reports.default.labels.count")
|
||||
}
|
||||
{ property: :key, title: I18n.t("reports.users_by_trust_level.labels.level") },
|
||||
{ property: :y, type: :number, title: I18n.t("reports.default.labels.count") },
|
||||
]
|
||||
|
||||
User.real.group('trust_level').count.sort.each do |level, count|
|
||||
key = TrustLevel.levels.key(level.to_i)
|
||||
url = Proc.new { |k| "/admin/users/list/#{k}" }
|
||||
report.data << { url: url.call(key), key: key, x: level.to_i, y: count }
|
||||
end
|
||||
User
|
||||
.real
|
||||
.group("trust_level")
|
||||
.count
|
||||
.sort
|
||||
.each do |level, count|
|
||||
key = TrustLevel.levels.key(level.to_i)
|
||||
url = Proc.new { |k| "/admin/users/list/#{k}" }
|
||||
report.data << { url: url.call(key), key: key, x: level.to_i, y: count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,31 +12,56 @@ module Reports::UsersByType
|
||||
report.dates_filtering = false
|
||||
|
||||
report.labels = [
|
||||
{
|
||||
property: :x,
|
||||
title: I18n.t("reports.users_by_type.labels.type")
|
||||
},
|
||||
{
|
||||
property: :y,
|
||||
type: :number,
|
||||
title: I18n.t("reports.default.labels.count")
|
||||
}
|
||||
{ property: :x, title: I18n.t("reports.users_by_type.labels.type") },
|
||||
{ property: :y, type: :number, title: I18n.t("reports.default.labels.count") },
|
||||
]
|
||||
|
||||
label = Proc.new { |x| I18n.t("reports.users_by_type.xaxis_labels.#{x}") }
|
||||
url = Proc.new { |key| "/admin/users/list/#{key}" }
|
||||
|
||||
admins = User.real.admins.count
|
||||
report.data << { url: url.call("admins"), icon: "shield-alt", key: "admins", x: label.call("admin"), y: admins } if admins > 0
|
||||
if admins > 0
|
||||
report.data << {
|
||||
url: url.call("admins"),
|
||||
icon: "shield-alt",
|
||||
key: "admins",
|
||||
x: label.call("admin"),
|
||||
y: admins,
|
||||
}
|
||||
end
|
||||
|
||||
moderators = User.real.moderators.count
|
||||
report.data << { url: url.call("moderators"), icon: "shield-alt", key: "moderators", x: label.call("moderator"), y: moderators } if moderators > 0
|
||||
if moderators > 0
|
||||
report.data << {
|
||||
url: url.call("moderators"),
|
||||
icon: "shield-alt",
|
||||
key: "moderators",
|
||||
x: label.call("moderator"),
|
||||
y: moderators,
|
||||
}
|
||||
end
|
||||
|
||||
suspended = User.real.suspended.count
|
||||
report.data << { url: url.call("suspended"), icon: "ban", key: "suspended", x: label.call("suspended"), y: suspended } if suspended > 0
|
||||
if suspended > 0
|
||||
report.data << {
|
||||
url: url.call("suspended"),
|
||||
icon: "ban",
|
||||
key: "suspended",
|
||||
x: label.call("suspended"),
|
||||
y: suspended,
|
||||
}
|
||||
end
|
||||
|
||||
silenced = User.real.silenced.count
|
||||
report.data << { url: url.call("silenced"), icon: "ban", key: "silenced", x: label.call("silenced"), y: silenced } if silenced > 0
|
||||
if silenced > 0
|
||||
report.data << {
|
||||
url: url.call("silenced"),
|
||||
icon: "ban",
|
||||
key: "silenced",
|
||||
x: label.call("silenced"),
|
||||
y: silenced,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,14 +6,24 @@ module Reports::Visits
|
||||
class_methods do
|
||||
def report_visits(report)
|
||||
group_filter = report.filters.dig(:group)
|
||||
report.add_filter('group', type: 'group', default: group_filter)
|
||||
report.add_filter("group", type: "group", default: group_filter)
|
||||
|
||||
report.icon = 'user'
|
||||
report.icon = "user"
|
||||
|
||||
basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, group_filter
|
||||
add_counts report, UserVisit, 'visited_at'
|
||||
basic_report_about report,
|
||||
UserVisit,
|
||||
:by_day,
|
||||
report.start_date,
|
||||
report.end_date,
|
||||
group_filter
|
||||
add_counts report, UserVisit, "visited_at"
|
||||
|
||||
report.prev30Days = UserVisit.where('visited_at >= ? and visited_at < ?', report.start_date - 30.days, report.start_date).count
|
||||
report.prev30Days =
|
||||
UserVisit.where(
|
||||
"visited_at >= ? and visited_at < ?",
|
||||
report.start_date - 30.days,
|
||||
report.start_date,
|
||||
).count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,22 +9,25 @@ module Reports::WebCrawlers
|
||||
{
|
||||
type: :string,
|
||||
property: :user_agent,
|
||||
title: I18n.t('reports.web_crawlers.labels.user_agent')
|
||||
title: I18n.t("reports.web_crawlers.labels.user_agent"),
|
||||
},
|
||||
{
|
||||
property: :count,
|
||||
type: :number,
|
||||
title: I18n.t('reports.web_crawlers.labels.page_views')
|
||||
}
|
||||
title: I18n.t("reports.web_crawlers.labels.page_views"),
|
||||
},
|
||||
]
|
||||
|
||||
report.modes = [:table]
|
||||
|
||||
report.data = WebCrawlerRequest.where('date >= ? and date <= ?', report.start_date, report.end_date)
|
||||
.limit(200)
|
||||
.order('sum_count DESC')
|
||||
.group(:user_agent).sum(:count)
|
||||
.map { |ua, count| { user_agent: ua, count: count } }
|
||||
report.data =
|
||||
WebCrawlerRequest
|
||||
.where("date >= ? and date <= ?", report.start_date, report.end_date)
|
||||
.limit(200)
|
||||
.order("sum_count DESC")
|
||||
.group(:user_agent)
|
||||
.sum(:count)
|
||||
.map { |ua, count| { user_agent: ua, count: count } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user