def test_size(self): avg = WeightedAverage(3) assert_that(avg.size, equal_to(3)) avg.weight = [3] avg.add(4, 5, 7) assert_that(avg.size, equal_to(1)) assert_that(avg.value(), equal_to(7))
class NodeInfo(object): def __init__(self, name, ip, available=None, working=False): """ constructor for `NodeInfo`. :param name: name of the node, could be `spa`, or `spb` :param ip: ip address of the node :param available: indicate whether this node is alive. :param working: indicate whether this node is executing command. :return: """ self.name = VNXSPEnum.parse(name) self.ip = ip.strip('\'" ') if available is None: available = True self._available = available self.timestamp = None self.working = working self._latency = WeightedAverage() @property def available(self): return self._available @available.setter def available(self, available): self._available = available self.timestamp = datetime.now() def is_updated_within(self, seconds): current = datetime.now() if self.timestamp is None: ret = False else: delta = current - self.timestamp ret = delta.total_seconds() < seconds return ret @property def latency(self): return self._latency.value() @latency.setter def latency(self, value): self._latency.add(value) def __repr__(self): props_to_print = [ 'name', 'ip', 'available', 'working', 'latency', 'timestamp' ] info = ', '.join( ['{}: {}'.format(p, getattr(self, p)) for p in props_to_print]) return info def __str__(self): return self.__repr__()
def __init__(self, name, ip, available=None, working=False): """ constructor for `NodeInfo`. :param name: name of the node, could be `spa`, or `spb` :param ip: ip address of the node :param available: indicate whether this node is alive. :param working: indicate whether this node is executing command. :return: """ self.name = VNXSPEnum.parse(name) self.ip = ip.strip('\'" ') if available is None: available = True self._available = available self.timestamp = None self.working = working self._latency = WeightedAverage()
class NodeInfo(object): def __init__(self, name, ip, available=None, working=False): """ constructor for `NodeInfo`. :param name: name of the node, could be `spa`, or `spb` :param ip: ip address of the node :param available: indicate whether this node is alive. :param working: indicate whether this node is executing command. :return: """ self.name = VNXSPEnum.from_str(name) self.ip = ip if available is None: available = True self._available = available self.timestamp = None self.working = working self._latency = WeightedAverage() @property def available(self): return self._available @available.setter def available(self, available): self._available = available self.timestamp = datetime.now() @property def latency(self): return self._latency.value() @latency.setter def latency(self, value): self._latency.add(value) def __repr__(self): props_to_print = ['name', 'ip', 'available', 'working', 'latency', 'timestamp'] info = ', '.join(['{}: {}'.format(p, getattr(self, p)) for p in props_to_print]) return info def __str__(self): return self.__repr__()
def __init__(self, name, ip, available=None, working=False): """ constructor for `NodeInfo`. :param name: name of the node, could be `spa`, or `spb` :param ip: ip address of the node :param available: indicate whether this node is alive. :param working: indicate whether this node is executing command. :return: """ self.name = VNXSPEnum.from_str(name) self.ip = ip if available is None: available = True self._available = available self.timestamp = None self.working = working self._latency = WeightedAverage()
def test_data_empty(self): avg = WeightedAverage(3) assert_that(avg.value(), equal_to(0))
def test_data_not_full(self): avg = WeightedAverage(3) avg.add(12, 6) assert_that(avg.value(), equal_to(8.4))
def test_data_full_1(self): avg = WeightedAverage(6) avg.add(30, 24, 18, 12, 6, 6, 6) assert_that(avg.value(), close_to(8.85, 0.01)) avg.add(30) assert_that(avg.value(), equal_to(14))
def test_data_full(self): avg = WeightedAverage(3) avg.add(30, 24, 18, 12, 6) assert_that(avg.value(), equal_to(10)) avg.add(30) assert_that(avg.value(), equal_to(19))