Пример #1
0
    def test_simple_take(self):
        """take 10 events in batch."""

        timeseries = TimeSeries(SEPT_2014_DATA)

        kcol = (
            Pipeline().from_source(timeseries).take(10).to_keyed_collections())

        new_ts = TimeSeries(dict(name='result', collection=kcol.get('all')))
        self.assertEqual(new_ts.size(), 10)
Пример #2
0
    def test_simple_take(self):
        """take 10 events in batch."""

        timeseries = TimeSeries(SEPT_2014_DATA)

        kcol = (
            Pipeline()
            .from_source(timeseries)
            .take(10)
            .to_keyed_collections()
        )

        new_ts = TimeSeries(dict(name='result', collection=kcol.get('all')))
        self.assertEqual(new_ts.size(), 10)
Пример #3
0
    def test_series_creation(self):
        """test timeseries creation.

        Calls to to_json() are to trigger coverage for different variants.
        """

        # from a wire format event list
        ts1 = TimeSeries(DATA)
        self.assertEqual(ts1.size(), len(DATA.get('points')))

        # from a wire format index
        ts2 = TimeSeries(AVAILABILITY_DATA)
        self.assertEqual(ts2.size(), len(AVAILABILITY_DATA.get('points')))
        self.assertEqual(ts2.to_json().get('name'), 'availability')

        # from a list of events
        ts3 = TimeSeries(dict(name='events', events=EVENT_LIST))
        self.assertEqual(ts3.size(), len(EVENT_LIST))

        # from a collection
        ts4 = TimeSeries(
            dict(name='collection', collection=self._canned_collection))
        self.assertEqual(ts4.size(), self._canned_collection.size())

        # copy constructor
        ts5 = TimeSeries(ts4)
        self.assertEqual(ts4.size(), ts5.size())

        # from a wire format time range
        ts6 = TimeSeries(TICKET_RANGE)
        self.assertEqual(ts6.size(), len(TICKET_RANGE.get('points')))
        self.assertEqual(ts6.to_json().get('name'), 'outages')

        # non-utc indexed data variant mostly for coverage
        idxd = copy.deepcopy(INDEXED_DATA)
        idxd['utc'] = False
        ts7 = TimeSeries(idxd)
        self.assertFalse(ts7.is_utc())
        self.assertFalse(ts7.to_json().get('utc'))

        # indexed data variant using Index object - for coverage as well
        idxd2 = copy.deepcopy(INDEXED_DATA)
        idxd2['index'] = Index(idxd2.get('index'))
        ts8 = TimeSeries(idxd2)
        self.assertEqual(ts8.to_json().get('index'), '1d-625')

        # make sure complex/deep/nested wire format is being handled correctly.
        ts7 = TimeSeries(DATA_FLOW)
        self.assertEqual(ts7.at(0).value('direction').get('in'), 1)
        self.assertEqual(ts7.at(0).value('direction').get('out'), 2)
        self.assertEqual(ts7.at(1).value('direction').get('in'), 3)
        self.assertEqual(ts7.at(1).value('direction').get('out'), 4)
Пример #4
0
    def test_series_creation(self):
        """test timeseries creation.

        Calls to to_json() are to trigger coverage for different variants.
        """

        # from a wire format event list
        ts1 = TimeSeries(DATA)
        self.assertEqual(ts1.size(), len(DATA.get('points')))

        # from a wire format index
        ts2 = TimeSeries(AVAILABILITY_DATA)
        self.assertEqual(ts2.size(), len(AVAILABILITY_DATA.get('points')))
        self.assertEqual(ts2.to_json().get('name'), 'availability')

        # from a list of events
        ts3 = TimeSeries(dict(name='events', events=EVENT_LIST))
        self.assertEqual(ts3.size(), len(EVENT_LIST))

        # from a collection
        ts4 = TimeSeries(dict(name='collection', collection=self._canned_collection))
        self.assertEqual(ts4.size(), self._canned_collection.size())

        # copy constructor
        ts5 = TimeSeries(ts4)
        self.assertEqual(ts4.size(), ts5.size())

        # from a wire format time range
        ts6 = TimeSeries(TICKET_RANGE)
        self.assertEqual(ts6.size(), len(TICKET_RANGE.get('points')))
        self.assertEqual(ts6.to_json().get('name'), 'outages')

        # non-utc indexed data variant mostly for coverage
        idxd = copy.deepcopy(INDEXED_DATA)
        idxd['utc'] = False
        ts7 = TimeSeries(idxd)
        self.assertFalse(ts7.is_utc())
        self.assertFalse(ts7.to_json().get('utc'))

        # indexed data variant using Index object - for coverage as well
        idxd2 = copy.deepcopy(INDEXED_DATA)
        idxd2['index'] = Index(idxd2.get('index'))
        ts8 = TimeSeries(idxd2)
        self.assertEqual(ts8.to_json().get('index'), '1d-625')

        # make sure complex/deep/nested wire format is being handled correctly.
        ts7 = TimeSeries(DATA_FLOW)
        self.assertEqual(ts7.at(0).value('direction').get('in'), 1)
        self.assertEqual(ts7.at(0).value('direction').get('out'), 2)
        self.assertEqual(ts7.at(1).value('direction').get('in'), 3)
        self.assertEqual(ts7.at(1).value('direction').get('out'), 4)