cleaned up timetracker
This commit is contained in:
		
							parent
							
								
									94b9f164bd
								
							
						
					
					
						commit
						8489a5920c
					
				@ -1,34 +0,0 @@
 | 
			
		||||
Alright, this system needs to be robust and easy to use. I shouldn't have to do ANYTHING extra to use this
 | 
			
		||||
 | 
			
		||||
2 ways to do it
 | 
			
		||||
Have a file for each day and clock in and out 
 | 
			
		||||
have a master log and parse the log
 | 
			
		||||
parsing the log seems significantly easier
 | 
			
		||||
 | 
			
		||||
File name can be generic because it gets cleaned as part of an accumulation script
 | 
			
		||||
i.e. timesheet.log
 | 
			
		||||
 | 
			
		||||
Everytime a user logs in echo
 | 
			
		||||
I, DATE, TIME to the file
 | 
			
		||||
A logout or i3lock echos
 | 
			
		||||
O, DATE, TIME to the same file
 | 
			
		||||
 | 
			
		||||
can be dead simple as far as the logging goes
 | 
			
		||||
clock -i to clock in
 | 
			
		||||
clock -o to clock out
 | 
			
		||||
 | 
			
		||||
Parser will have to be a bit more robust
 | 
			
		||||
 | 
			
		||||
hell with a parser, I have a better system. 
 | 
			
		||||
 | 
			
		||||
Steps
 | 
			
		||||
1) On login echo date, start time >> to a csv
 | 
			
		||||
2) On logout echo end time, total uptime \n to same csv
 | 
			
		||||
    Ending format:
 | 
			
		||||
    Date, Time in, Time out, Total
 | 
			
		||||
    11/11, 11:00,  12:00,    1
 | 
			
		||||
3) On every wednesday mv to a non-temp file for tracking and destroy csv
 | 
			
		||||
notes)
 | 
			
		||||
    - Should be robust as hell as it will log entries into a seperate entry for the same date which can be compressed manually
 | 
			
		||||
    - Column -s -t ',' < csv should make for easy viewing in terminal
 | 
			
		||||
    - should be deadsimple to implement a way to track pay periods or modifyed command for entries
 | 
			
		||||
@ -1,2 +0,0 @@
 | 
			
		||||
Date, Time In, Time Out, Total Time
 | 
			
		||||
Nov-28, 12:15, 14:30, 2:15
 | 
			
		||||
		
		
			
  | 
@ -1,105 +0,0 @@
 | 
			
		||||
I 10-03T16:24
 | 
			
		||||
O 10-03T16:25
 | 
			
		||||
I 10-03T16:25
 | 
			
		||||
O 10-03T16:27
 | 
			
		||||
I 10-03T16:27
 | 
			
		||||
O 10-03T16:30
 | 
			
		||||
I 10-03T16:31
 | 
			
		||||
O 10-03T16:31
 | 
			
		||||
I 10-05T09:52
 | 
			
		||||
O 10-05T10:06
 | 
			
		||||
I 10-05T10:06
 | 
			
		||||
O 10-05T10:06
 | 
			
		||||
I 10-05T10:15
 | 
			
		||||
O 10-05T12:53
 | 
			
		||||
I 10-05T17:18
 | 
			
		||||
O 10-05T18:48
 | 
			
		||||
I 10-06T13:21
 | 
			
		||||
O 10-06T13:40
 | 
			
		||||
I 10-07T11:37
 | 
			
		||||
O 10-07T12:59
 | 
			
		||||
I 10-07T16:13
 | 
			
		||||
O 10-07T16:38
 | 
			
		||||
I 10-07T17:06
 | 
			
		||||
O 10-07T20:20
 | 
			
		||||
I 10-08T14:22
 | 
			
		||||
O 10-08T18:50
 | 
			
		||||
I 10-09T14:35
 | 
			
		||||
O 10-09T19:13
 | 
			
		||||
I 10-10T10:35
 | 
			
		||||
O 10-10T16:43
 | 
			
		||||
I 10-11T11:28
 | 
			
		||||
O 10-11T12:29
 | 
			
		||||
I 10-11T14:54
 | 
			
		||||
O 10-11T18:56
 | 
			
		||||
I 10-12T09:45
 | 
			
		||||
O 10-12T12:23
 | 
			
		||||
I 10-12T15:39
 | 
			
		||||
O 10-12T17:06
 | 
			
		||||
I 10-13T09:55
 | 
			
		||||
O 10-13T10:30
 | 
			
		||||
I 10-14T15:25
 | 
			
		||||
O 10-14T17:19
 | 
			
		||||
I 10-16T13:19
 | 
			
		||||
O 10-16T17:00
 | 
			
		||||
I 10-17T10:15
 | 
			
		||||
O 10-17T13:41
 | 
			
		||||
I 10-18T13:22
 | 
			
		||||
O 10-18T13:54
 | 
			
		||||
I 10-18T14:11
 | 
			
		||||
O 10-18T18:00
 | 
			
		||||
