Removing some intermediate values

This removes some intermediate steps that were ultimately not necessary
to the math.  It also consolidates some of the methods for counting events
so that fewer intermediate values are necessary.

To that end, a new scope is added to the ToDo model for events that are
*either* created_at or completed_at after a certain date. This scope
allows the StatsController to pull out the largest possible responsive
set of values, and then filter just the particular slices that it needs
for various steps in the calculation.
This commit is contained in:
Don Cruse 2013-07-18 22:32:44 -05:00 committed by Reinier Balt
parent 9de6d85342
commit d4bd8ed4db
2 changed files with 40 additions and 34 deletions

View file

@ -48,6 +48,7 @@ class Todo < ActiveRecord::Base
scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) }
scope :created_after, lambda { |date| where("todos.created_at > ?", date) }
scope :created_before, lambda { |date| where("todos.created_at < ?", date) }
scope :created_or_completed_after, lambda { |date| where("todos.created_at > ? or todos.completed_at > ?", date, date) }
def self.due_after(date)
where('todos.due > ?', date)