Re: [Rails] group by + sum

2013-01-25 Thread Werner
Hi Jim.. thanks.. looks good now.. I had a mistake in another model..so the grouping was not correct. my god.. what a trip sometimes.. Werner Am Freitag, 25. Januar 2013 14:50:53 UTC+1 schrieb jim: > > > > > On Fri, Jan 25, 2013 at 9:42 PM, Werner > > > wrote: > >> Well.. I cant get it workin

Re: [Rails] group by + sum

2013-01-25 Thread Jim Ruther Nill
On Fri, Jan 25, 2013 at 9:42 PM, Werner wrote: > Well.. I cant get it working > > Try to explain it again.. > > db_table: > week_id, project_id, user_id, hour > ex. => > 33, 1, 1, 10 > 33, 4, 1, 20 > 33, 1, 2, 0 > 34, 1, 2, 15 > 34, 1, 1, 0 > > > So, user with the id 1 worked 10 hours in week 33 a

Re: [Rails] group by + sum

2013-01-25 Thread Werner
Well.. I cant get it working Try to explain it again.. db_table: week_id, project_id, user_id, hour ex. => 33, 1, 1, 10 33, 4, 1, 20 33, 1, 2, 0 34, 1, 2, 15 34, 1, 1, 0 So, user with the id 1 worked 10 hours in week 33 and 20 in the week 33, but other project I want to show all hours summed

Re: [Rails] group by + sum

2013-01-24 Thread Jim Ruther Nill
On Thu, Jan 24, 2013 at 10:38 PM, Werner wrote: > Jim..sorry.. not my day... > have to contemplate about your solution. > > I wonder.. > > HourUser.includes(:user).where.group_by { |h| h.week_id } > > <% @hours.keys.sort.each do |h| %> > <%= @hours[h].collect(&:hour).sum %> > <% end %> > > is

Re: [Rails] group by + sum

2013-01-24 Thread Werner
Jim..sorry.. not my day... have to contemplate about your solution. I wonder.. HourUser.includes(:user).where.group_by { |h| h.week_id } <% @hours.keys.sort.each do |h| %> <%= @hours[h].collect(&:hour).sum %> <% end %> is giving me what I want, just needs to be grouped by user_id Thanks s

Re: [Rails] group by + sum

2013-01-24 Thread Jim Ruther Nill
On Thu, Jan 24, 2013 at 7:55 PM, Werner wrote: > Hi Jim.. thanks so far.. > > in the moment this is a bit too far for me. > > > Just remember that to get a certain value, you'll have to pass an array as > the index > ie sums[[33,2]] to get 70 > => this is unclear > Pls. be so kind to explain the v

Re: [Rails] group by + sum

2013-01-24 Thread Werner
Hi Jim.. thanks so far.. in the moment this is a bit too far for me. Just remember that to get a certain value, you'll have to pass an array as the index ie sums[[33,2]] to get 70 => this is unclear Pls. be so kind to explain the view part. Werner Am Donnerstag, 24. Januar 2013 11:36:44 U

Re: [Rails] group by + sum

2013-01-24 Thread Jim Ruther Nill
On Thu, Jan 24, 2013 at 4:35 PM, Werner wrote: > Hi.. I need some support... > > table: > week_id, user_id, project_id, hours > ex. => > 33, 2, 1, 10 > 34, 2,1,15 > 33, 2, 2, 20 > 35, 3, 1,20 > etc. > Want to display a sum of hours per week_id per user_id > I have: > > @hours = HourUser.includes

Re: [Rails] group by + sum

2013-01-24 Thread Werner
Think, you mean something like: Model.sort_by{|h| [h.user_id, -h.week_id]} ? Am Donnerstag, 24. Januar 2013 10:24:57 UTC+1 schrieb Jordon Bedwell: > > On Thu, Jan 24, 2013 at 3:14 AM, Werner > > > wrote: > > Feel a litte ittle stupid right now.. > > where to sort_by? > > Well, without a

Re: [Rails] group by + sum

2013-01-24 Thread Jordon Bedwell
On Thu, Jan 24, 2013 at 3:14 AM, Werner wrote: > Feel a litte ittle stupid right now.. > where to sort_by? Well, without a coherent though (AKA proper data outputs in the form of say a copy of the pry session where it outputs => { } and then you go through the steps I cannot say. I have no idea

Re: [Rails] group by + sum

2013-01-24 Thread Werner
Feel a litte ittle stupid right now.. where to sort_by? Am Donnerstag, 24. Januar 2013 09:49:33 UTC+1 schrieb Jordon Bedwell: > > On Thu, Jan 24, 2013 at 2:35 AM, Werner > > > wrote: > > Hi.. I need some support... > > > > table: > > week_id, user_id, project_id, hours > > ex. => > > 33,

Re: [Rails] group by + sum

2013-01-24 Thread Jordon Bedwell
On Thu, Jan 24, 2013 at 2:35 AM, Werner wrote: > Hi.. I need some support... > > table: > week_id, user_id, project_id, hours > ex. => > 33, 2, 1, 10 > 34, 2,1,15 > 33, 2, 2, 20 > 35, 3, 1,20 > etc. > > Want to display a sum of hours per week_id per user_id > I have: > > @hours = HourUser.includes

[Rails] group by + sum

2013-01-24 Thread Werner
Hi.. I need some support... table: week_id, user_id, project_id, hours ex. => 33, 2, 1, 10 34, 2,1,15 33, 2, 2, 20 35, 3, 1,20 etc. Want to display a sum of hours per week_id per user_id I have: @hours = HourUser.includes(:user).group_by { |h| h.week_id } @hours.keys.sort.each do |hour| @hours