I 10-19T10:22
 | 
			
		||||
O 10-19T13:00
 | 
			
		||||
I 10-19T13:25
 | 
			
		||||
O 10-19T16:59
 | 
			
		||||
I 10-19T17:23
 | 
			
		||||
O 10-19T18:34
 | 
			
		||||
I 10-21T12:04
 | 
			
		||||
O 10-21T12:51
 | 
			
		||||
I 10-23T14:59
 | 
			
		||||
O 10-23T17:19
 | 
			
		||||
I 10-24T13:07
 | 
			
		||||
O 10-24T13:57
 | 
			
		||||
I 10-25T15:34
 | 
			
		||||
O 10-25T17:53
 | 
			
		||||
I 10-26T11:57
 | 
			
		||||
O 10-26T19:47
 | 
			
		||||
I 10-27T17:56
 | 
			
		||||
O 10-27T20:23
 | 
			
		||||
I 11-01T13:40
 | 
			
		||||
O 11-01T18:13
 | 
			
		||||
I 11-02T13:24
 | 
			
		||||
O 11-02T18:57
 | 
			
		||||
I 11-03T12:59
 | 
			
		||||
O 11-03T15:53
 | 
			
		||||
I 11-03T17:07
 | 
			
		||||
O 11-03T18:31
 | 
			
		||||
I 11-04T19:07
 | 
			
		||||
O 11-04T19:34
 | 
			
		||||
I 11-07T15:15
 | 
			
		||||
O 11-07T17:11
 | 
			
		||||
I 11-08T13:58
 | 
			
		||||
O 11-08T17:27
 | 
			
		||||
I 11-09T17:02
 | 
			
		||||
O 11-09T19:05
 | 
			
		||||
I 11-10T13:19
 | 
			
		||||
O 11-10T21:12
 | 
			
		||||
I 11-11T16:03
 | 
			
		||||
O 11-11T20:24
 | 
			
		||||
I 11-14T13:39
 | 
			
		||||
O 11-14T14:20
 | 
			
		||||
I 11-14T14:23
 | 
			
		||||
O 11-14T14:23
 | 
			
		||||
I 11-15T17:06
 | 
			
		||||
O 11-15T21:11
 | 
			
		||||
I 11-16T15:11
 | 
			
		||||
O 11-16T17:09
 | 
			
		||||
I 11-17T14:34
 | 
			
		||||
O 11-17T22:01
 | 
			
		||||
I 11-18T15:25
 | 
			
		||||
O 11-18T19:39
 | 
			
		||||
I 11-20T15:34
 | 
			
		||||
O 11-20T19:22
 | 
			
		||||
I 11-21T15:10
 | 
			
		||||
O 11-21T19:09
 | 
			
		||||
I 11-28T12:20
 | 
			
		||||
@ -1,134 +0,0 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Time sheet creator
 | 
			
		||||
# Stores clock in and outs to timesheet named for the ending date of the ts
 | 
			
		||||
