title: Querying a cumulative sum of a boolean column per day
body: <p>I've been attempting to get a cumulative sum of a boolean column per day. I've tried different ways using either <code>#sum</code> and looked up <code>#distinct</code> too (by looking at other posts on Stack Overflow) but haven't been able to successfully implement either of those methods in a way I'd like my hash to look.</p>
  
  <p>Currently, this is the query I have:</p>
  
  <pre><code>Device.where(boxed: true).group('date(updated_at)').count
  </code></pre>
  
  <p>Which gives me this:</p>
  
  <pre><code>{Fri, 17 Apr 2015=&gt;48, Sat, 18 Apr 2015=&gt;44, Sun, 19 Apr 2015=&gt;5, Mon, 20 Apr 2015=&gt;48}
  </code></pre>
  
  <p>But I would like it to look like this:</p>
  
  <pre><code>{Fri, 17 Apr 2015=&gt;48, Sat, 18 Apr 2015=&gt;92, Sun, 19 Apr 2015=&gt;97, Mon, 20 Apr 2015=&gt;145}
  </code></pre>
  
  <p>I am using Rails 4 and Postgres. Any help would be appreciated.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I ended up doing this to get the cumulative sum, even though this probably is not the best way or elegant at all:</p>
  
  <pre><code>data_all_time = Device.where(boxed: true).group('date(updated_at)').count 
  data_all_time_keys = data_all_time.keys
  data_all_time_values = data_all_time.values
  sum = 0
  data_all_time_values.map!{|x| sum += x}
  
  all_time_sum_tuple = data_all_time_keys.zip(data_all_time_values)
  </code></pre>
  
  <p>I end up getting something like this: </p>
  
  <pre><code>[["April 17, 2015", 48], ["April 18, 2015", 92], ["April 19, 2015", 97], ["April 20, 2015", 145]]
  </code></pre>
  
  <p>Which works for now until I can figure out a better way.</p>