def test_make_aggregate_rate():
    """
    test_make_aggregate_rate()

    Test that aggregation works when there are two fields summed over, and
    that rate aggregation works correctly. It isn't easy to test independently
    because one must aggregate over the two fields to get the correct result.
    """
    from nose.tools import assert_equal

    doc1 = {"a": 2, "b": 2, "c": 2, "visits": 100, "rate": 0.25}
    doc2 = {"a": 2, "b": 2, "c": 2, "visits": 100, "rate": 0.75}
    docs = [doc1, doc2]

    aggregate_doc = make_aggregate(docs, [aggregate_count("visits"),
                                          aggregate_rate("rate", "visits")])
    expected_aggregate = {
        "a": 2, "b": 2, "c": 2,
        "visits": 200,
        "rate": (0.25 * 100 + 0.75 * 100) / (100 + 100)}

    assert_equal(aggregate_doc, expected_aggregate)
def test_make_aggregate_rate ( ) : from nose . tools import assert_equal doc1 = { "a" : 2 , "b" : 2 , "c" : 2 , "visits" : 100 , "rate" : 0.25 } doc2 = { "a" : 2 , "b" : 2 , "c" : 2 , "visits" : 100 , "rate" : 0.75 } docs = [ doc1 , doc2 ] aggregate_doc = make_aggregate ( docs , [ aggregate_count ( "visits" ) , aggregate_rate ( "rate" , "visits" ) ] ) expected_aggregate = { "a" : 2 , "b" : 2 , "c" : 2 , "visits" : 200 , "rate" : ( 0.25 * 100 + 0.75 * 100 ) / ( 100 + 100 ) } assert_equal ( aggregate_doc , expected_aggregate )
test_make_aggregate_rate()

    Test that aggregation works when there are two fields summed over, and
    that rate aggregation works correctly. It isn't easy to test independently
    because one must aggregate over the two fields to get the correct result.