Merge "api: use delta_seconds()"
This commit is contained in:
commit
6d70a85850
@ -324,12 +324,8 @@ class Statistics(Base):
|
|||||||
if (self.duration_start and
|
if (self.duration_start and
|
||||||
self.duration_end and
|
self.duration_end and
|
||||||
self.duration_start <= self.duration_end):
|
self.duration_start <= self.duration_end):
|
||||||
# Can't use timedelta.total_seconds() because
|
self.duration = timeutils.delta_seconds(self.duration_start,
|
||||||
# it is not available in Python 2.6.
|
self.duration_end)
|
||||||
diff = self.duration_end - self.duration_start
|
|
||||||
self.duration = (diff.seconds + (diff.days * 24 * 60 ** 2)) / 60
|
|
||||||
# FIXME(dhellmann): Shouldn't this value be returned in
|
|
||||||
# seconds, or something even smaller?
|
|
||||||
else:
|
else:
|
||||||
self.duration_start = self.duration_end = self.duration = None
|
self.duration_start = self.duration_end = self.duration = None
|
||||||
|
|
||||||
|
@ -570,10 +570,7 @@ def compute_duration_by_resource(resource, meter):
|
|||||||
# sentinal indicating that there is something "funny"
|
# sentinal indicating that there is something "funny"
|
||||||
# about the range.
|
# about the range.
|
||||||
if min_ts and max_ts and (min_ts <= max_ts):
|
if min_ts and max_ts and (min_ts <= max_ts):
|
||||||
# Can't use timedelta.total_seconds() because
|
duration = timeutils.delta_seconds(min_ts, max_ts)
|
||||||
# it is not available in Python 2.6.
|
|
||||||
diff = max_ts - min_ts
|
|
||||||
duration = (diff.seconds + (diff.days * 24 * 60 ** 2)) / 60
|
|
||||||
else:
|
else:
|
||||||
min_ts = max_ts = duration = None
|
min_ts = max_ts = duration = None
|
||||||
|
|
||||||
|
@ -80,14 +80,14 @@ class TestComputeDurationByResource(tests_api.TestBase):
|
|||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['start_timestamp'], self.start)
|
self._assert_times_match(data['start_timestamp'], self.start)
|
||||||
self._assert_times_match(data['end_timestamp'], self.middle1)
|
self._assert_times_match(data['end_timestamp'], self.middle1)
|
||||||
assert data['duration'] == 8 * 60
|
self.assertEqual(data['duration'], 8 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range(self):
|
def test_within_range(self):
|
||||||
self._set_interval(self.middle1, self.middle2)
|
self._set_interval(self.middle1, self.middle2)
|
||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['start_timestamp'], self.middle1)
|
self._assert_times_match(data['start_timestamp'], self.middle1)
|
||||||
self._assert_times_match(data['end_timestamp'], self.middle2)
|
self._assert_times_match(data['end_timestamp'], self.middle2)
|
||||||
assert data['duration'] == 10 * 60
|
self.assertEqual(data['duration'], 10 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range_zero_duration(self):
|
def test_within_range_zero_duration(self):
|
||||||
self._set_interval(self.middle1, self.middle1)
|
self._set_interval(self.middle1, self.middle1)
|
||||||
@ -101,7 +101,7 @@ class TestComputeDurationByResource(tests_api.TestBase):
|
|||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['start_timestamp'], self.middle2)
|
self._assert_times_match(data['start_timestamp'], self.middle2)
|
||||||
self._assert_times_match(data['end_timestamp'], self.end)
|
self._assert_times_match(data['end_timestamp'], self.end)
|
||||||
assert data['duration'] == (6 * 60) - 1
|
self.assertEqual(data['duration'], ((6 * 60) - 1) * 60)
|
||||||
|
|
||||||
def test_after_range(self):
|
def test_after_range(self):
|
||||||
self._set_interval(self.late1, self.late2)
|
self._set_interval(self.late1, self.late2)
|
||||||
|
@ -99,14 +99,14 @@ class TestComputeDurationByResource(FunctionalTest):
|
|||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['duration_start'], self.start)
|
self._assert_times_match(data['duration_start'], self.start)
|
||||||
self._assert_times_match(data['duration_end'], self.middle1)
|
self._assert_times_match(data['duration_end'], self.middle1)
|
||||||
assert data['duration'] == 8 * 60
|
self.assertEqual(data['duration'], 8 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range(self):
|
def test_within_range(self):
|
||||||
self._set_interval(self.middle1, self.middle2)
|
self._set_interval(self.middle1, self.middle2)
|
||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['duration_start'], self.middle1)
|
self._assert_times_match(data['duration_start'], self.middle1)
|
||||||
self._assert_times_match(data['duration_end'], self.middle2)
|
self._assert_times_match(data['duration_end'], self.middle2)
|
||||||
assert data['duration'] == 10 * 60
|
self.assertEqual(data['duration'], 10 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range_zero_duration(self):
|
def test_within_range_zero_duration(self):
|
||||||
self._set_interval(self.middle1, self.middle1)
|
self._set_interval(self.middle1, self.middle1)
|
||||||
@ -120,7 +120,7 @@ class TestComputeDurationByResource(FunctionalTest):
|
|||||||
data = self._invoke_api()
|
data = self._invoke_api()
|
||||||
self._assert_times_match(data['duration_start'], self.middle2)
|
self._assert_times_match(data['duration_start'], self.middle2)
|
||||||
self._assert_times_match(data['duration_end'], self.end)
|
self._assert_times_match(data['duration_end'], self.end)
|
||||||
assert data['duration'] == (6 * 60) - 1
|
self.assertEqual(data['duration'], ((6 * 60) - 1) * 60)
|
||||||
|
|
||||||
def test_after_range(self):
|
def test_after_range(self):
|
||||||
self._set_interval(self.late1, self.late2)
|
self._set_interval(self.late1, self.late2)
|
||||||
|
@ -66,7 +66,7 @@ class TestStatisticsDuration(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
assert s.duration_start == self.start
|
assert s.duration_start == self.start
|
||||||
assert s.duration_end == self.middle1
|
assert s.duration_end == self.middle1
|
||||||
assert s.duration == 8 * 60
|
self.assertEqual(s.duration, 8 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range(self):
|
def test_within_range(self):
|
||||||
s = v2.Statistics(duration_start=self.middle1,
|
s = v2.Statistics(duration_start=self.middle1,
|
||||||
@ -76,7 +76,7 @@ class TestStatisticsDuration(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
assert s.duration_start == self.middle1
|
assert s.duration_start == self.middle1
|
||||||
assert s.duration_end == self.middle2
|
assert s.duration_end == self.middle2
|
||||||
assert s.duration == 10 * 60
|
self.assertEqual(s.duration, 10 * 60 * 60)
|
||||||
|
|
||||||
def test_within_range_zero_duration(self):
|
def test_within_range_zero_duration(self):
|
||||||
s = v2.Statistics(duration_start=self.middle1,
|
s = v2.Statistics(duration_start=self.middle1,
|
||||||
@ -96,7 +96,7 @@ class TestStatisticsDuration(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
assert s.duration_start == self.middle2
|
assert s.duration_start == self.middle2
|
||||||
assert s.duration_end == self.end
|
assert s.duration_end == self.end
|
||||||
assert s.duration == (6 * 60) - 1
|
self.assertEqual(s.duration, ((6 * 60) - 1) * 60)
|
||||||
|
|
||||||
def test_after_range(self):
|
def test_after_range(self):
|
||||||
s = v2.Statistics(duration_start=self.late1,
|
s = v2.Statistics(duration_start=self.late1,
|
||||||
|
Loading…
Reference in New Issue
Block a user