forked from Guillotine17/qbReporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qbReporterFinal.py
190 lines (153 loc) · 3.43 KB
/
qbReporterFinal.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import csv
class Client:
def __init__(self, name):
self.name = name
self.time = float(0)
def addTime(self, time):
self.time = self.time + float(time)
def getName(self):
return self.name
def getTime(self):
return self.time
class Caller:
def __init__(self, name):
self.name = name
self.clients = []
def getName(self):
return self.name
def addClient(self, clientName):
self.clients.append(Client(clientName))
def addTime(self, clientName, time):
for client in self.clients:
if client.getName() == clientName:
client.addTime(time)
def getClients(self):
return self.clients
def getConfig():
fh = open("qbReporterConfig", "rbU")
lines = fh.readlines()
settings = []
for line in lines:
if line[0] == '#':
continue
else:
split = line.split(':')
settings.append(split[-1][:-1])
fh.close()
return settings
#inputFile:
#CallerColumn:
#clientColumn:
#timeColumn:
def isTotal(row):
if row[0] == '':
return False
if row[0].split()[0] == "Total":
return True
def getCaller(row):
return row[callerColumn]
def getClient(row):
return row[clientColumn]
def getTime(row):
return row[timeColumn]
def updateClients(clientName):
global clients
if clientName not in clients:
clients.append(clientName)
def updateCallers(clientToAdd):
global callers
for caller in callers:
found = 0
for client in caller.clients:
if client.getName() == clientToAdd:
found = 1
break
if found == 0:
caller.addClient(clientToAdd)
def update():
global clients
global callers
global currentClient
updateClients(currentClient)
for client in clients:
updateCallers(client)
def firstFilledRestEmpty(row):
if row[0] != '':
row.pop(0)
for each in row:
if each != '':
return False
return True
else:
return False
def allBlank(row):
for x in row:
if x != '':
return False
return True
def isHeader(row):
if row[1] == 'Activity Date':
return True
return False
def evaluate(row):
if isTotal(row):
return False
elif firstFilledRestEmpty(row):
return False
elif allBlank(row):
return False
elif isHeader(row):
return False
else:
return True
def main():
global clientColumn
global callerColumn
global timeColumn
global clients
global callers
global currentClient
settings = getConfig()
#load config
inputFile = settings[0]
callerColumn = int(settings[1])
clientColumn = int(settings[2])
timeColumn = int(settings[3])
#print settings[3]
clients = []
callers = []
currentClient = ''
with open(inputFile, 'rbU') as f:
reader = csv.reader(f)
for row in reader:
if not evaluate(row):
continue
currentClient = getClient(row)
#print row
if currentClient not in clients:
update()
caller = getCaller(row)
found = 0
for employee in callers:
callerName = employee.getName()
if callerName == caller:
found = 1
employee.addTime(currentClient,getTime(row))
break
if found == 0:
callers.append(Caller(caller))
update()
callers[-1].addTime(currentClient, getTime(row))
########OUTPUT############
with open('csvWriterOutput.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',', quotechar = '"', quoting = csv.QUOTE_MINIMAL)
spamwriter.writerow(["caller"] + clients)
for employee in callers:
times = []
for client in employee.clients:
times.append(str(client.time))
spamwriter.writerow([employee.name] + times)
#print times
return callers
if __name__ == "__main__":
main()