rails data aggregation

Posted by ash34 on Stack Overflow See other posts from Stack Overflow or by ash34
Published on 2010-05-18T08:43:57Z Indexed on 2010/05/18 9:00 UTC
Read the original article Hit count: 208

Filed under:
|

Hi,

I have to create a hash of the form h[:bill] => ["Billy", "NA", 20, "PROJ_A"] by login where 20 is the cumulative number of hours reported by the login for all task transactions returned by the query where each login has multiple reported transactions. Did I do this in a bad way or this seems alright.

h = Hash.new
Task.find_each(:include => [:user], :joins => :user, :conditions => ["from_date >= ? AND from_date <= ? AND category = ?", Date.today - 30, Date.today + 30, 'PROJ1']) do |t|

   h[t.login.intern] = [t.user.name, 'NA', h[t.login.intern].nil? ? (t.hrs_per_day * t.num_days) : h[t.login.intern][2] + (t.hrs_day * t.workdays), t.category]

end

Also if I have to aggregate this data not just by login but login and category how do I accomplish this?

thanks, ash

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby