[Git][NTPsec/ntpsec][wip-ntpq-peers-display] Fixed some rendering and added variables to cook() unit display.

Ian Bruene gitlab at mg.gitlab.com
Sun Mar 26 23:46:37 UTC 2017


Ian Bruene pushed to branch wip-ntpq-peers-display at NTPsec / ntpsec


Commits:
2563c137 by Ian Bruene at 2017-03-26T18:31:51-05:00
Fixed some rendering and added variables to cook() unit display.

Fixed bug in f8unit which would lead to displaying .00000000000001 as 10ms.

Out of unit bounds numbers are now rendered in scientific notation. No good
options here, anything else is just about guaranteed to blow the formatting.

0.0 is now rendered without decimal places.

Added temporary renderer for data in ppm.

Added some missing variables, including ppms, to the cook() handler. This can't
be completed until the Great Unit Hunt is complete.

- - - - -


2 changed files:

- + devel/units.txt
- pylib/util.py


Changes:

=====================================
devel/units.txt
=====================================
--- /dev/null
+++ b/devel/units.txt
@@ -0,0 +1,50 @@
+This document is a list of the important time variables and what units they represent in various areas throughout the program.
+
+System Variables
+
+Name                  | internal  | mode 6
+=================================================
+leap                  | seconds   | seconds (* presumed seconds)
+precision             | UNKNOWN   | UNKNOWN
+rootdelay             | seconds   | milliseconds
+rootdisp              | seconds   | milliseconds
+offset                | seconds   | milliseconds
+frequency (aka drift) | seconds/s | microseconds/s (aka ppm)
+sys_jitter            | seconds   | milliseconds
+clk_jitter            | seconds   | milliseconds
+clk_wander            | seconds/s | microseconds/s (probably ppm)
+leapsmearinterval     | seconds   | seconds
+leapsmearoffset       | seconds   | milliseconds
+mintc (aka CR_RATE)   | UNKNOWN   | UNKNOWN
+authdelay             | seconds   | milliseconds
+koffset               | seconds   | milliseconds
+kmaxerr               | seconds   | milliseconds
+kesterr               | seconds   | milliseconds
+kprecis               | seconds   | milliseconds
+kppsjitter            | seconds   | milliseconds
+fuzz                  | seconds   | milliseconds
+clk_wander_threshold  | seconds   | microseconds (probably ppm)
+tick                  | seconds   | milliseconds
+
+
+Peer Variables
+
+Name       | internal | mode 6
+=====================================
+in         | seconds  | milliseconds
+out        | seconds  | milliseconds
+rootdelay  | seconds  | milliseconds
+rootdisp   | seconds  | milliseconds
+bias       | seconds  | milliseconds
+delay      | seconds  | milliseconds
+offset     | seconds  | milliseconds
+jitter     | seconds  | milliseconds
+dispersion | seconds  | milliseconds
+
+
+Clock Variables
+
+Name       | internal | mode 6
+====================================
+fudgetime1 | seconds  | milliseconds
+fudgetime2 | seconds  | milliseconds


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -90,22 +90,31 @@ def f8unit(f, startingunit, strip=False):
     "Floating point formatting to show sign and unit in 8 characters"
     oldf = f
     f, unitsmoved = scaleforunit(f)
-    try:
-        unit = UNITS[startingunit + unitsmoved]
-    except IndexError:  # out of defined units revert to original, very ugly
-        rendered = ("%6f" % oldf) + UNITS[startingunit]  # but few options
-    if abs(f).is_integer():
-        rendered = ("%6d" % f) + unit
-    elif abs(f) >= 100.0:  # +xxx.x
-        rendered = ("%6.1f" % f) + unit
-    elif abs(f) >= 10.0:  # +xx.xx
-        rendered = ("%6.2f" % f) + unit
-    elif abs(f) >= 1.0:  # +x.xxx
-        rendered = ("%6.3f" % f) + unit
-    else:  # zero, if it weren't then scaleforunit would have moved it up
-        rendered = ("%6.3f" % oldf) + unit
+    unitget = startingunit + unitsmoved
+    if (0 <= unitget < len(UNITS)):
+        unit = UNITS[unitget]
+        if abs(f).is_integer():
+            rendered = ("%6d" % f) + unit
+        elif abs(f) >= 100.0:  # +xxx.x
+            rendered = ("%6.1f" % f) + unit
+        elif abs(f) >= 10.0:  # +xx.xx
+            rendered = ("%6.2f" % f) + unit
+        elif abs(f) >= 1.0:  # +x.xxx
+            rendered = ("%6.3f" % f) + unit
+        else:  # zero, if it weren't then scaleforunit would have moved it up
+            rendered = ("%6d" % oldf) + unit
+    else:  # Out of units so revert to the original. Ugly but there are very
+        rendered = repr(oldf) + UNITS[startingunit]  # few options here.
+    if strip:
+        return rendered.strip()
+    return rendered
+
+
+def ppmformathack(f, strip=False):
+    "Format a float as ppm, a hack until the Great Unit Hunt is ended."
+    rendered = ("%5f" % f) + "ppm"
     if strip:
-        return rendered.lstrip().rstrip()
+        rendered = rendered.strip()
     return rendered
 
 
@@ -335,11 +344,17 @@ def cook(variables, showunits=False):
                       "clk_jitter", "leapsmearoffset", "authdelay",
                       "koffset", "kmaxerr", "kesterr", "kprecis",
                       "kppsjitter", "fuzz", "clk_wander_threshold",
-                      "tick"):
+                      "tick", "in", "out", "bias", "delay", "jitter",
+                      "dispersion", "fudgetime1", "fudgetime2"):
+            #  Note that this is *not* complete, there are definitely
+            #   missing variables here, and other units (ppm).
+            #  Completion cannot occur until all units are tracked down.
             if showunits:
                 item += f8unit(value, UNIT_MS, True)
             else:
                 item += repr(value)
+        elif name in ("frequency", "clk_wander", "clk_wander_threshold"):
+            item += ppmformathack(value, True)
         else:
             item += repr(value)
         item += ", "



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/2563c1376b2d5bdde18c1430738c3747b6e8b409
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170326/ad561f6a/attachment.html>


More information about the vc mailing list