From 5d17f2cbe1fb25bf8680b5a6666b1bfaa725b880 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Tue, 2 Oct 2018 15:52:05 -0400 Subject: [PATCH] Refactored to only report up to nearest quarter hour --- timetracker.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/timetracker.py b/timetracker.py index 32d8b88..3b67f38 100755 --- a/timetracker.py +++ b/timetracker.py @@ -6,6 +6,9 @@ import re import sys import time +def nearest(hr): + return math.ceil(hr*4)/4 + # Variables start = {} # Data structure for storing the beginning of a time frame finish = {} # Data structure for storing the end of a time frame @@ -44,6 +47,7 @@ for line in fileinput.input(): # We're here, we've captured all of the data +gtoth = 0 gtot = 0 for act in sorted(start.keys()): if act in start: @@ -70,35 +74,37 @@ for act in sorted(start.keys()): ind[act] = sigma gtot += sigma + gtoth += nearest(sigma/3600) ttot = 0 utot = 0 -table = "{a:<50} {s:>10} {h:>10} {m:>10} {f:>10}" +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(ind[act]/3600)) - fhrs = "{:.2f}hrs".format(ind[act]/3600) - sec = "{:d}s".format(int(ind[act])) + #minutes = "{:d}min".format(int(ind[act]%3600/60)) + #hrs = "{:d}hrs".format(int(nearest(ind[act]/3600))) + fhrs = "{:.2f}hrs".format(nearest(ind[act]/3600)) + #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, s=sec, h=hrs, m=minutes, f=fhrs) + print table.format(a=act, f=fhrs) if incident.match(act): ttot += ind[act] else: utot += ind[act] -total = "{t:<20} {s:>10} {h:>10}" +total = "{t:<20} {h:>10}" -ttots = "{:d}s".format(int(ttot)) -utots = "{:d}s".format(int(utot)) -ttoth = "{:3.2f}hrs".format(ttot / 3600) -utoth = "{:3.2f}hrs".format(utot / 3600) -gtots = "{:d}s".format(int(gtot)) -gtoth = "{:3.2f}hrs".format(gtot / 3600) +#ttots = "{:d}s".format(int(ttot)) +#utots = "{:d}s".format(int(utot)) +#ttoth = "{:3.2f}hrs".format(nearest(ttot / 3600)) +#utoth = "{:3.2f}hrs".format(nearest(utot / 3600)) +#gtots = "{:d}s".format(int(gtot)) +gtoth = "{:3.2f}hrs".format(gtoth) 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:", s=gtots, h=gtoth) +#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)