From 30fe02f133fc5282d61ce4e60ca3a4a69fb96bb4 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Thu, 26 Aug 2021 17:00:10 -0400 Subject: [PATCH 1/3] Converted to Python3, round to nearest quarter hour --- timetracker.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/timetracker.py b/timetracker.py index ea7a28d..a969fb4 100755 --- a/timetracker.py +++ b/timetracker.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import fileinput import math @@ -7,7 +7,7 @@ import sys import time def nearest(hr): - return math.ceil(hr*4)/4 + return round(hr*4)/4 # Variables start = {} # Data structure for storing the beginning of a time frame @@ -58,12 +58,12 @@ for act in sorted(start.keys()): else: ec = 0 if bc - ec > 1: - print >> sys.stderr, "ERROR: Missing more than one End" + print("ERROR: Missing more than one End", file=sys.stderr) sys.exit(2) elif bc > ec: # bc should be exactly one greater start[act].pop() elif ec > bc: - print >> sys.stderr, "ERROR: Missing a Begin" + print("ERROR: Missing a Begin", file=sys.stderr) sys.exit(1) delta = 0 @@ -94,7 +94,7 @@ for act in sorted(ind.keys()): #sec = "{:d}s".format(int(ind[act])) #print table.format(a=act, s=sec, h=hrs, m=minutes, f=fhrs) - print table.format(a=act, f=fhrs) + print(table.format(a=act, f=fhrs)) # if case.match(act): # ttot += ind[act] # else: @@ -109,8 +109,8 @@ total = "{t:<20} {h:>10}" #gtots = "{:d}s".format(int(gtot)) gtoth = "{:3.2f}hrs".format(gtoth) -print +print() #print total.format(t="Incident total:", s=ttots, h=ttoth) #print total.format(t="Unnumbered total:", s=utots, h=utoth) -print total.format(t="Section total:", h=gtoth) +print(total.format(t="Section total:", h=gtoth)) From 28a44469a6aab6ca4054639b5f22800194c1b35b Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Thu, 26 Aug 2021 22:49:44 -0400 Subject: [PATCH 2/3] Removed references to 288s, replaced with nearest(delta/3600.00) == 0 --- timetracker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/timetracker.py b/timetracker.py index a969fb4..7262cd7 100755 --- a/timetracker.py +++ b/timetracker.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import fileinput -import math import re import sys import time @@ -74,7 +73,7 @@ for act in sorted(start.keys()): ind[act] = delta gtot += delta - if delta <= 288: + if nearest(delta/3600.00) == 0: gtoth += 0.08 else: gtoth += nearest(delta/3600.00) From 03d28465ebea2fea48c516ebac2cba434f36c081 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Thu, 26 Aug 2021 22:58:21 -0400 Subject: [PATCH 3/3] Removed remaining 288s, replaced with nearest(ind[act]/3600.0) == 0 --- timetracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timetracker.py b/timetracker.py index 7262cd7..5b44049 100755 --- a/timetracker.py +++ b/timetracker.py @@ -86,7 +86,7 @@ table = "{a:<50} {f:>10}" for act in sorted(ind.keys()): #minutes = "{:d}min".format(int(ind[act]%3600/60)) #hrs = "{:d}hrs".format(int(nearest(ind[act]/3600))) - if ind[act] <= 288: + if nearest(ind[act]/3600.0) == 0: fhrs = "{:.2f}hrs".format(0.08) else: fhrs = "{:.2f}hrs".format(nearest(ind[act]/3600.00))