From d3334b29d9124b8a9e9c2dbfcdd6e125e471c412 Mon Sep 17 00:00:00 2001 From: MirceaDan Date: Sat, 1 Dec 2018 22:26:30 -0800 Subject: [PATCH] fix for tests and previous commit regarding estimations tests needed updated None replaced with -1 --- src/octoprint/printer/estimation.py | 13 +++++-------- tests/printer/test_estimation.py | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/octoprint/printer/estimation.py b/src/octoprint/printer/estimation.py index 4cab68473..f778d7d5b 100644 --- a/src/octoprint/printer/estimation.py +++ b/src/octoprint/printer/estimation.py @@ -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,7 +217,7 @@ class TimeEstimationHelper(object): @property def average_total(self): if not self._count: - return -1 + return 0 else: return self._sum_total / self._count diff --git a/tests/printer/test_estimation.py b/tests/printer/test_estimation.py index b164b21bd..15076562e 100644 --- a/tests/printer/test_estimation.py +++ b/tests/printer/test_estimation.py @@ -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), )