Пример #1
0
    def test_aggregate_metrics_to_monthly_is_correct_for_uncast_dates_with_averaged_columns(
            self):
        data = {
            '2017-08-02': {
                'conversions': 1,
                'cpc': 2,
                'cost': 4
            },
            '2017-08-04': {
                'conversions': 8,
                'cpc': 16,
                'cost': 32
            },
            '2017-09-02': {
                'conversions': 64,
                'cpc': 128,
                'cost': 256
            },
            '2016-08-08': {
                'conversions': 512,
                'cpc': 1024,
                'cost': 2048
            },
        }

        expected = {
            '2017-08-01': {
                'conversions': 9,
                'cpc': 9,
                'cost': 36
            },
            '2017-09-01': {
                'conversions': 64,
                'cpc': 128,
                'cost': 256
            },
            '2016-08-01': {
                'conversions': 512,
                'cpc': 1024,
                'cost': 2048
            },
        }

        self.assertEqual(
            Adapter.aggregate_metrics_to_monthly(data,
                                                 date_format='%Y-%m-%d',
                                                 average_columns=('cpc', )),
            expected,
        )
Пример #2
0
    def test_aggregate_metrics_to_monthly_is_correct_with_averaged_columns(
            self):
        data = {
            date(2017, 8, 2): {
                'conversions': 1,
                'cpc': 2,
                'cost': 4
            },
            date(2017, 8, 4): {
                'conversions': 8,
                'cpc': 16,
                'cost': 32
            },
            date(2017, 9, 2): {
                'conversions': 64,
                'cpc': 128,
                'cost': 256
            },
            date(2016, 8, 8): {
                'conversions': 512,
                'cpc': 1024,
                'cost': 2048
            },
        }

        expected = {
            date(2017, 8, 1): {
                'conversions': 9,
                'cpc': 9,
                'cost': 36
            },
            date(2017, 9, 1): {
                'conversions': 64,
                'cpc': 128,
                'cost': 256
            },
            date(2016, 8, 1): {
                'conversions': 512,
                'cpc': 1024,
                'cost': 2048
            },
        }

        self.assertEqual(
            Adapter.aggregate_metrics_to_monthly(data,
                                                 average_columns=('cpc', )),
            expected,
        )