From 8849990ed290b06c5ff13bd28fa834b2dd55b6df Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 28 Apr 2022 14:59:32 +0100 Subject: [PATCH] svc/connect.in: Fix latent type errors in info output. Before we've had an answer to the first `ping', the mean and standard deviation aren't properly defined. We attempt to avoid this by setting them to `-', but then try to format them using `%f', which isn't going to work well. Fix this and some related problems with the minimum and maximum times. --- svc/connect.in | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/svc/connect.in b/svc/connect.in index 836ea2f3..aaf68ded 100644 --- a/svc/connect.in +++ b/svc/connect.in @@ -510,21 +510,24 @@ class PingPeer (object): def info(me): if not me._nping: - mean = sd = '-' + mean = sd = min = max = '-' else: - mean = me._sigma_t/me._nping - sd = sqrt(me._sigma_t2/me._nping - mean*mean) + meanval = me._sigma_t/me._nping + mean = '%.1fms' % meanval + sd = '%.1fms' % sqrt(me._sigma_t2/me._nping - meanval*meanval) + min = '%.1fms' % me._min + max = '%.1fms' % me._max n = me._nping + me._nlost if not n: pclost = '-' else: pclost = '%d' % ((100*me._nlost + n//2)//n) return { 'last-ping': me._last, - 'mean-ping': '%.1fms' % mean, - 'sd-ping': '%.1fms' % sd, + 'mean-ping': mean, + 'sd-ping': sd, 'n-ping': '%d' % me._nping, 'n-lost': '%d' % me._nlost, 'percent-lost': pclost, - 'min-ping': '%.1fms' % me._min, - 'max-ping': '%.1fms' % me._max, + 'min-ping': min, + 'max-ping': max, 'state': me._timer and 'idle' or 'check', 'failures': str(me._failures) } -- 2.11.0