Refactored to only report up to nearest quarter hour

This commit is contained in:
Trey Blancher 2018-10-02 15:52:05 -04:00
parent abc8f09f20
commit 5d17f2cbe1
1 changed files with 22 additions and 16 deletions

View File

@ -6,6 +6,9 @@ import re
import sys import sys
import time import time
def nearest(hr):
return math.ceil(hr*4)/4
# Variables # Variables
start = {} # Data structure for storing the beginning of a time frame start = {} # Data structure for storing the beginning of a time frame
finish = {} # Data structure for storing the end 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 # We're here, we've captured all of the data
gtoth = 0
gtot = 0 gtot = 0
for act in sorted(start.keys()): for act in sorted(start.keys()):
if act in start: if act in start:
@ -70,35 +74,37 @@ for act in sorted(start.keys()):
ind[act] = sigma ind[act] = sigma
gtot += sigma gtot += sigma
gtoth += nearest(sigma/3600)
ttot = 0 ttot = 0
utot = 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()): for act in sorted(ind.keys()):
minutes = "{:d}min".format(int(ind[act]%3600/60)) #minutes = "{:d}min".format(int(ind[act]%3600/60))
hrs = "{:d}hrs".format(int(ind[act]/3600)) #hrs = "{:d}hrs".format(int(nearest(ind[act]/3600)))
fhrs = "{:.2f}hrs".format(ind[act]/3600) fhrs = "{:.2f}hrs".format(nearest(ind[act]/3600))
sec = "{:d}s".format(int(ind[act])) #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): if incident.match(act):
ttot += ind[act] ttot += ind[act]
else: else:
utot += ind[act] utot += ind[act]
total = "{t:<20} {s:>10} {h:>10}" total = "{t:<20} {h:>10}"
ttots = "{:d}s".format(int(ttot)) #ttots = "{:d}s".format(int(ttot))
utots = "{:d}s".format(int(utot)) #utots = "{:d}s".format(int(utot))
ttoth = "{:3.2f}hrs".format(ttot / 3600) #ttoth = "{:3.2f}hrs".format(nearest(ttot / 3600))
utoth = "{:3.2f}hrs".format(utot / 3600) #utoth = "{:3.2f}hrs".format(nearest(utot / 3600))
gtots = "{:d}s".format(int(gtot)) #gtots = "{:d}s".format(int(gtot))
gtoth = "{:3.2f}hrs".format(gtot / 3600) gtoth = "{:3.2f}hrs".format(gtoth)
print print
print total.format(t="Incident total:", s=ttots, h=ttoth) #print total.format(t="Incident total:", s=ttots, h=ttoth)
print total.format(t="Unnumbered total:", s=utots, h=utoth) #print total.format(t="Unnumbered total:", s=utots, h=utoth)
print total.format(t="Section total:", s=gtots, h=gtoth) print total.format(t="Section total:", h=gtoth)