Merge commit 'd3334b29d9124b8a9e9c2dbfcdd6e125e471c412' into py23

This commit is contained in:
Matthias Urlichs committed 2019-01-27 17:13:28 +01:00
commit 353309fc60
2 files changed
+10 -13

No files matched your search

+7 -10
View File
@@ -189,10 +189,10 @@ class TimeEstimationHelper(object):
self._totals = collections.deque([], self._rolling_window)
self._sum_total = 0
self._count = 0
self._stable_counter = None
self._stable_counter = -1
def is_stable(self):
return self._stable_counter is not None and self._stable_counter >= self._countdown
return self._stable_counter >= self._countdown
def update(self, new_estimate):
old_average_total = self.average_total
@@ -205,12 +205,9 @@ class TimeEstimationHelper(object):
self._distances.append(abs(self.average_total - old_average_total))
if -1.0 * self._threshold < self.average_distance < self._threshold:
if self._stable_counter is None:
self._stable_counter = 0
else:
self._stable_counter += 1
self._stable_counter += 1
else:
self._stable_counter = None
self._stable_counter = -1
if self.is_stable():
return self.average_total_rolling
@@ -220,20 +217,20 @@ class TimeEstimationHelper(object):
@property
def average_total(self):
if not self._count:
return None
return 0
else:
return self._sum_total / self._count
@property
def average_total_rolling(self):
if not self._count or self._count < self._rolling_window:
return None
return -1
else:
return sum(self._totals) / len(self._totals)
@property
def average_distance(self):
if not self._count or self._count < self._rolling_window + 1:
return None
return -1
else:
return sum(self._distances) / len(self._distances)
+3 -3
View File
@@ -35,8 +35,8 @@ class EstimationTestCase(unittest.TestCase):
self.assertEqual(self.estimation_helper.average_total, expected)
@data(
((1.0, 2.0), None), # not enough values, have 1, need 3
((1.0, 2.0, 3.0), None), # not enough values, have 2, need 3
((1.0, 2.0), -1), # not enough values, have 1, need 3
((1.0, 2.0, 3.0), -1), # not enough values, have 2, need 3
((1.0, 2.0, 3.0, 4.0), 0.5), # average totals: 1.0, 1.5, 2.0, 2.5 => (3 * 0.5 / 3 = 0.5
((1.0, 2.0, 3.0, 4.0, 5.0), 0.5), # average totals: 1.0, 1.5, 2.0, 2.5, 3.0 => (0.5 + 0.5 + 0.5) / 3 = 0.5
((1.0, 2.0, 0.0, 1.0, 2.0), 0.7 / 3) # average totals: 1.0, 1.5, 1.0, 1.0, 1.2 => (0.5 + 0.0 + 0.2) / 3 = 0.7 / 3
@@ -49,7 +49,7 @@ class EstimationTestCase(unittest.TestCase):
self.assertEqual(self.estimation_helper.average_distance, expected)
@data(
((1.0, 1.0), None),
((1.0, 1.0), -1),
((1.0, 1.0, 1.0), 1.0),
((1.0, 2.0, 3.0, 4.0, 5.0), 4.0),
)