Esempio n. 1
0
    def test_merge_sum_and_map(self):
        """test the time series merging/map static methods."""
        t_in = TimeSeries(TRAFFIC_DATA_IN)
        t_out = TimeSeries(TRAFFIC_DATA_OUT)

        t_merged = TimeSeries.timeseries_list_merge(dict(name='traffic'), [t_in, t_out])

        self.assertEqual(t_merged.at(2).get('in'), 26)
        self.assertEqual(t_merged.at(2).get('out'), 67)
        self.assertEqual(t_merged.name(), 'traffic')

        t_summed = TimeSeries.timeseries_list_sum(
            dict(name='traffic'), [t_in, t_in], 'in')

        self.assertEqual(t_summed.at(0).get('in'), 104)
        self.assertEqual(t_summed.at(1).get('in'), 36)

        # more variations for coverage

        test_idx_data = dict(
            name="availability",
            columns=["index", "uptime"],
            points=[
                ["2014-07", 100],
                ["2014-08", 88],
                ["2014-09", 95],
                ["2014-10", 99],
                ["2014-11", 91],
                ["2014-12", 99],
                ["2015-01", 100],
                ["2015-02", 92],
                ["2015-03", 99],
                ["2015-04", 87],
                ["2015-05", 92],
                ["2015-06", 100],
            ]
        )

        t_idx = TimeSeries(test_idx_data)
        idx_sum = TimeSeries.timeseries_list_sum(
            dict(name='available'), [t_idx, t_idx], 'uptime')
        self.assertEqual(idx_sum.at(0).get('uptime'), 200)
        self.assertEqual(idx_sum.at(1).get('uptime'), 176)
        self.assertEqual(idx_sum.at(2).get('uptime'), 190)

        test_outage = dict(
            name="outages",
            columns=["timerange", "length", "esnet_ticket"],
            points=[
                [[1429673400000, 1429707600000], 23, "ESNET-20080101-001"],
                [[1429673500000, 1429707700000], 54, "ESNET-20080101-002"],
            ],
        )

        t_tr = TimeSeries(test_outage)
        tr_sum = TimeSeries.timeseries_list_sum(
            dict(name='outage length'), [t_tr, t_tr], 'length')
        self.assertEqual(tr_sum.at(0).get('length'), 46)
        self.assertEqual(tr_sum.at(1).get('length'), 108)
Esempio n. 2
0
    def test_merge_sum_and_map(self):
        """test the time series merging/map static methods."""
        t_in = TimeSeries(TRAFFIC_DATA_IN)
        t_out = TimeSeries(TRAFFIC_DATA_OUT)

        t_merged = TimeSeries.timeseries_list_merge(dict(name='traffic'),
                                                    [t_in, t_out])

        self.assertEqual(t_merged.at(2).get('in'), 26)
        self.assertEqual(t_merged.at(2).get('out'), 67)
        self.assertEqual(t_merged.name(), 'traffic')

        t_summed = TimeSeries.timeseries_list_sum(dict(name='traffic'),
                                                  [t_in, t_in], 'in')

        self.assertEqual(t_summed.at(0).get('in'), 104)
        self.assertEqual(t_summed.at(1).get('in'), 36)

        # more variations for coverage

        test_idx_data = dict(name="availability",
                             columns=["index", "uptime"],
                             points=[
                                 ["2014-07", 100],
                                 ["2014-08", 88],
                                 ["2014-09", 95],
                                 ["2014-10", 99],
                                 ["2014-11", 91],
                                 ["2014-12", 99],
                                 ["2015-01", 100],
                                 ["2015-02", 92],
                                 ["2015-03", 99],
                                 ["2015-04", 87],
                                 ["2015-05", 92],
                                 ["2015-06", 100],
                             ])

        t_idx = TimeSeries(test_idx_data)
        idx_sum = TimeSeries.timeseries_list_sum(dict(name='available'),
                                                 [t_idx, t_idx], 'uptime')
        self.assertEqual(idx_sum.at(0).get('uptime'), 200)
        self.assertEqual(idx_sum.at(1).get('uptime'), 176)
        self.assertEqual(idx_sum.at(2).get('uptime'), 190)

        test_outage = dict(
            name="outages",
            columns=["timerange", "length", "esnet_ticket"],
            points=[
                [[1429673400000, 1429707600000], 23, "ESNET-20080101-001"],
                [[1429673500000, 1429707700000], 54, "ESNET-20080101-002"],
            ],
        )

        t_tr = TimeSeries(test_outage)
        tr_sum = TimeSeries.timeseries_list_sum(dict(name='outage length'),
                                                [t_tr, t_tr], 'length')
        self.assertEqual(tr_sum.at(0).get('length'), 46)
        self.assertEqual(tr_sum.at(1).get('length'), 108)
Esempio n. 3
0
    def test_series_reduce(self):
        """Test reduce re-ordering out of order start times."""

        # Mix the ordering up so they're out of chronological order
        summ = TimeSeries.timeseries_list_sum(
            {"name": "summ"}, [TS4, TS2, TS3, TS1, TS5], ["in", "out"])

        self.assertEqual(summ.size(), 10)
        self.assertEqual(summ.at(0).get('in'), 2)
        self.assertEqual(summ.at(1).get('in'), 2)
        self.assertEqual(summ.at(2).get('in'), 2)
        self.assertEqual(summ.at(3).get('in'), 3)
        self.assertEqual(summ.at(4).get('in'), 3)
        self.assertEqual(summ.at(5).get('in'), 3)
        self.assertEqual(summ.at(6).get('in'), 3)
        self.assertEqual(summ.at(7).get('in'), 2)
        self.assertEqual(summ.at(8).get('in'), 2)
        self.assertEqual(summ.at(9).get('in'), 2)
Esempio n. 4
0
    def test_series_reduce(self):
        """Test reduce re-ordering out of order start times."""

        # Mix the ordering up so they're out of chronological order
        summ = TimeSeries.timeseries_list_sum({"name": "summ"},
                                              [TS4, TS2, TS3, TS1, TS5],
                                              ["in", "out"])

        self.assertEqual(summ.size(), 10)
        self.assertEqual(summ.at(0).get('in'), 2)
        self.assertEqual(summ.at(1).get('in'), 2)
        self.assertEqual(summ.at(2).get('in'), 2)
        self.assertEqual(summ.at(3).get('in'), 3)
        self.assertEqual(summ.at(4).get('in'), 3)
        self.assertEqual(summ.at(5).get('in'), 3)
        self.assertEqual(summ.at(6).get('in'), 3)
        self.assertEqual(summ.at(7).get('in'), 2)
        self.assertEqual(summ.at(8).get('in'), 2)
        self.assertEqual(summ.at(9).get('in'), 2)