~mrp/time_computer

f2cd053102a4c4ffc6e7ec51ccb22e3b2f32616e — Mark Penner 3 years ago 1179ba3
improve daily hours figuring
1 files changed, 85 insertions(+), 49 deletions(-)

M tc
M tc => tc +85 -49
@@ 1,30 1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  Time Computer version: 2020-10
#  
#  Time Computer version: 2020-11-26
#
#  Public Domain
#  mrp

import sys
import datetime
print('        ____')
print('       /    \\')
print('      /  |   \\')
print('     |   |    |')
print('      \   \  /')
print('       \____/')
print('-----time computer-----')

try: FName = sys.argv[1]
except IndexError: FName = input ("File Name: ")
infile = open(FName, 'r')
print("time computer")
print("version 2020-11-26")
print("        ____")
print("       /    \\")
print("      /  |   \\")
print("     |   |    |")
print("      \   \  /")
print("       \____/")

try:
    FName = sys.argv[1]
except IndexError:
    FName = input("File Name: ")
infile = open(FName, "r")

minutes = [[None, 0]]
weeks = [[None, 0]]
days = [[None, 0]]
dates = []
totalminutes=0
linenum=1
totalminutes = 0
linenum = 1
try:
    while True:
        linebuffer = []


@@ 35,65 40,96 @@ try:
        month = int(infile.read(2))
        day = int(infile.read(3))
        d = datetime.date(year, month, day)
        
        name = ''
        while True: # read job name (random length)

        # read job name (random length)
        name = ""
        while True:
            x = infile.read(1)
            if x == ' ': break
            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
            if infile.read(1) == "\n":
                break

        # figure hours for one clock-in/out
        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])
            try:
                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
            timeIndex += 4  # go to next in/out

        # add minutes to right job
        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 no match append jobname
            minutes.append([None, 0])
            minutes[jobIndex][0]=linebuffer[0]
        minutes[jobIndex][1] += x # add hrs to matchjobIndex=0
        
            minutes[jobIndex][0] = linebuffer[0]
        minutes[jobIndex][1] += x

        # add minutes to right week
        weekIndex = 0
        ic = d.isocalendar()
        while ic[1] != weeks[weekIndex][0] and weeks[weekIndex][0]:
            weekIndex+=1
            weekIndex += 1
        if ic[1] != weeks[weekIndex][0]:
            weeks.append([None, 0])
            weeks[weekIndex][0]=ic[1]
            weeks[weekIndex][0] = ic[1]
        weeks[weekIndex][1] += x
        

        # add minutes to right day
        dayIndex = 0
        while d != days[dayIndex][0] and days[dayIndex][0]:
            dayIndex += 1
        if d != days[dayIndex][0]:
            days.append([None, 0])
            days[dayIndex][0] = d
        days[dayIndex][1] += x

        totalminutes += x
        linenum += 1
except:
    print ("error on line", linenum)
    print("error on line", linenum)
finally:
    infile.close()
    

print("\nhours by day")
x = 0
while days[x][0]:
    print(str(days[x][0]) + ":", round(days[x][1] / 60, 2))
    x += 1

print("\nhours by job")
x=0
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
x = 0
while weeks[x][0]:
    if weeks[x][1]/60 <= stdweek:
        print("week", str(weeks[x][0])+':', round(weeks[x][1]/60, 2))
    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')
        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")