def __init__(self, *args, **kwargs): """Initialize attributes. :param host: Optional. The hostname where redis is running. :param port: Optional. The port where redis is running. """ super().__init__() # The Redis connection object. self._redis = None self._redis_params = kwargs.get('redis_params', {}) # Running coordination. self._should_stop = False self._runner_coro = None # The verbosity level to pass around to Resolwe utilities # such as data_purge. self._verbosity = kwargs.get('verbosity', 1) # Statistics about how much time each event needed for handling. self.service_time = stats.NumberSeriesShape() # Statistics about the number of events handled per time interval. self.load_avg = stats.SimpleLoadAvg([60, 5 * 60, 15 * 60]) # Timestamp of last critical load error and level, for throttling. self.last_load_log = -math.inf self.last_load_level = 0
def test_shape_basic(self): series = stats.NumberSeriesShape() self.assertEqual( series.to_dict(), { 'high': -math.inf, 'low': math.inf, 'mean': 0, 'count': 0, 'deviation': 0, }) series.update(1) self.assertEqual(series.count, 1) self.assertAlmostEqual(series.high, 1.0) self.assertAlmostEqual(series.low, 1.0) self.assertAlmostEqual(series.mean, 1.0) self.assertAlmostEqual(series.deviation, 0.0) for _ in range(5): series.update(1) self.assertEqual(series.count, 6) self.assertAlmostEqual(series.high, 1.0) self.assertAlmostEqual(series.low, 1.0) self.assertAlmostEqual(series.mean, 1.0) self.assertAlmostEqual(series.deviation, 0.0) large = 1000000.0 series.update(large) series.update(-large) self.assertAlmostEqual(series.high, large) self.assertAlmostEqual(series.low, -large) self.assertAlmostEqual(series.mean, 0.75) self.assertAlmostEqual(series.deviation, 534522.483825049)
def test_shape_basic(self): series = stats.NumberSeriesShape() self.assertEqual( series.to_dict(), { "high": -math.inf, "low": math.inf, "mean": 0, "count": 0, "deviation": 0, }, ) series.update(1) self.assertEqual(series.count, 1) self.assertAlmostEqual(series.high, 1.0) self.assertAlmostEqual(series.low, 1.0) self.assertAlmostEqual(series.mean, 1.0) self.assertAlmostEqual(series.deviation, 0.0) for _ in range(5): series.update(1) self.assertEqual(series.count, 6) self.assertAlmostEqual(series.high, 1.0) self.assertAlmostEqual(series.low, 1.0) self.assertAlmostEqual(series.mean, 1.0) self.assertAlmostEqual(series.deviation, 0.0) large = 1000000.0 series.update(large) series.update(-large) self.assertAlmostEqual(series.high, large) self.assertAlmostEqual(series.low, -large) self.assertAlmostEqual(series.mean, 0.75) self.assertAlmostEqual(series.deviation, 534522.483825049)
def test_shape_tricky(self): series = stats.NumberSeriesShape() for _ in range(10): series.update(1) for _ in range(10): series.update(-1) self.assertAlmostEqual(series.mean, 0.0) self.assertAlmostEqual(series.deviation, 1.02597835208515)