Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:48:43+00:00 2026-05-28T02:48:43+00:00

I am trying to make an admin dashboard that shows an administrator relevant statistics

  • 0

I am trying to make an admin dashboard that shows an administrator relevant statistics about the site. For example, given a company has many users, finding the average number of users per company, or the maximum number of users a company has.

I have found activerecord::calculations, which seems to do most of what I want, but as far as I can tell, it doesn’t let you do anything with relations. How would I go about finding counts or averages that are grouped by relations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:48:44+00:00Added an answer on May 28, 2026 at 2:48 am

    You have to think of it in terms of the User.

    The simplest way would be

    # get a hash of company_ids and user counts
    User.group(:company_id).count
    

    But then you’ll have to load the Companies and match them up.

    Then you could try and do

    user_counts = User.group(:company_id).count
    
    company_users = Company.all.map{|company| user_counts[company.id]}
    
    # the maximum
    company_users.max
    
    # the average
    company_users.sum.to_f / company_users.length
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I'm trying to make a custom view in Django admin. I'm reading from this
I'm trying to make my admin login field greater than 30 characters because I'm
I'm trying to keep my specs DRY by creating a shared example group that
1st Question: I'm trying to make the create method work, but it appears that
I'm trying to make a Preview function. I'm reading this blog, Django Admin Preview
I have a fairly complex relationship that I am trying to make work with
I am new MVC 3 user and I am trying to make admin through
I am trying to make a simple admin page for managing users list. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.