Last active
December 17, 2015 16:58
-
-
Save petrjoachim/5642233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf-8 | |
""" | |
V pondeli do 9:00 mi to vzdy poslete v excelu ve formatu | |
|| Sluzba || Projekt || Pocet odpracovanych hodin || Pocet lidi || | |
report lze ziskat v neznamu, ocekava to vstup z exportu ktery najdete v | |
Neznam - sluzby - prehled prace - [filtr] - vypis - [exportovat pro excel] | |
"Datum";"Zaměstnanec";"Služba";"Projekt";"Doba (h)";"Popis" | |
""" | |
import csv | |
from collections import defaultdict | |
from datetime import timedelta | |
import time | |
def read(filename='export.csv'): | |
reader = csv.reader(open(filename, 'rb'), delimiter=';') | |
for line in reader: | |
yield [unicode(cell, 'cp1250') for cell in line] | |
def write(data, filename='kouzelny-report.csv'): | |
writer = csv.writer(open(filename, 'w'), delimiter=';') | |
for row in data: | |
writer.writerow([cell.encode('cp1250') for cell in row]) | |
def do_the_magic(group_maintenance=True, group_administration=True): | |
data = defaultdict(lambda: { | |
'time': timedelta(), | |
'people': set(), | |
'service': '', | |
'project': '', | |
}) | |
for line in read(): | |
try: | |
t = time.strptime(line[4], "%H:%M") | |
except ValueError: | |
# this was not a duck. | |
continue | |
service = '' | |
project = '' | |
if group_maintenance and 'maintenance' in line[3].lower(): | |
service_project = 'Maintenance' | |
service = 'Maintenance' | |
elif group_administration and line[2] == 'Administrativa': | |
service_project = 'Administrativa' | |
service = 'Administrativa' | |
else: | |
service_project = "%s-%s" % (line[2], line[3]) | |
service = line[2] | |
project = line[3] | |
row = data[service_project] | |
row['people'].add(line[1]) | |
row['service'] = service | |
row['project'] = project | |
row['time'] += timedelta(hours=t.tm_hour, minutes=t.tm_min) | |
return [[ | |
value['service'], | |
value['project'], | |
"%d:%d" % ( | |
value['time'].total_seconds() // 3600, | |
value['time'].total_seconds() % 3600 // 60), | |
str(len(value['people'])), | |
"%.1f" % (value['time'].total_seconds() / 3600 / 40)] for key, value in data.iteritems()] | |
if __name__ == '__main__': | |
write(do_the_magic()) | |
# write(do_the_magic(group_maintenance=False)) | |
# write(do_the_magic(group_administration=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment