

def test_make_aggregate_rate():
    "\n    test_make_aggregate_rate()\n\n    Test that aggregation works when there are two fields summed over, and\n    that rate aggregation works correctly. It isn't easy to test independently\n    because one must aggregate over the two fields to get the correct result.\n    "
    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)

dataset/ETHPy150Open alphagov/performanceplatform-collector/tests/performanceplatform/collector/ga/plugins/test_aggregate.py test_make_aggregate_rate/original