svc/connect.in: Fix latent type errors in info output.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 28 Apr 2022 13:59:32 +0000 (14:59 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 Apr 2022 15:01:31 +0000 (16:01 +0100)
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

index 836ea2f..aaf68de 100644 (file)
@@ -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) }