~mrp/time_computer

1179ba3bf8ed375aed5656ebf33c25e72ea94cee — Mark Penner 3 years ago dd70d91
add feature to print out hours for each line
1 files changed, 62 insertions(+), 61 deletions(-)

M tc
M tc => tc +62 -61
@@ 1,7 1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  Time Computer version: 2019-01
#  Time Computer version: 2020-10
#  
#  Public Domain
#  mrp


@@ 26,73 26,74 @@ dates = []
totalminutes=0
linenum=1
try:
	while True:
		linebuffer = []
		try:
			year = int(infile.read(4))
		except ValueError:
			break
		month = int(infile.read(2))
		day = int(infile.read(3))
		d = datetime.date(year, month, day)
		
		name = ''
		while True: # read job name (random length)
			x = infile.read(1)
			if x == ' ': break
			name = name + x
		linebuffer.append(name)
		
		while True:
			x = int(infile.read(2))
			linebuffer.append(x)
			if infile.read(1) == '\n': break
			
		x=0; timeIndex=1
		while True:
			try:  # figure hours for one clock-in/out
				x += (linebuffer[timeIndex+2]*60+linebuffer[timeIndex+3])-(linebuffer[timeIndex]*60+linebuffer[timeIndex+1])
			except IndexError:
				break
			timeIndex += 4 # go to next in/out
			
		jobIndex=0
		while linebuffer[0] != minutes[jobIndex][0] and minutes[jobIndex][0]: # check if current job matches previous
			jobIndex+=1
			
		if linebuffer[0] != minutes[jobIndex][0]: #if not match copy jobname to next open
			minutes.append([None, 0])
			minutes[jobIndex][0]=linebuffer[0]
		minutes[jobIndex][1] += x # add hrs to matchjobIndex=0
		
		weekIndex = 0
		ic = d.isocalendar()
		while ic[1] != weeks[weekIndex][0] and weeks[weekIndex][0]:
			weekIndex+=1
		if ic[1] != weeks[weekIndex][0]:
			weeks.append([None, 0])
			weeks[weekIndex][0]=ic[1]
		weeks[weekIndex][1] += x
		
		totalminutes += x
		linenum += 1
    while True:
        linebuffer = []
        try:
            year = int(infile.read(4))
        except ValueError:
            break
        month = int(infile.read(2))
        day = int(infile.read(3))
        d = datetime.date(year, month, day)
        
        name = ''
        while True: # read job name (random length)
            x = infile.read(1)
            if x == ' ': break
            name = name + x
        linebuffer.append(name)
        
        while True:
            x = int(infile.read(2))
            linebuffer.append(x)
            if infile.read(1) == '\n': break
            
        x=0; timeIndex=1
        while True:
            try:  # figure hours for one clock-in/out
                x += (linebuffer[timeIndex+2]*60+linebuffer[timeIndex+3])-(linebuffer[timeIndex]*60+linebuffer[timeIndex+1])
            except IndexError:
                break
            timeIndex += 4 # go to next in/out
        
        print(d,linebuffer[0], round(x/60, 2))
        jobIndex=0
        while linebuffer[0] != minutes[jobIndex][0] and minutes[jobIndex][0]: # check if current job matches previous
            jobIndex+=1
            
        if linebuffer[0] != minutes[jobIndex][0]: #if not match copy jobname to next open
            minutes.append([None, 0])
            minutes[jobIndex][0]=linebuffer[0]
        minutes[jobIndex][1] += x # add hrs to matchjobIndex=0
        
        weekIndex = 0
        ic = d.isocalendar()
        while ic[1] != weeks[weekIndex][0] and weeks[weekIndex][0]:
            weekIndex+=1
        if ic[1] != weeks[weekIndex][0]:
            weeks.append([None, 0])
            weeks[weekIndex][0]=ic[1]
        weeks[weekIndex][1] += x
        
        totalminutes += x
        linenum += 1
except:
	print ("error on line", linenum)
    print ("error on line", linenum)
finally:
	infile.close()
	
    infile.close()
    
print("\nhours by job")
x=0
while minutes[x][0]:
	print(minutes[x][0]+':', round(minutes[x][1]/60, 2))
	x+=1
    print(minutes[x][0]+':', round(minutes[x][1]/60, 2))
    x+=1
print("\nhours by week")
stdweek = 40
x=0
while weeks[x][0]:
	if weeks[x][1]/60 <= stdweek:
		print("week", str(weeks[x][0])+':', round(weeks[x][1]/60, 2))
	else:
		print("week", str(weeks[x][0])+':', stdweek, "overtime:", round(weeks[x][1]/60-stdweek, 2))
	x+=1
    if weeks[x][1]/60 <= stdweek:
        print("week", str(weeks[x][0])+':', round(weeks[x][1]/60, 2))
    else:
        print("week", str(weeks[x][0])+':', stdweek, "overtime:", round(weeks[x][1]/60-stdweek, 2))
    x+=1
print('\ntotal hours:', round(totalminutes/60, 2), '\n')