lundi 20 avril 2015

Rails 4: Querying a cumulative sum of a boolean column per day

I've been attempting to get a cumulative sum of a boolean column per day. I've tried different ways using either #sum and looked up #distinct too (by looking at other posts on stackoverflow) but haven't been able to successfully implement either of those methods in a way I'd like my hash to look.

Currently, this is the query I have:

Device.where(boxed: true).group('date(updated_at)').count

Which gives me this:

{Fri, 17 Apr 2015=>48, Sat, 18 Apr 2015=>44, Sun, 19 Apr 2015=>5, Mon, 20 Apr 2015=>48}

But I would like it to look like this:

{Fri, 17 Apr 2015=>48, Sat, 18 Apr 2015=>92, Sun, 19 Apr 2015=>97, Mon, 20 Apr 2015=>125}

I am using Rails 4 and postgres. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire