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 8923351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:05:37+00:00 2026-06-15T07:05:37+00:00

Using Ruby 1.9.3-p194 Rails 3.2.8 Here’s what I need. Count the different human resources

  • 0

Using

Ruby  1.9.3-p194  
Rails 3.2.8

Here’s what I need.
Count the different human resources (human_resource_id) and divide this by the total number of assignments (assignment_id).
So, the answer for the dummy-data as given below should be:

1.5 assignments per human resource

But I just don’t know where to go anymore.
Here’s what I tried:

Table name: Assignments

id       | human_resource_id | assignment_id | assignment_start_date | assignment_expected_end_date
80101780 | 20200132          | 80101780      | 2012-10-25            | 2012-10-31
80101300 | 20200132          | 80101300      | 2012-07-07            | 2012-07-31
80101308 | 21100066          | 80101308      | 2012-07-09            | 2012-07-17

At first I need to make a selection for the period I need to ‘look’ at. This is always from max a year ago.

a = Assignment.find(:all, :conditions => { :assignment_expected_end_date => (DateTime.now - 1.year)..DateTimenow })
=> [
#<Assignment id: 80101780, human_resource_id: "20200132", assignment_id: "80101780", assignment_start_date: "2012-10-25", assignment_expected_end_date: "2012-10-31">, 
#<Assignment id: 80101300, human_resource_id: "20200132", assignment_id: "80101300", assignment_start_date: "2012-07-07", assignment_expected_end_date: "2012-07-31">, 
#<Assignment id: 80101308, human_resource_id: "21100066", assignment_id: "80101308", assignment_start_date: "2012-07-09", assignment_expected_end_date: "2012-07-17">
]

foo = a.group_by(&:human_resource_id)

Now I got a beautiful ‘Array of hash of object’ and I just don’t know what to do next.

Can someone help me?

  • 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-06-15T07:05:39+00:00Added an answer on June 15, 2026 at 7:05 am

    You can try to execute the request in SQL :

    ActiveRecord::Base.connection.select_value('SELECT count(distinct human_resource_id) / count(distinct assignment_id) AS ratio FROM assignments');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Ruby on Rails tutorial for OSX here: http://ruby.railstutorial.org/book/ruby-on-rails-tutorial It states to install
I'm using rvm 1.15.6 and ruby-1.9.3-p194. I've created a new Rails application with the
I am using Ruby 1.9.3 and Rails 3.2.8. This uses rake 0.9.2.2. I wish
I am using following gems and ruby-1.9.3-p194 : rails 3.2.3 rspec-rails 2.9.0 spork 1.0.0rc2
Using Ruby, I'm trying to parse some documentation in which I need to split
Using Ruby 1.8.6 & Rails 1.2. Models: Job , JobExtraStop : class JobExtraStop <
Using Ruby on Rails. I'm trying to sort a query by number (saved as
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
Using Ruby 1.8.6 / Rails 2.3.2 I am noticing that any method called on

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.