usage() {
 | 
			
		||||
    cat <<EOF
 | 
			
		||||
Usage: timetracker [-i|o|t|v|h]
 | 
			
		||||
 | 
			
		||||
Tracks timesheets automatically
 | 
			
		||||
 | 
			
		||||
Options:
 | 
			
		||||
  -i, --in          clock in
 | 
			
		||||
  -o, --out         clock out
 | 
			
		||||
  -t, --total       totals the hours worked
 | 
			
		||||
  -v, --visualize   prints the timesheet
 | 
			
		||||
  -h, --help        display this message
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# dir for timesheets
 | 
			
		||||
TIMESHEET_DIR="$HOME/.dotfiles/bin/timetracker/timesheets"
 | 
			
		||||
# existing
 | 
			
		||||
TIMESHEET=$(ls "$HOME/.dotfiles/bin/timetracker/timesheets" | grep ".csv")
 | 
			
		||||
# generated by clock in
 | 
			
		||||
CURRENT_SESSION="${TIMESHEET_DIR}/.session"
 | 
			
		||||
 | 
			
		||||
createTimesheet() {
 | 
			
		||||
    payperiods=$((($(date +%s) - $(date -d "Dec-30-22" +%s)) / (14*24*3600)))
 | 
			
		||||
    period_end=$(date -d "Dec-30-22 + $((($payperiods + 1) * 14)) days" +%b-%d-%y)
 | 
			
		||||
    TIMESHEET=$(printf "%s.csv" "$period_end")
 | 
			
		||||
    # create timesheet 
 | 
			
		||||
    echo "Date, Time In, Time Out, Total Time (HH:MM)" > "${TIMESHEET_DIR}/${TIMESHEET}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
getTimesheet() {
 | 
			
		||||
    # get Timesheet to use
 | 
			
		||||
    if [[ -z "$TIMESHEET" ]] ; then
 | 
			
		||||
        # no timesheet, create one
 | 
			
		||||
        createTimesheet
 | 
			
		||||
    else
 | 
			
		||||
        # timesheet found, check we are still in period
 | 
			
		||||
        period_end=$(date -d "$(echo "$TIMESHEET" | awk -F . '{print $1}') + 1 days" +%s) 
 | 
			
		||||
        if [[ $(date +%s) -ge $period_end ]] ; then
 | 
			
		||||
            # past timesheet, moving to archive and creating new
 | 
			
		||||
            mv ${TIMESHEET_DIR}/${TIMESHEET} ${TIMESHEET_DIR}/archive
 | 
			
		||||
            createTimesheet
 | 
			
		||||
        fi
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
clockIn() {
 | 
			
		||||
    # clock in by creating env file
 | 
			
		||||
    curdate=$(date +%s)
 | 
			
		||||
    env_details=$(printf 'DATE=%s\nTIME_IN=%s\n' "$curdate" "$curdate")
 | 
			
		||||
    if [[ ! -f "$CURRENT_SESSION" ]] ; then
 | 
			
		||||
        # creating session
 | 
			
		||||
        echo "$env_details" > "$CURRENT_SESSION"
 | 
			
		||||
    else
 | 
			
		||||
        echo "Already Clocked In!" >&2
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
clockOut() {
 | 
			
		||||
    # clock out
 | 
			
		||||
    if [[ -f "$CURRENT_SESSION" ]] ; then
 | 
			
		||||
        # session exists, get info
 | 
			
		||||
        source "$CURRENT_SESSION"
 | 
			
		||||
        # printing to timesheet
 | 
			
		||||
        TIME_OUT=$(date +%s) 
 | 
			
		||||
        TOTAL_TIME=$(($TIME_OUT - $TIME_IN + 3600 * 5)) 
 | 
			
		||||
        echo "$TOTAL_TIME"
 | 
			
		||||
        # printing to timesheet
 | 
			
		||||
        printf '%s, %s, %s, %s\n' "$(date -d @$DATE "+%a %b-%d")" "$(date -d @$TIME_IN +%I:%M%P)" "$(date -d @$TIME_OUT +%I:%M%P)" "$(date -d @$TOTAL_TIME +%H:%M)" >> ${TIMESHEET_DIR}/${TIMESHEET}
 | 
			
		||||
        # cleaning up session
 | 
			
		||||
        rm ${CURRENT_SESSION}
 | 
			
		||||
    else
 | 
			
		||||
        # no session
 | 
			
		||||
        echo "Not clocked in!" >&2
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
visualize() {
 | 
			
		||||
    # visualize the current timesheet
 | 
			
		||||
    column -s "," -t < ${TIMESHEET_DIR}/${TIMESHEET}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
totalHours() {
 | 
			
		||||
    # tally up hours for the current timesheet
 | 
			
		||||
    while read -r entry; do
 | 
			
		||||
        date=$(echo "$entry" | awk -F , '{print $1}' | tr -d ",\n")
 | 
			
		||||
        time=$(echo "$entry" | awk -F , '{print $4}' | tr -d " ,\n")
 | 
			
		||||
        if [[ "$date" != "Date" ]] ; then
 | 
			
		||||
            printf 'On %s worked %s\n' "$date" "$time"
 | 
			
		||||
            hours=$(($hours + 10#$(echo "$time" | awk -F : '{print $1}')))
 | 
			
		||||
            mins=$(($mins + 10#$(echo "$time" | awk -F : '{print $2}')))
 | 
			
		||||
        fi
 | 
			
		||||
    done < ${TIMESHEET_DIR}/${TIMESHEET}
 | 
			
		||||
    hours=$(($hours + $mins/60)) # overflow
 | 
			
		||||
    mins=$(($mins%60))
 | 
			
		||||
    printf 'Worked %d hours, %d minutes\n' "$hours" "$mins"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# get the timesheet
 | 
			
		||||
getTimesheet
 | 
			
		||||
 | 
			
		||||
# parse args
 | 
			
		||||
while [[ $# -gt 0 ]] ; do
 | 
			
		||||
    case $1 in
 | 
			
		||||
        -h | --help)
 | 
			
		||||
            usage
 | 
			
		||||
            exit 0
 | 
			
		||||
            ;;
 | 
			
		||||
        -i | --in)
 | 
			
		||||
            clockIn
 | 
			
		||||
            ;;
 | 
			
		||||
        -o | --out)
 | 
			
		||||
            clockOut
 | 
			
		||||
            ;;
 | 
			
		||||
        -v | --visualize)
 | 
			
		||||
            visualize
 | 
			
		||||
            ;;
 | 
			
		||||
        -t | --total)
 | 
			
		||||
            totalHours
 | 
			
		||||
            ;;
 | 
			
		||||
        *)
 | 
			
		||||
            echo "Error: Unrecognized" >&2
 | 
			
		||||
            usage
 | 
			
		||||
            exit 1
 | 
			
		||||
            ;;
 | 
			
		||||
    esac
 | 
			
		||||
    shift
 | 
			
		||||
done
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user