def test_get_by_time(self): ts = DataSeriesTest.factory.build_time_series(series_id="test", keys=["timestamp", "v1", "v2"]) series = DataSeries(time_series=ts) # time and key series.add(data={"timestamp": 0, "v1": 2}) series.add(data={"timestamp": 1, "v1": 2.4}) series.add(data={"timestamp": 1, "v2": 3.0}) self.assertEqual(2, series.get_by_time(time=0, keys="v1")) self.assertEqual(0.0, series.get_by_time(time=0, keys="v2")) self.assertEqual(2.4, series.get_by_time(time=1, keys="v1")) self.assertEqual(3.0, series.get_by_time(time=1, keys="v2")) # time only self.assertEqual({"timestamp": 0, "v1": 2, "v2": 0.0}, series.get_by_time(time=0)) self.assertEqual({"timestamp": 1, "v1": 2.4, "v2": 3.0}, series.get_by_time(time=1))
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"))