Exemple #1
0
    def get_snapshot(self):
        time_range = self.config["time_range"]
        if self.config["align_to_start"]:
            from_time = utils.floor_time(utils.now(), time_range)
        else:
            from_time = utils.relative_to_now(-time_range)

        d = self.backend.get_data(from_time=from_time)
        d.addCallback(self.process_backend_response)
        return d
Exemple #2
0
    def get_snapshot(self):
        time_range = self.config['time_range']

        if self.config['align_to_start']:
            until_time = utils.floor_time(utils.now(), time_range)
        else:
            until_time = utils.now()

        # ask for time since double the time range so we can compare with the
        # previous time range
        from_time = until_time - (time_range * 2)
        d = self.backend.get_data(from_time=from_time)
        d.addCallback(self.handle_backend_response, until_time)
        return d
Exemple #3
0
    def test_floor_time_relative(self):
        self.assertEqual(utils.floor_time(1, 5, 3), 0)
        self.assertEqual(utils.floor_time(2, 5, 3), 0)
        self.assertEqual(utils.floor_time(3, 5, 3), 3)
        self.assertEqual(utils.floor_time(5, 5, 3), 3)
        self.assertEqual(utils.floor_time(6, 5, 3), 3)
        self.assertEqual(utils.floor_time(7, 5, 3), 3)
        self.assertEqual(utils.floor_time(8, 5, 3), 8)
        self.assertEqual(utils.floor_time(9, 5, 3), 8)
        self.assertEqual(utils.floor_time(10, 5, 3), 8)
        self.assertEqual(utils.floor_time(11, 5, 3), 8)
        self.assertEqual(utils.floor_time(13, 5, 3), 13)
        self.assertEqual(utils.floor_time(14, 5, 3), 13)

        self.assertEqual(utils.floor_time(1, 5, 18), 0)
        self.assertEqual(utils.floor_time(2, 5, 18), 0)
        self.assertEqual(utils.floor_time(3, 5, 18), 3)
        self.assertEqual(utils.floor_time(5, 5, 18), 3)
        self.assertEqual(utils.floor_time(6, 5, 18), 3)
        self.assertEqual(utils.floor_time(7, 5, 18), 3)
        self.assertEqual(utils.floor_time(8, 5, 18), 8)
        self.assertEqual(utils.floor_time(9, 5, 18), 8)
        self.assertEqual(utils.floor_time(10, 5, 18), 8)
        self.assertEqual(utils.floor_time(11, 5, 18), 8)
        self.assertEqual(utils.floor_time(13, 5, 18), 13)
        self.assertEqual(utils.floor_time(14, 5, 18), 13)
Exemple #4
0
    def test_floor_time(self):
        self.assertEqual(utils.floor_time(2, 5), 0)
        self.assertEqual(utils.floor_time(3, 5), 0)
        self.assertEqual(utils.floor_time(5, 5), 5)
        self.assertEqual(utils.floor_time(6, 5), 5)
        self.assertEqual(utils.floor_time(7, 5), 5)
        self.assertEqual(utils.floor_time(8, 5), 5)
        self.assertEqual(utils.floor_time(9, 5), 5)
        self.assertEqual(utils.floor_time(10, 5), 10)

        self.assertEqual(utils.floor_time(3, 10), 0)
        self.assertEqual(utils.floor_time(5, 10), 0)
        self.assertEqual(utils.floor_time(10, 10), 10)
        self.assertEqual(utils.floor_time(12, 10), 10)
        self.assertEqual(utils.floor_time(13, 10), 10)
        self.assertEqual(utils.floor_time(15, 10), 10)
        self.assertEqual(utils.floor_time(18, 10), 10)
        self.assertEqual(utils.floor_time(22, 10), 20)