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