most_used_apps.rb 518 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. report_statuses.joins(:application).group(oauth_applications: [:name]).order(count_all: :desc).limit(SET_SIZE).count
  17. end
  18. end