languages_dimension.rb 698 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension::BaseDimension
  3. include LanguagesHelper
  4. def key
  5. 'languages'
  6. end
  7. protected
  8. def perform_query
  9. sql = <<-SQL.squish
  10. SELECT locale, count(*) AS value
  11. FROM users
  12. WHERE current_sign_in_at BETWEEN $1 AND $2
  13. AND locale IS NOT NULL
  14. GROUP BY locale
  15. ORDER BY count(*) DESC
  16. LIMIT $3
  17. SQL
  18. rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
  19. rows.map { |row| { key: row['locale'], human_key: standard_locale_name(row['locale']), value: row['value'].to_s } }
  20. end
  21. end