Ejemplo n.º 1
0
    def test_get_data(self):
        ts = DataSeriesTest.factory.build_time_series(series_id="test")

        series = DataSeries(time_series=ts)

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

        self.assertEqual([{"timestamp": 1, "v1": 1, "v2": 1},
                          {"timestamp": 2, "v1": 2, "v2": 2}], series.get_data())
Ejemplo n.º 2
0
    def test_add(self):
        ts = DataSeriesTest.factory.build_time_series(series_id="test")

        series = DataSeries(time_series=ts)

        self.assertTrue(len(series.get_data()) == 0)

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

        self.assertEqual([{"timestamp": 0, "v1": 1, "v2": 1},
                          {"timestamp": 1, "v1": 2, "v2": 2}], series.get_data())

        series.add(data={"timestamp": 1, "v1": 3, "v2": 3})

        self.assertEqual([{"timestamp": 0, "v1": 1, "v2": 1},
                          {"timestamp": 1, "v1": 3, "v2": 3}], series.get_data())

        series.add(data={"timestamp": 2, "v1": 4, "v2": 4})

        self.assertEqual([{"timestamp": 0, "v1": 1, "v2": 1},
                          {"timestamp": 1, "v1": 3, "v2": 3},
                          {"timestamp": 2, "v1": 4, "v2": 4}], series.get_data())
Ejemplo n.º 3
0
    def test_init_w_keys(self):

        ts = DataSeriesTest.factory.build_time_series(series_id="test",
                                                      keys=["v1"])

        series = DataSeries(time_series=ts)

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

        result = series.get_data()

        self.assertEqual(1, len(result))
        self.assertTrue("v1" in result[0])
        self.assertFalse("v2" in result[0])
Ejemplo n.º 4
0
    def test_init_w_data(self):
        ts = DataSeriesTest.factory.build_time_series(series_id="test",
                                                      keys=["v1"])
        DataSeriesTest.factory.add_time_series_item(ts, 0, {"v1": 1})
        DataSeriesTest.factory.add_time_series_item(ts, 1, {"v1": 2})
        series = DataSeries(time_series=ts)

        self.assertEqual(2, series.size())

        result = series.get_data()

        self.assertEqual(2, len(result))
        self.assertEqual(1, result[0]["v1"])
        self.assertEqual(2, result[1]["v1"])