public:musings:watches:watchcheck
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| public:musings:watches:watchcheck [30/12/25 09:55 GMT] – created - external edit 127.0.0.1 | public:musings:watches:watchcheck [23/01/26 14:13 GMT] (current) – john | ||
|---|---|---|---|
| Line 12: | Line 12: | ||
| 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. | ||
| - | ++++ watchcheck.py | | + | ** update 23/01/26 ** I've modified the code to run under Python 3 - using the tool '' |
| + | |||
| + | |||
| + | ++++ watchcheck.py | ||
| <file python watchcheck.py> | <file python watchcheck.py> | ||
| + | |||
| + | # a text-terminal version of the WatchCheck app | ||
| + | ## to track error, daily error rate of timepieces. | ||
| + | # auto update? | ||
| + | # | ||
| + | import time | ||
| + | import datetime | ||
| + | import json | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | def write_file(text): | ||
| + | filename = " | ||
| + | f = open(filename, | ||
| + | timenow = time.strftime(" | ||
| + | log = " " | ||
| + | f.write(log) | ||
| + | f.close() | ||
| + | |||
| + | |||
| + | |||
| + | def get_delta(): | ||
| + | |||
| + | print(time.strftime(" | ||
| + | |||
| + | h = time.strftime(" | ||
| + | w = input(" | ||
| + | print(w) | ||
| + | |||
| + | date = time.strftime(" | ||
| + | s = date + " " + h +":" | ||
| + | |||
| + | input(" | ||
| + | |||
| + | watchtime = time.mktime(datetime.datetime.strptime(s, | ||
| + | record_time = time.strftime(" | ||
| + | timenow = time.time() | ||
| + | delta = watchtime - timenow | ||
| + | |||
| + | return record_time, | ||
| + | |||
| + | |||
| + | def watch_stat(): | ||
| + | |||
| + | try: | ||
| + | saved_error = open(' | ||
| + | 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 = ' | ||
| + | |||
| + | t_latest = datetime.datetime.strptime(latest_time, | ||
| + | t_previous = datetime.datetime.strptime(previous_time, | ||
| + | t_first = datetime.datetime.strptime(first_time, | ||
| + | |||
| + | tdelta = t_latest - t_previous | ||
| + | full_delta = t_latest - t_first | ||
| + | |||
| + | elapsed_time = tdelta.total_seconds() | ||
| + | |||
| + | full_time = full_delta.total_seconds() | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | 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(" | ||
| + | |||
| + | print(" | ||
| + | |||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | |||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | text = " | ||
| + | write_file(text) | ||
| + | else: | ||
| + | print(" | ||
| + | |||
| + | |||
| + | def new_record(): | ||
| + | |||
| + | try: | ||
| + | saved_error = open(' | ||
| + | error_list = json.load(saved_error) | ||
| + | except: | ||
| + | error_list = [] | ||
| + | |||
| + | s,delta = get_delta() | ||
| + | |||
| + | print("" | ||
| + | print(" | ||
| + | last_data=[s, | ||
| + | error_list.append(last_data) | ||
| + | #print error_list | ||
| + | |||
| + | with open(' | ||
| + | json.dump(error_list, | ||
| + | |||
| + | return | ||
| + | |||
| + | def delete_last(): | ||
| + | try: | ||
| + | saved_error = open(' | ||
| + | error_list = json.load(saved_error) | ||
| + | except: | ||
| + | error_list = [] | ||
| + | error_list.pop() | ||
| + | |||
| + | with open(' | ||
| + | json.dump(error_list, | ||
| + | |||
| + | return | ||
| + | |||
| + | |||
| + | def menu(): | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | choice = input(" | ||
| + | if choice == " | ||
| + | print(" | ||
| + | new_record() | ||
| + | watch_stat() | ||
| + | menu() | ||
| + | elif choice == " | ||
| + | print(" | ||
| + | watch_stat() | ||
| + | menu() | ||
| + | elif choice == " | ||
| + | delete_last() | ||
| + | watch_stat() | ||
| + | menu() | ||
| + | elif choice == " | ||
| + | return | ||
| + | else: | ||
| + | print("?" | ||
| + | menu() | ||
| + | |||
| + | |||
| + | menu() | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | ++++ | ||
| + | |||
| + | |||
| + | |||
| + | ++++ original watchcheck.py in python 2 | | ||
| + | |||
| + | <file python watchcheck.py> | ||
| + | |||
| #! / | #! / | ||
| Line 217: | Line 427: | ||
| < | < | ||
| + | |||
| Wire2waves WatchCheck..... | Wire2waves WatchCheck..... | ||
| ========================= | ========================= | ||
| Line 294: | Line 505: | ||
| display the data | display the data | ||
| - | ++++ watchstat.py | | + | ++++ original |
| <file python watchstat.py> | <file python watchstat.py> | ||
| + | |||
| #! / | #! / | ||
| Line 404: | 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.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 = ' | ||
| + | | ||
| + | t_latest = datetime.datetime.strptime(latest_time, | ||
| + | t_previous = datetime.datetime.strptime(previous_time, | ||
| + | t_first = datetime.datetime.strptime(first_time, | ||
| + | |||
| + | tdelta = t_latest - t_previous | ||
| + | full_delta = t_latest - t_first | ||
| + | |||
| + | elapsed_time = tdelta.total_seconds() | ||
| + | |||
| + | full_time = full_delta.total_seconds() | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | | ||
| + | print(" | ||
| + | print(" | ||
| + | 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(" | ||
| + | |||
| + | print(" | ||
| + | |||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | |||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | print("" | ||
| + | else: | ||
| + | print(" | ||
| + | |||
| + | |||
| + | watch_stat() | ||
| + | |||
| + | </ | ||
| + | |||
| + | ++++ | ||
| + | |||
| Running watchstat.py on the newly updated '' | Running watchstat.py on the newly updated '' | ||
public/musings/watches/watchcheck.1767088507.txt.gz · Last modified: by 127.0.0.1
