John's Vademecum

Try to learn something about everything, and everything about something -Thomas Huxley “Darwin's bulldog” (1824-1895)

User Tools

Site Tools


public:musings:watches:watchcheck

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:musings:watches:watchcheck [23/01/26 13:53 GMT] johnpublic:musings:watches:watchcheck [23/01/26 14:13 GMT] (current) john
Line 11: Line 11:
 You put the application in a directory specific to the watch and execute it from that You put the application in a directory specific to the watch and execute it from that
 directory. the data from each measurement is stored in a **json** file in the same directory. directory. the data from each measurement is stored in a **json** file in the same directory.
 +
 +** update 23/01/26 **  I've modified the code to run under Python 3 - using the tool ''2to3'' and a minor manual tweak.
 +
  
 ++++ watchcheck.py in Python 3 | ++++ watchcheck.py in Python 3 |
  
-<code python>+<file python watchcheck.py>
            
 # a text-terminal version of the WatchCheck app # a text-terminal version of the WatchCheck app
Line 211: Line 214:
  
  
-</code>+</file>
  
 ++++ ++++
Line 219: Line 222:
 ++++ original watchcheck.py in python 2 | ++++ original watchcheck.py in python 2 |
  
-<code python>+<file python watchcheck.py>
  
 #! /usr/bin/env python #! /usr/bin/env python
Line 424: Line 427:
  
 <code> <code>
 +
 Wire2waves WatchCheck..... Wire2waves WatchCheck.....
 ========================= =========================
Line 501: Line 505:
 display the data display the data
  
-++++ watchstat.py |+++++ original watchstat.py in python 2|
  
 <file python watchstat.py> <file python watchstat.py>
 +
 #! /usr/bin/env python #! /usr/bin/env python
  
Line 611: Line 616:
  
 ++++ ++++
 +
 +++++ watchstat.py in python 3 |
 +
 +<file python watchstat.py>
 +
 +## a text-terminal version of the WatchCheck app
 +## to track error, daily error rate of timepieces.
 +
 +#
 +import time
 +import datetime
 +import json
 +
 +
 +
 +def watch_stat():
 +
 +    try:
 +        saved_error = open('error_list.json')
 +        error_list = json.load(saved_error)
 +    except:
 +        error_list = []
 +
 +
 +
 +
 +    if len(error_list) > 1:
 +        first_record = error_list[0]
 +        latest_record = error_list[-1]
 +        previous_record = error_list[-2]
 +
 +        first_time = first_record[0]
 +
 +        first_delta = first_record[1]
 +
 +        latest_time = latest_record[0] 
 +        latest_delta = latest_record[1]
 +
 +        previous_time = previous_record[0]
 +        previous_delta = previous_record[1]
 +
 +        FMT = '%Y/%m/%d %H:%M:%S'
 +    
 +        t_latest = datetime.datetime.strptime(latest_time, FMT)
 +        t_previous = datetime.datetime.strptime(previous_time, FMT)
 +        t_first = datetime.datetime.strptime(first_time, FMT)
 +
 +        tdelta = t_latest - t_previous
 +        full_delta = t_latest - t_first
 +
 +        elapsed_time = tdelta.total_seconds()
 +
 +        full_time = full_delta.total_seconds()
 +
 +        print("First record time ", first_time)
 +        print("First record delta ", first_delta)
 +        print("")
 +
 +        print("Previous record time ", previous_time)
 +        print("Previous record delta ", previous_delta)
 +        print("")
 +
 +        print("Latest record time " , latest_time)
 +        print("Latest record delta ", latest_delta)
 +        print("")
 +    
 +        print("Overall elapsed time ", full_delta)
 +        print("Latest elapsed time ", tdelta)
 +        print("")
 +
 +        # Current Error rate
 +        time_error = latest_delta - previous_delta
 +        error_rate = time_error / elapsed_time
 +        daily_rate = error_rate * (60*60*24)
 +        ppm_daily = error_rate * 1000000
 +
 +        # Overall Error rate
 +        total_error = latest_delta - first_delta
 +        average_error_rate = total_error / full_time
 +
 +        average_rate = average_error_rate * (60*60*24)
 +        ppm_overall = average_error_rate * 1000000
 +
 +
 +        print("Latest delta change ", time_error)
 +
 +        print("Latest elapsed time %d seconds " % (elapsed_time))
 +
 +        print("")
 +        print("Daily PPM : %0.3f" % ppm_daily)
 +        print("Daily rate error: %0.1f s/d " % (daily_rate))
 +
 +        print("")
 +        print("Total Time %d seconds" % (full_time))
 +        print("Total error ", total_error)
 +        print("Total PPM : %0.3f" % ppm_overall)
 +        print("Total rate error: %0.1f s/d" % (average_rate))
 +        print("")
 +        print("========================================================")
 +        print(" Delta : %0.1f s | Rate : %0.1f s/d | Average : %0.1f s/d" % (latest_delta, daily_rate, average_rate))
 +        print("========================================================")
 +        print("")
 +    else:
 +        print("No rate yet")
 +
 +
 +watch_stat()
 +
 +</file>
 +
 +++++
 +
  
 Running watchstat.py on the newly updated ''error_list.json''  Running watchstat.py on the newly updated ''error_list.json'' 
public/musings/watches/watchcheck.1769176426.txt.gz · Last modified: by john