This bug was caused when the chart encountered data outside of its
visible range (i.e., the upper bound of the array size). A test was
added that inserts some data from 2 years and 16 months in the past.
The test failed on the old version, throwing exactly the error in bug
report #1442.
The fix is to check whether or not the value is within the array range
before sending the "+=" operator. With this change, the test passes.
Also removing the python-esque combination methods to set multiple
disparate variables from a single method by refactoring that to a
simpler method.
Reducing the complexity of computing running averages.
Note: It is not clear to me why the actions_done_lastyears_data
action is entirely unscoped on date. That seems to be the expected
behavior, so I left it alone.
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.
Also removing some instance variables that were never invoked in the
views. This sets up a future refactoring of the method of comptuting
rolling averages, which differs between the two types of "last year"
views being refactored.
`Todo.from_rich_message` was partially tested from the MessageGateway,
but it is mostly untested and does not belong in Todo due to it's unique
nature. Extract it entirely from `Todo` into it's own dedicated object
for unit testing.
- Use `define_method` to clean up definition of methods that only
vary by the name of the day they reference and the corresponding
numerical value.
- Remove calls to self, explicit return statements, etc.