Initial timetracker commit
This commit is contained in:
commit
c885ca37c5
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
WK_OFFSET=$1
|
||||||
|
[[ -z ${WK_OFFSET} ]] && WK_OFFSET=0
|
||||||
|
DATE=$(gdate -d "last Monday - ${WK_OFFSET} weeks")
|
||||||
|
for date in $(gdate +%F -d "${DATE}") \
|
||||||
|
$(gdate +%F -d "${DATE} + 1 day") \
|
||||||
|
$(gdate +%F -d "${DATE} + 2 day") \
|
||||||
|
$(gdate +%F -d "${DATE} + 3 day") \
|
||||||
|
$(gdate +%F -d "${DATE} + 4 day") \
|
||||||
|
$(gdate +%F -d "${DATE} + 5 day") \
|
||||||
|
$(gdate +%F -d "${DATE} + 6 day"); do
|
||||||
|
|
||||||
|
echo $date
|
||||||
|
|
||||||
|
./do_process $date
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n Press ENTER for ${date}...
|
||||||
|
|
||||||
|
read
|
||||||
|
|
||||||
|
done
|
|
@ -0,0 +1,58 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ORGS=()
|
||||||
|
|
||||||
|
if [[ "x${1}" == "x" ]]; then
|
||||||
|
DATE=$(date +%F)
|
||||||
|
else
|
||||||
|
DATE=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f ${DATE}.log ]]; then
|
||||||
|
get_list_of_orgs () {
|
||||||
|
orgs=$( grep -Po "\s+\[.*\]" | tr -d '[][]' )
|
||||||
|
for org in ${orgs}; do
|
||||||
|
org="${org##*( )}" # trim leading whitespace
|
||||||
|
org="${org%%*( )}" # trim trailing whitespace
|
||||||
|
[[ "${ORGS[@]}" =~ "${org}" ]] || ORGS+=("${org}")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
get_list_of_orgs < ${DATE}.log
|
||||||
|
|
||||||
|
for (( i=0; i < ${#ORGS[@]}; i++ )); do
|
||||||
|
echo "ORGS[$i]=${ORGS[$i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
#for org in "${ORGS[@]}"; do
|
||||||
|
# echo ${org}
|
||||||
|
#done
|
||||||
|
|
||||||
|
echo "--"
|
||||||
|
echo ${DATE}
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
WHOLE=""
|
||||||
|
for pattern in "${ORGS[@]}" meeting; do
|
||||||
|
#echo "pattern=${pattern}" >&2
|
||||||
|
if [[ "${pattern}" == "meeting" ]]; then
|
||||||
|
grep "${pattern}" ${DATE}.log | grep -Ev "${WHOLE}" | timetracker
|
||||||
|
else
|
||||||
|
grep "${pattern}" ${DATE}.log | timetracker
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
if [[ "${WHOLE}x" == "x" ]]; then
|
||||||
|
WHOLE="${pattern}"
|
||||||
|
else
|
||||||
|
WHOLE="${WHOLE}|${pattern}"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
grep -Ev "${WHOLE}" ${DATE}.log | timetracker
|
||||||
|
echo
|
||||||
|
timetracker ${DATE}.log | grep "Section" | sed 's/Section/Grand/'
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "${DATE}.log does not exist" >&2
|
||||||
|
fi
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "x$1" == "x" ]; then
|
||||||
|
MONTH=$(( $(date +%-m) - 1 ))
|
||||||
|
else
|
||||||
|
MONTH=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "x$1" == "x" ]; then
|
||||||
|
YEAR=$(date +%Y)
|
||||||
|
CURR=1
|
||||||
|
else
|
||||||
|
YEAR=$1
|
||||||
|
shift
|
||||||
|
CURR=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ $MONTH -eq 0 ];
|
||||||
|
then
|
||||||
|
MONTH=12
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${CURR} -eq 1 ] && [ $(( $(date +%-m) - $MONTH )) -le 0 ]; then
|
||||||
|
YEAR=$(( $YEAR - 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $MONTH -lt 10 ];
|
||||||
|
then
|
||||||
|
MONTH=0$MONTH
|
||||||
|
fi
|
||||||
|
tar -cvJf $YEAR-$MONTH.tar.xz $YEAR-$MONTH-*.log --remove-files
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import fileinput
|
||||||
|
import math
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
start = {} # Data structure for storing the beginning of a time frame
|
||||||
|
finish = {} # Data structure for storing the end of a time frame
|
||||||
|
ind = {} # Data structure for storing individual timecards
|
||||||
|
misc = {} # Data structure for storing miscellaneous timecards
|
||||||
|
|
||||||
|
empty = re.compile("^\s*$") # regex for finding empty lines (and skipping them)
|
||||||
|
comment = re.compile("^\s*#") # regex for finding empty lines (and skipping them)
|
||||||
|
delim = re.compile(":\s{2}") # regex for splitting timestamp entry
|
||||||
|
begin = re.compile("^Begin\s+(?P<action>.*)\s*$")
|
||||||
|
end = re.compile("^End\s+(?P<action>.*)\s*$")
|
||||||
|
incident = re.compile("^(PDROP|CHG)-?\d+")
|
||||||
|
|
||||||
|
for line in fileinput.input():
|
||||||
|
if empty.match(line) or comment.match(line): # if the current line is empty
|
||||||
|
continue # skip to the next line
|
||||||
|
|
||||||
|
(datetime,entry) = delim.split(line.strip())
|
||||||
|
timestamp = time.mktime(time.strptime(datetime,"%Y-%m-%d %H:%M:%S"))
|
||||||
|
|
||||||
|
if begin.match(entry):
|
||||||
|
action = begin.sub("\g<action>",entry)
|
||||||
|
|
||||||
|
if action not in start:
|
||||||
|
start[action] = []
|
||||||
|
|
||||||
|
start[action].append(timestamp)
|
||||||
|
|
||||||
|
if end.match(entry):
|
||||||
|
action = end.sub("\g<action>",entry)
|
||||||
|
|
||||||
|
if action not in finish:
|
||||||
|
finish[action] = []
|
||||||
|
|
||||||
|
finish[action].append(timestamp)
|
||||||
|
|
||||||
|
# We're here, we've captured all of the data
|
||||||
|
|
||||||
|
gtot = 0
|
||||||
|
for act in sorted(start.keys()):
|
||||||
|
if act in start:
|
||||||
|
bc = len(start[act])
|
||||||
|
else: bc = 0
|
||||||
|
if act in finish:
|
||||||
|
ec = len(finish[act])
|
||||||
|
else: ec = 0
|
||||||
|
|
||||||
|
if bc - ec > 1:
|
||||||
|
print >> sys.stderr, "ERROR: Missing more than one End"
|
||||||
|
sys.exit(2)
|
||||||
|
elif bc > ec: # bc should be exactly one greater
|
||||||
|
start[act].pop()
|
||||||
|
elif ec > bc:
|
||||||
|
print >> sys.stderr, "ERROR: Missing a Begin"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
sigma = 0
|
||||||
|
while (len(start[act]) > 0 and len(start[act]) > 0):
|
||||||
|
beg = start[act].pop(0)
|
||||||
|
en = finish[act].pop(0)
|
||||||
|
sigma += en - beg
|
||||||
|
|
||||||
|
ind[act] = sigma
|
||||||
|
gtot += sigma
|
||||||
|
|
||||||
|
ttot = 0
|
||||||
|
utot = 0
|
||||||
|
|
||||||
|
table = "{a:<50} {s:>10} {h:>10} {m:>10} {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]))
|
||||||
|
|
||||||
|
print table.format(a=act, s=sec, h=hrs, m=minutes, f=fhrs)
|
||||||
|
if incident.match(act):
|
||||||
|
ttot += ind[act]
|
||||||
|
else:
|
||||||
|
utot += ind[act]
|
||||||
|
|
||||||
|
total = "{t:<20} {s:>10} {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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue