-
Notifications
You must be signed in to change notification settings - Fork 0
/
punches.py
104 lines (78 loc) · 2.58 KB
/
punches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import csv
# This dictionary stores all the info needed
employee_hours = {}
def create_employee(name):
'''
[billed hours, unbilled hours, hrvst total, clock hours, hrvst %, billed %]
'''
employee_hours[name] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
def add_unbill_hrs(name, hours):
employee_hours[name][0] += hours
def add_bill_hrs(name, hours):
employee_hours[name][1] += hours
def add_harvest_total(name, hours):
employee_hours[name][2] += hours
def add_clock_hrs(name, hours):
employee_hours[name][3] += hours
def add_harvest_perc(name, hours):
employee_hours[name][4] += hours
def add_billed_perc(name, hours):
employee_hours[name][5] += hours
def percentage(part, whole):
if whole != 0:
return float(part)/float(whole)
else:
return 0.0
'''
----------------Process the Harvest CSV file------------------------
First Last Hours Billable 'Yes' or 'No'
row[12] row[13] row[6] row[10]
'''
f = open('harvest.csv')
csv_f = csv.reader(f)
f.next()
for row in csv_f:
name = row[12]
hours = round(float(row[6]), 2)
billable = True if row[10] == 'Yes' else False
if name not in employee_hours:
create_employee(name)
add_harvest_total(name, hours)
if billable:
add_bill_hrs(name, hours)
else:
add_unbill_hrs(name, hours)
'''
------------Process the Icon CSV file---------------
First Last Hours OT1 OT2
row[0] row[2] row[27] row[28] row[2]
'''
g = open('icon.csv')
csv_g = csv.reader(g)
g.next()
for row in csv_g:
name = row[0]
#don't forget overtime in rows 28 and 29
mins = round(float(row[27]) + float(row[28]) + float(row[29]), 2)
hours = round(mins/60, 2)
if name not in employee_hours:
create_employee(name)
add_clock_hrs(name, hours)
'''
----------Compute Percentages-----------------
'''
for employee in employee_hours:
# harvest_unbilled = employee_hours[employee][0]
harvest_billed = employee_hours[employee][1]
harvest_total = employee_hours[employee][2]
clock_total = employee_hours[employee][3]
# set to harvest total if they don't clock in
# set the value as well so the spreadsheet reads correctly
#
if clock_total == 0.0:
employee_hours[employee][3] = harvest_total
clock_total = harvest_total
harvest_perc = percentage(harvest_total, clock_total)
billed_perc = percentage(harvest_billed, clock_total)
add_harvest_perc(employee, harvest_perc)
add_billed_perc(employee, billed_perc)