2021-10-14 19:44:59 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension::BaseDimension
|
2021-11-25 12:07:38 +00:00
|
|
|
include LanguagesHelper
|
|
|
|
|
2021-10-14 19:44:59 +01:00
|
|
|
def key
|
|
|
|
'languages'
|
|
|
|
end
|
|
|
|
|
2022-02-22 14:27:08 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2021-10-14 19:44:59 +01:00
|
|
|
sql = <<-SQL.squish
|
|
|
|
SELECT locale, count(*) AS value
|
|
|
|
FROM users
|
|
|
|
WHERE current_sign_in_at BETWEEN $1 AND $2
|
|
|
|
AND locale IS NOT NULL
|
|
|
|
GROUP BY locale
|
|
|
|
ORDER BY count(*) DESC
|
|
|
|
LIMIT $3
|
|
|
|
SQL
|
|
|
|
|
|
|
|
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
|
|
|
|
|
2022-02-09 03:15:38 +00:00
|
|
|
rows.map { |row| { key: row['locale'], human_key: standard_locale_name(row['locale']), value: row['value'].to_s } }
|
2021-10-14 19:44:59 +01:00
|
|
|
end
|
|
|
|
end
|