most_used_apps.rb 618 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class AnnualReport::MostUsedApps < AnnualReport::Source
  3. SET_SIZE = 10
  4. def generate
  5. {
  6. most_used_apps: most_used_apps.map do |(name, count)|
  7. {
  8. name: name,
  9. count: count,
  10. }
  11. end,
  12. }
  13. end
  14. private
  15. def most_used_apps
  16. @account.statuses.reorder(nil).where(id: year_as_snowflake_range).joins(:application).group('oauth_applications.name').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('oauth_applications.name, count(*) as total'))
  17. end
  18. end