languages_dimension.rb 790 B

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension::BaseDimension
  3. include Admin::Metrics::Dimension::QueryHelper
  4. include LanguagesHelper
  5. def key
  6. 'languages'
  7. end
  8. protected
  9. def perform_query
  10. dimension_data_rows.map { |row| { key: row['locale'], human_key: standard_locale_name(row['locale']), value: row['value'].to_s } }
  11. end
  12. def sql_array
  13. [sql_query_string, { start_at: @start_at, end_at: @end_at, limit: @limit }]
  14. end
  15. def sql_query_string
  16. <<~SQL.squish
  17. SELECT locale, count(*) AS value
  18. FROM users
  19. WHERE current_sign_in_at BETWEEN :start_at AND :end_at
  20. AND locale IS NOT NULL
  21. GROUP BY locale
  22. ORDER BY count(*) DESC
  23. LIMIT :limit
  24. SQL
  25. end
  26. end