def test_coalesce_format_initial(self): coalesced = {} first_run = { 'result': { Aggregation.SUM: { 'metric1': 10 } }, 'parameters': { 'Metric_timeseries': 'none', 'Metric_end_date': '2014-07-01' } } _merge_run(coalesced, first_run) assert_equal( coalesced, { 'result': { Aggregation.SUM: { 'metric1': { '2014-07-01': 10 } } }, 'parameters': { 'Metric_timeseries': 'none', 'Metric_end_date': '2014-07-01' } })
def test_coalesce_format_initial(self): coalesced = {} first_run = { 'result': { Aggregation.SUM: {'metric1': 10} }, 'parameters': { 'Metric_timeseries': 'none', 'Metric_end_date': '2014-07-01' } } _merge_run(coalesced, first_run) assert_equal(coalesced, { 'result': { Aggregation.SUM: {'metric1': {'2014-07-01': 10}} }, 'parameters': { 'Metric_timeseries': 'none', 'Metric_end_date': '2014-07-01' } })
def test_coalesce_format_updating(self): coalesced = {} new_run = { 'result': { Aggregation.IND: { '123|enwiki|1': { 'metric1': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 1, '2014-06-16 00:00:00': 0, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 0, '2014-06-16 00:00:00': 2, }, }, '124|enwiki|1': { 'metric1': { '2014-06-14 00:00:00': 1, '2014-06-15 00:00:00': 0, '2014-06-16 00:00:00': 1, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 3, '2014-06-16 00:00:00': 0, }, } }, Aggregation.SUM: { 'metric1': { '2014-06-14 00:00:00': 1, '2014-06-15 00:00:00': 1, '2014-06-16 00:00:00': 1, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 3, '2014-06-16 00:00:00': 2, }, } }, 'parameters': { 'param1': 1, 'param2': 2, 'param3': 3, 'Metric_timeseries': 'day', } } _merge_run(coalesced, new_run) assert_equal(coalesced, new_run) new_date = '2014-06-17 00:00:00' _merge_run(coalesced, { 'parameters': {'Metric_end_date': new_date}, 'result': { Aggregation.SUM: {'metric1': 2, 'metric2': 3}, Aggregation.IND: { '123|enwiki|1': {'metric1': 3, 'metric2': 1}, '124|enwiki|1': {'metric1': 4, 'metric2': 0}, } } }) r = coalesced['result'] assert_equal(r[Aggregation.SUM]['metric1'][new_date], 2) assert_equal(r[Aggregation.SUM]['metric2'][new_date], 3) assert_equal(r[Aggregation.IND]['123|enwiki|1']['metric1'][new_date], 3) assert_equal(r[Aggregation.IND]['123|enwiki|1']['metric2'][new_date], 1) assert_equal(r[Aggregation.IND]['124|enwiki|1']['metric1'][new_date], 4) assert_equal(r[Aggregation.IND]['124|enwiki|1']['metric2'][new_date], 0)
def test_coalesce_format_updating(self): coalesced = {} new_run = { 'result': { Aggregation.IND: { '123|enwiki|1': { 'metric1': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 1, '2014-06-16 00:00:00': 0, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 0, '2014-06-16 00:00:00': 2, }, }, '124|enwiki|1': { 'metric1': { '2014-06-14 00:00:00': 1, '2014-06-15 00:00:00': 0, '2014-06-16 00:00:00': 1, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 3, '2014-06-16 00:00:00': 0, }, } }, Aggregation.SUM: { 'metric1': { '2014-06-14 00:00:00': 1, '2014-06-15 00:00:00': 1, '2014-06-16 00:00:00': 1, }, 'metric2': { '2014-06-14 00:00:00': 0, '2014-06-15 00:00:00': 3, '2014-06-16 00:00:00': 2, }, } }, 'parameters': { 'param1': 1, 'param2': 2, 'param3': 3, 'Metric_timeseries': 'day', } } _merge_run(coalesced, new_run) assert_equal(coalesced, new_run) new_date = '2014-06-17 00:00:00' _merge_run( coalesced, { 'parameters': { 'Metric_end_date': new_date }, 'result': { Aggregation.SUM: { 'metric1': 2, 'metric2': 3 }, Aggregation.IND: { '123|enwiki|1': { 'metric1': 3, 'metric2': 1 }, '124|enwiki|1': { 'metric1': 4, 'metric2': 0 }, } } }) r = coalesced['result'] assert_equal(r[Aggregation.SUM]['metric1'][new_date], 2) assert_equal(r[Aggregation.SUM]['metric2'][new_date], 3) assert_equal(r[Aggregation.IND]['123|enwiki|1']['metric1'][new_date], 3) assert_equal(r[Aggregation.IND]['123|enwiki|1']['metric2'][new_date], 1) assert_equal(r[Aggregation.IND]['124|enwiki|1']['metric1'][new_date], 4) assert_equal(r[Aggregation.IND]['124|enwiki|1']['metric2'][new_date], 0)