Returns a dict of (year, month) -> active_keys. The dict will contain a key
    for each month observed in the data.

def _active_keys_by_month(ignore_internal_keys, monthly_minimum, cached=True):
    """
    Returns a dict of (year, month) -> active_keys. The dict will contain a key
    for each month observed in the data.
    """

    cache_key = '_active_keys_by_month({0!r},{1!r})[{date!s}]'.format(ignore_internal_keys,
                                                                      monthly_minimum,
                                                                      date=datetime.date.today())
    if cached == True:
        result = cache.get(cache_key)
        if result is not None:
            return result

    keys_issued_period = _keys_issued_date_range()

    # We first do a (date, key) aggregation for the number of daily calls.
    # We would do monthly aggregation here if we were using a newer version
    # of django with ORM month accessors. This rolls up the per-method reports.
    calls_by_key = Report.objects
    if ignore_internal_keys:
        calls_by_key = exclude_internal_key_reports(calls_by_key)
    calls_by_key = (calls_by_key.values('date', 'key__key', 'key__email')
                                .annotate(calls=Sum('calls'))
                                .order_by('-calls'))

    # Aggregate the daily aggregates into monthly aggregates (still on a per-key
    # basis). This facilitates filtering keys by monthly usage.
    grp_by = lambda r: (r['date'].year, r['date'].month, r['key__key'])
    def sum_calls(grp, records):
        return {'calls': sum([r['calls'] for r in records])}
    calls_per_key_monthly = generic_aggregation(calls_by_key,
                                                key=grp_by,
                                                agg_func=sum_calls)
    calls_per_key_monthly1 = ((grp, agg)
                              for (grp, agg) in calls_per_key_monthly.iteritems()
                              if agg['calls'] >= monthly_minimum)

    # Now aggregate the (year, month, key) into the size of (year, month) groups.
    grp_by_month = lambda ((year, month, key), agg): (year, month)
    active_keys_per_month = generic_aggregation(calls_per_key_monthly1,
                                                key=grp_by_month,
                                                agg_func=lambda grp, records: len(records))
    cache.set(cache_key, active_keys_per_month, timeout=(60 * 60 * 25))
    return active_keys_per_month