[comp.sources.misc] v15i001: A program to see if you're working overtime too much

arnold%audiofax.com@mathcs.emory.edu (Arnold Robbins) (10/06/90)

Posting-number: Volume 15, Issue 1
Submitted-by: arnold%audiofax.com@mathcs.emory.edu (Arnold Robbins)
Archive-name: dohours/part01

[This has not been a good past two weeks.  If I have to work any more 9pm-ers,
I will be forced to find another moderator...  Which is right to the point of
this awk script.  Unfortunately, I don't need it to know that I've been working
too much overtime:  the backlog of things that need to be done is sufficient
evidence.  ++bsa]

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README
#	dohours
# This archive created: Wed Sep 26 18:21:23 1990
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'README'" '(1519 characters)'
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
README: Wed Sep 26 18:13:21 EDT 1990

Are you overworked?  Do you want to be able to prove it?  Here's the
program for you!  It tracks:

	Weeks worked greater than 45, 50, 55, 60, and 65 hours
	Weeks worked with 6 or more days in them

Simply start tracking your hours in a file in the following format:

	January 8
	11:00 4:30
	8:30 7:30
	8:30 7:30
	Remarks: Out sick 2 days
	January 15
	9:15 7:15
	10:50 7:00
	9:00 7:00
	9:55 7:00
	9:30 4:05

Each date is the monday that a week begins.  Each other line is the start
and end time for how long you worked.  If you miss some days for a holiday
or sick time, put that in a Remarks line.  One Remarks line per week.

The program assumes that start hours less than 8 are in the afternoon; if
you get to work very early, that should be fixed.

This program requires either new awk (nawk) or GNU awk.  It could be made
to work with old awk by 1) running "sed 's/:/ /g'" over the data first,
2) commenting out the BEGIN block, and 3) inlining the report() function.
I haven't tried it though.

There are undoubtedly lots of improvements, tweaks, customizations, etc.
that could be done to this program, but what do you want from something
hacked together in less than two hours? :-)

Enjoy,

Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold@audiofax.com Phone:   +1 404 933 7600 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins
SHAR_EOF
fi
echo shar: "extracting 'dohours'" '(1359 characters)'
if test -f 'dohours'
then
	echo shar: "will not over-write existing file 'dohours'"
else
cat << \SHAR_EOF > 'dohours'
#! /usr/local/bin/gawk -f

BEGIN	{	FS = "[ \t:]+" }

END	\
{
	report()

	if (w65)
		printf "%d weeks >= 65 hours\n", w65
	if (w60)
		printf "%d weeks >= 60 hours\n", w60
	if (w55)
		printf "%d weeks >= 55 hours\n", w55
	if (w50)
		printf "%d weeks >= 50 hours\n", w50
	if (w45)
		printf "%d weeks >= 45 hours\n", w45
	if (w6days)
		printf "%d weeks of 6 days\n", w6days
}

/^[Rr]emark/	{	remark = $0 ; next }

/^[A-Za-z]/	{
			report()
			minutes = 0
			daysinweek = 0
			remark = ""
			thisweek = $0
			next
		}

NF == 4		{
			daysinweek++

			bhour = $1 ; bmin = $2 ; ehour = $3 ; emin = $4
			ehour += 12	# end times are p.m.
			if (bhour < 8)		# started work in afternoon
				bhour += 12	# e.g. on a Sunday

			start = (bhour * 60) + bmin	# minutes since midnight
			end = (ehour * 60) + emin	# minutes since midnight
			minutes += (end - start)
			# next
		}

function report(	hours, wmin)	# hours, wmin are local
{
	if (minutes == 0)
		return

	hours = int(minutes / 60)
	wmin = minutes % 60
	printf "Week of %s, %d hours, %d minutes. %s\n",
		thisweek, hours, wmin, remark

	if (hours >= 65)
		w65++
	else if (hours >= 60)
		w60++
	else if (hours >= 55)
		w55++
	else if (hours >= 50)
		w50++
	else if (hours >= 45)
		w45++
	if (daysinweek >= 6)
		w6days++
}

NF != 4		{
			print "weird record, line", NF, ":", $0 | "cat 1>&2"
			close("cat 1>&2")
		}
SHAR_EOF
chmod +x 'dohours'
fi
exit 0
#	End of shell archive
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold@audiofax.com Phone:   +1 404 933 7600 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins