code: def aggregate_rate(rate_key, count_key):
      
      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
docs: Compute an aggregate rate for `rate_key` weighted according to
      `count_rate`.