public:watches:watchcheck
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
public:watches:watchcheck [04/05/22 10:27 BST] – gm4slv | public:watches:watchcheck [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Watchcheck Python code ====== | ||
- | |||
- | I wrote a small python2 application to keep track of a watch/ | ||
- | daily rate error. It's a console-only mimic of an Android app that | ||
- | I use on my phone to track my watch timekeeping. | ||
- | |||
- | I wrote it mainly as a // | ||
- | piece of code. | ||
- | |||
- | 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. | ||
- | |||
- | |||
- | <code python> | ||
- | #! / | ||
- | |||
- | ## 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 = raw_input(" | ||
- | print w | ||
- | | ||
- | date = time.strftime(" | ||
- | s = date + " " + h +":" | ||
- | | ||
- | raw_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 "First record time ", first_time | ||
- | print "First record delta ", first_delta | ||
- | 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 "Daily PPM : %0.3f" % ppm_daily | ||
- | print "Daily rate error: %0.1f s/d " % (daily_rate) | ||
- | |||
- | print "" | ||
- | print "Total Time %d seconds" | ||
- | 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, | ||
- | print " | ||
- | print "" | ||
- | text = " | ||
- | write_file(text) | ||
- | else: | ||
- | print "No rate yet" | ||
- | |||
- | |||
- | def new_record(): | ||
- | | ||
- | try: | ||
- | saved_error = open(' | ||
- | error_list = json.load(saved_error) | ||
- | except: | ||
- | error_list = [] | ||
- | |||
- | s,delta = get_delta() | ||
- | |||
- | print "" | ||
- | print "%s \n\nDelta %0.1f seconds" | ||
- | 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 "N : New Record\nD : Delete Last\nS : Stats\nQ : Quit\n" | ||
- | choice = raw_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() | ||
- | </ | ||
- | |||
- | |||
- | Running it for the first time, with no previous records stored, looks like this: | ||
- | |||
- | < | ||
- | Wire2waves WatchCheck..... | ||
- | ========================= | ||
- | |||
- | N : New Record | ||
- | D : Delete Last | ||
- | S : Stats | ||
- | Q : Quit | ||
- | |||
- | Command > : n | ||
- | New | ||
- | Current Time = 10:18 | ||
- | Watch time 10:19 | ||
- | 19 | ||
- | Press enter when seconds = 0 | ||
- | |||
- | 2022/05/04 10:19:30 | ||
- | |||
- | Delta -30.2 seconds | ||
- | </ | ||
- | |||
- | and the first time-delta is stored in the '' | ||
- | |||
- | < | ||
- | [[" | ||
- | </ | ||
- | |||
- | I'll update this once I've done a second measurement, | ||
- | |||
- | |||
- | There' | ||
- | display the data | ||
- | |||
- | <code python> | ||
- | #! / | ||
- | |||
- | ## 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 "First record time ", first_time | ||
- | print "First record delta ", first_delta | ||
- | 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 "Daily PPM : %0.3f" % ppm_daily | ||
- | print "Daily rate error: %0.1f s/d " % (daily_rate) | ||
- | |||
- | print "" | ||
- | print "Total Time %d seconds" | ||
- | 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, | ||
- | print " | ||
- | print "" | ||
- | else: | ||
- | print "No rate yet" | ||
- | |||
- | |||
- | watch_stat() | ||
- | </ | ||
- | |||
- | |||
- | // | ||
- | |||
- | Page Updated : ~~LASTMOD~~ | ||
- | |||
- | {{tag> |
public/watches/watchcheck.1651656432.txt.gz · Last modified: (external edit)