Compute an aggregate rate for `rate_key` weighted according to
    `count_rate`.

def aggregate_rate(rate_key, count_key):
    """
    Compute an aggregate rate for `rate_key` weighted according to
    `count_rate`.
    """
    def inner(docs):
        total = sum(doc[count_key] for doc in docs)
        weighted_total = sum(doc[rate_key] * doc[count_key] for doc in docs)
        total_rate = weighted_total / total
        return total_rate

    return rate_key, inner