rackerlabs/blueflood — pull request #167 by russellhaering (2013-12-09 23:54:34+00:00)
Title: Improve "by points" Granularity Selection Algorithm

Currently the algorithm used in `granularityFromPointsInInterval` attempts to select the granularity that provides the absolute closest number of points to that requested. This breaks under some circumstances.

When a user requests a fixed number of points, they are doing so in order to generate a graph that approximates a desired point resolution over a fixed width. In other words, our goal should not be to supply the closest number of points to that requested, but to minimize the ratio of points requested to points supplied.

To illustrate this, consider the case where a user requests 500 points, but our options are to return 100 points or 1000 points. Although 100 points is closer to 500, it is actually 5x lower density than the user wanted. It is better to return 1000 points, which is only 2x higher.