Skip to content

Instantly share code, notes, and snippets.

@keithhamilton
Last active August 29, 2015 14:03
Show Gist options
  • Save keithhamilton/6e282b5b4dbf0cc2104d to your computer and use it in GitHub Desktop.
Save keithhamilton/6e282b5b4dbf0cc2104d to your computer and use it in GitHub Desktop.
Takes your timesheet in CSV format and aggregates the time per job per day of the time period.
'''
0. Disclaimer
This is not a silver bullet. It is simply a tool that I made so I could summarize my weekly time tracking.
If you are looking for a silver bullet...sorry? Not sorry. Next point.
1. How to use
a) write this into a csv file on your computer somewhere: http://bit.ly/1pYAruL
b) copy the below script into a py file on your machine, probably in the same location as your csv file.
c) open that shit in Excel or Numbers, your choice.
d) enter your time. You can enter your time however makes sense to you. For example, I use "ADM" as
"Admin," and stuff like "SHOOTOUT" for "KO FIFA Shootout," which certainly has a code I can't remember.
The point here being that you can label your time however you want, JUST DO IT CONSISTENTLY, or this shit won't work.
e) once you've entered in your time, run the csv file against the python script, passing the csv file as the first arg:
python time_cruncher.py my_time_sheet.csv
f) straight enter the time into the appropriate fields in Super Mobile Aura Turbo (Championship Edition, if you prefer).
2. Disclaimer, part two:
If this isn't how you want to record your time, that's cool. Leave now, and post a negative review on yelp.
3. Output
So what does this script output, exactly? Check the rhyme, G:
------SAMPLE OUTPUT------
7/1/2014: {'MY_PROJECT': 1.25, 'KO_SAMPLE_PROJ': 0.5, 'ADM': 3.5, 'INTERNAL_PROJ_B': 1.5, 'MED': 2.0}
7/10/2014: {}
7/11/2014: {}
7/12/2014: {}
7/13/2014: {}
7/14/2014: {}
7/15/2014: {}
7/2/2014: {'MY_PROJECT': 3.25, 'INTERNAL_PROJ_B': 6.0}
7/3/2014: {}
7/4/2014: {}
7/6/2014: {}
7/7/2014: {}
7/8/2014: {}
7/9/2014: {}
4. Disclaimer, part three
So, yeah, it doesn't sort perfectly by date. Sue me. I pay my lawyer good money for some good lying.
5. Statement of Existence
By fact of this gist's existence, this shit happened.
'''
#!/usr/bin/python
from re import search
from sys import argv
def crunch(times):
_times = {}
for line in times[1:]:
_line = line.split(',')
_day_times = {}
_date = _line[0]
for item in _line[1:]:
'''
if the item is not an errant return or newline char and is a blank entry
check if it's in the dict.
if it is, increment its value by .25 hours
if it is not, add it to the dict with a value of .25 hours
'''
if not search('\r|\n',item) and len(item) > 0:
if item in _day_times:
_day_times[item] += .25
else:
_day_times[item] = .25
_times[_date] = _day_times
return _times
if __name__ == '__main__':
f = open(argv[1],'r')
time_data = f.readlines()
f.close()
crunched_time = crunch(time_data)
for key in sorted(crunched_time):
print('%s: %s' % (key,crunched_time[key]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment