2

Example: a table, in which the power consumption is saved every few minutes.

What i am trying to do with this data using the groupdate gem:

@kWh = Consumption.group_by_hour(:at).average(:kw)
@kWh_per_day = @kWh.group_by_day(:at).sum(:average_kw)

For the second line I get an error: "no block given"

Any push in the right direction would be appreciated.

tuvya
  • 21
  • 4

1 Answers1

0

... what finally worked, though it doesn't look very elegeant:

@kWh = Consumption.group_by_hour(:at).average(:kw)
@kWh_per_day = Hash [@kWh.group_by_day { |h| h[0] }.map { |k,v| [k, v.map { |j| j[1] }.reduce(:+)] } ]
tuvya
  • 21
  • 4