Yo All!

Please don't laugh too hard.  Attached is my first Python program, to
make the adev plot.

Next I need to figure out Python process control and get rid of the
shell script.

Still unresolved, the best way to handle minpoll andmissing data points.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        [email protected]  Tel:+1 541 382 8588

Attachment: adev.plot
Description: Binary data

#!/usr/bin/env python

# this program takes an NTP peerstats time and changes it to
# a unix time stamp.  The rest of the line is unchanged.
#
# a peerstats line looks like this:
# 57589 0.805 127.127.28.1 961a -0.000021843 0.000000000 0.000233609 0.000005153
#
# column one is the GPS week, column two is the seconds into the week.
#
# our result will be:
#1468972800.805 127.127.28.1 961a -0.000021843 0.000000000 0.000233609 0.000005153
#

# for regular expressions
import re
# for stdin, stdout
import sys

if 2 != len(sys.argv):
    print 'Usage:\n' \
          ' timestamps.py [refclock]\n'
    exit(1)

# I found compiling the regex was no win
# so don't do it

# tuples for empty refclock lines
refs = []

for line in sys.stdin:
    #print line
    # week time refclock offset etc.
    m = re.match( "^([0-9]+) ([0-9.]+) ([0-9.]+) ([^ ]+) ([^ ]+) (.*)", line)
    if None == m:
        # bad line
        continue

    if sys.argv[1] != m.groups()[2]:
        # wrong refclock
        continue

    # calculate the UNIX time
    mjd    = long( m.groups()[0] )
    second = float( m.groups()[1] )
    epoch = 24 * 60 * 60 * mjd + second - 3506716800L;
    #print '{:-.3f}'.format(epoch) , m.groups()[2] , m.groups()[3]
    refs.append( (epoch , m.groups()[2] , m.groups()[4]) )


# sort by time
refs.sort( key=lambda ref: ref[0])

for ref in refs:
    print ref[2]

Attachment: adev.sh
Description: application/shellscript

Attachment: pgplIIwFmsmSJ.pgp
Description: OpenPGP digital signature

_______________________________________________
devel mailing list
[email protected]
http://lists.ntpsec.org/mailman/listinfo/devel

Reply via email to