예제 #1
0
    def test_get_by_idx(self):
        ts = DataSeriesTest.factory.build_time_series(series_id="test", keys=["timestamp", "v1", "v2"])

        series = DataSeries(time_series=ts)

        series.add(data={"timestamp": 0, "v1": 2})
        series.add(data={"timestamp": 1, "v1": 2.4})
        series.add(data={"timestamp": 1, "v2": 3.0})

        # index and key
        self.assertEqual(2, series.get_by_idx(idx=0, keys="v1"))
        self.assertEqual(0.0, series.get_by_idx(idx=0, keys="v2"))
        self.assertEqual(2.4, series.get_by_idx(idx=1, keys="v1"))
        self.assertEqual(3.0, series.get_by_idx(idx=1, keys="v2"))

        # index only
        self.assertEqual({"timestamp": 0, "v1": 2, "v2": 0.0}, series.get_by_idx(idx=0))
        self.assertEqual({"timestamp": 1, "v1": 2.4, "v2": 3.0}, series.get_by_idx(idx=1))

        # test index slice
        series2 = self.create_series_by_list(range(100))
        sliced = series2.get_by_idx(keys='v1', idx=slice(-10, None, None))
        self.assertEqual(len(sliced), 10)

        endPoint = series2.get_by_idx(keys='v1', idx=slice(-1, None, None))
        self.assertEqual(endPoint[0], 99)
예제 #2
0
    def test_override_w_same_time(self):
        ts = DataSeriesTest.factory.build_time_series(series_id="test", keys=["timestamp", "v1", "v2", "v3"])

        series = DataSeries(time_series=ts)

        series.add(data={"timestamp": 1, "v1": 2, "v2": 3})
        self.assertEqual(1, series.size())
        self.assertEqual(2, series.get_by_idx(0, "v1"))
        self.assertEqual(2, series.get_by_time(1, "v1"))
        self.assertEqual(3, series.get_by_idx(0, "v2"))
        self.assertEqual(3, series.get_by_time(1, "v2"))
        self.assertEqual(0.0, series.get_by_idx(0, "v3"))
        self.assertEqual(0.0, series.get_by_time(1, "v3"))

        series.add(data={"timestamp": 1, "v1": 2.4, "v2": 3.4, "v3": 1.1})
        self.assertEqual(1, series.size())
        self.assertEqual(2.4, series.get_by_idx(0, "v1"))
        self.assertEqual(2.4, series.get_by_time(1, "v1"))
        self.assertEqual(3.4, series.get_by_idx(0, "v2"))
        self.assertEqual(3.4, series.get_by_time(1, "v2"))
        self.assertEqual(1.1, series.get_by_idx(0, "v3"))
        self.assertEqual(1.1, series.get_by_time(1, "v3"))

        series.add(data={"timestamp": 2, "v1": 2.6, "v2": 3.6})
        self.assertEqual(2, series.size())
        self.assertEqual(2.4, series.get_by_idx(0, "v1"))
        self.assertEqual(2.4, series.get_by_time(1, "v1"))
        self.assertEqual(3.4, series.get_by_idx(0, "v2"))
        self.assertEqual(3.4, series.get_by_time(1, "v2"))
        self.assertEqual(1.1, series.get_by_idx(0, "v3"))
        self.assertEqual(1.1, series.get_by_time(1, "v3"))

        self.assertEqual(2.6, series.get_by_idx(1, "v1"))
        self.assertEqual(2.6, series.get_by_time(2, "v1"))
        self.assertEqual(3.6, series.get_by_idx(1, "v2"))
        self.assertEqual(3.6, series.get_by_time(2, "v2"))
        self.assertEqual(0.0, series.get_by_idx(1, "v3"))
        self.assertEqual(0.0, series.get_by_time(2, "v3"))