2021-10-15 05:44:59 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-06 00:52:33 +10:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
2021-11-25 23:07:38 +11:00
|
|
|
include LanguagesHelper
|
|
|
|
|
2021-10-15 05:44:59 +11:00
|
|
|
def key
|
|
|
|
'languages'
|
|
|
|
end
|
|
|
|
|
2022-02-23 01:27:08 +11:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-06 00:52:33 +10:00
|
|
|
dimension_data_rows.map { |row| { key: row['locale'], human_key: standard_locale_name(row['locale']), value: row['value'].to_s } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_array
|
|
|
|
[sql_query_string, { start_at: @start_at, end_at: @end_at, limit: @limit }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_query_string
|
|
|
|
<<~SQL.squish
|
2021-10-15 05:44:59 +11:00
|
|
|
SELECT locale, count(*) AS value
|
|
|
|
FROM users
|
2023-06-06 00:52:33 +10:00
|
|
|
WHERE current_sign_in_at BETWEEN :start_at AND :end_at
|
2021-10-15 05:44:59 +11:00
|
|
|
AND locale IS NOT NULL
|
|
|
|
GROUP BY locale
|
|
|
|
ORDER BY count(*) DESC
|
2023-06-06 00:52:33 +10:00
|
|
|
LIMIT :limit
|
2021-10-15 05:44:59 +11:00
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|