| 15394 |
manas |
1 |
'''
|
|
|
2 |
Created on 27-May-2015
|
|
|
3 |
|
|
|
4 |
@author: kshitij
|
|
|
5 |
'''
|
|
|
6 |
from datetime import date, datetime, timedelta
|
|
|
7 |
from dtr.storage.Mysql import getOrdersAfterDate, \
|
|
|
8 |
getOrdersByTag
|
|
|
9 |
from email import encoders
|
|
|
10 |
from email.mime.base import MIMEBase
|
|
|
11 |
from email.mime.multipart import MIMEMultipart
|
|
|
12 |
from email.mime.text import MIMEText
|
|
|
13 |
from pymongo.mongo_client import MongoClient
|
|
|
14 |
from xlrd import open_workbook
|
|
|
15 |
from xlutils.copy import copy
|
|
|
16 |
from xlwt.Workbook import Workbook
|
|
|
17 |
import MySQLdb
|
|
|
18 |
import smtplib
|
|
|
19 |
import time
|
|
|
20 |
import xlwt
|
|
|
21 |
import pymongo
|
|
|
22 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
|
|
23 |
from datetime import datetime
|
|
|
24 |
from elixir import *
|
|
|
25 |
from dtr.storage import DataService
|
|
|
26 |
from dtr.storage.DataService import Orders, Users, CallHistory
|
|
|
27 |
from sqlalchemy.sql.expression import func
|
|
|
28 |
|
|
|
29 |
DB_HOST = "localhost"
|
|
|
30 |
DB_USER = "root"
|
|
|
31 |
DB_PASSWORD = "shop2020"
|
|
|
32 |
DB_NAME = "dtr"
|
|
|
33 |
TMP_FILE = "/tmp/CRM_OutBound_Report.xls"
|
|
|
34 |
|
|
|
35 |
con = None
|
|
|
36 |
|
|
|
37 |
SENDER = "cnc.center@shop2020.in"
|
|
|
38 |
PASSWORD = "5h0p2o2o"
|
|
|
39 |
SUBJECT = "CRM Outbound Report for" + date.today().isoformat()
|
|
|
40 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
41 |
SMTP_PORT = 587
|
|
|
42 |
|
|
|
43 |
date_format = xlwt.XFStyle()
|
|
|
44 |
date_format.num_format_str = 'yyyy/mm/dd'
|
|
|
45 |
|
|
|
46 |
datetime_format = xlwt.XFStyle()
|
|
|
47 |
datetime_format.num_format_str = 'yyyy/mm/dd HH:MM AM/PM'
|
|
|
48 |
|
|
|
49 |
default_format = xlwt.XFStyle()
|
|
|
50 |
freshList=['1','2','3','4','5','6','7','8','9','10','11','12','13']
|
|
|
51 |
followUpList=['1','2','3','4','5','6','7']
|
|
|
52 |
onBoardingList=['1','2','3','4','5']
|
|
|
53 |
dispositionMap = { 'call_later':0,
|
|
|
54 |
'ringing_no_answer':1,
|
|
|
55 |
'not_reachable':2,
|
|
|
56 |
'switch_off':3,
|
|
|
57 |
'invalid_no':4,
|
|
|
58 |
'wrong_no':5,
|
|
|
59 |
'hang_up':6,
|
|
|
60 |
'retailer_not_interested':7,
|
|
|
61 |
'alreadyuser':8,
|
|
|
62 |
'verified_link_sent':9,
|
|
|
63 |
'accessory_retailer':10,
|
|
|
64 |
'service_center_retailer':11,
|
|
|
65 |
'not_retailer':12,
|
|
|
66 |
'recharge_retailer':13,
|
|
|
67 |
'onboarded':14
|
|
|
68 |
}
|
|
|
69 |
followUpDispositionMap = { 'call_later':0,
|
|
|
70 |
'ringing_no_answer':1,
|
|
|
71 |
'not_reachable':2,
|
|
|
72 |
'switch_off':3,
|
|
|
73 |
'retailer_not_interested':4,
|
|
|
74 |
'alreadyuser':5,
|
|
|
75 |
'verified_link_sent':6,
|
|
|
76 |
'not_retailer':7,
|
|
|
77 |
}
|
|
|
78 |
onBoardingDispositionMap = { 'call_later':0,
|
|
|
79 |
'ringing_no_answer':1,
|
|
|
80 |
'not_reachable':2,
|
|
|
81 |
'switch_off':3,
|
|
|
82 |
'onboarded':4,
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
FRESH_QUERY="""
|
|
|
86 |
select call_disposition,count(1) from
|
|
|
87 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
88 |
and call_type ='fresh' order by created desc)
|
|
|
89 |
as a group by retailer_id)
|
|
|
90 |
a1 group by date(created), call_disposition;
|
|
|
91 |
"""
|
|
|
92 |
AGENT_FRESH_QUERY="""
|
|
|
93 |
select call_disposition,count(1) from
|
|
|
94 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
95 |
and call_type ='fresh' and agent_id=%s order by created desc)
|
|
|
96 |
as a group by retailer_id)
|
|
|
97 |
a1 group by date(created), call_disposition,agent_id;
|
|
|
98 |
"""
|
|
|
99 |
AGENT_NAME_QUERY="""
|
|
|
100 |
select name from agents where id=%s
|
|
|
101 |
"""
|
|
|
102 |
FRESH_QUERY_LOGIN_TIME="""
|
|
|
103 |
select agent_id,TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='fresh' and date(created)=date(now());
|
|
|
104 |
"""
|
|
|
105 |
FRESH_QUERY_DURATION="""
|
|
|
106 |
select sum(duration_sec) from callhistory where call_type ='fresh' and date(created)=date(now());
|
|
|
107 |
"""
|
|
|
108 |
AGENT_FRESH_QUERY_LOGIN_TIME="""
|
|
|
109 |
select TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='fresh' and date(created)=date(now()) and agent_id=%s;
|
|
|
110 |
"""
|
|
|
111 |
AGENT_FRESH_QUERY_DURATION="""
|
|
|
112 |
select sum(duration_sec) from callhistory where call_type ='fresh' and date(created)=date(now()) and agent_id=%s;
|
|
|
113 |
"""
|
|
|
114 |
|
|
|
115 |
FOLLOW_UP_QUERY="""
|
|
|
116 |
select call_disposition,count(1) from
|
|
|
117 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
118 |
and call_type ='followup' order by created desc)
|
|
|
119 |
as a group by retailer_id)
|
|
|
120 |
a1 group by date(created), call_disposition;
|
|
|
121 |
"""
|
|
|
122 |
AGENT_FOLLOW_UP_QUERY="""
|
|
|
123 |
select call_disposition,count(1) from
|
|
|
124 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
125 |
and call_type ='followup' and agent_id=%s order by created desc)
|
|
|
126 |
as a group by retailer_id)
|
|
|
127 |
a1 group by date(created), call_disposition,agent_id;
|
|
|
128 |
"""
|
|
|
129 |
FOLLOW_UP_QUERY_LOGIN_TIME="""
|
|
|
130 |
select agent_id,TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='followup' and date(created)=date(now());
|
|
|
131 |
"""
|
|
|
132 |
FOLLOW_UP_QUERY_DURATION="""
|
|
|
133 |
select sum(duration_sec) from callhistory where call_type ='followup' and date(created)=date(now());
|
|
|
134 |
"""
|
|
|
135 |
AGENT_FOLLOW_UP_QUERY_LOGIN_TIME="""
|
|
|
136 |
select TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='followup' and date(created)=date(now()) and agent_id=%s;
|
|
|
137 |
"""
|
|
|
138 |
AGENT_FOLLOW_UP_QUERY_DURATION="""
|
|
|
139 |
select sum(duration_sec) from callhistory where call_type ='followup' and date(created)=date(now()) and agent_id=%s;
|
|
|
140 |
"""
|
|
|
141 |
|
|
|
142 |
ONBOARDING_QUERY="""
|
|
|
143 |
select call_disposition,count(1) from
|
|
|
144 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
145 |
and call_type ='onboarding' order by created desc)
|
|
|
146 |
as a group by retailer_id)
|
|
|
147 |
a1 group by date(created), call_disposition;
|
|
|
148 |
"""
|
|
|
149 |
AGENT_ONBOARDING_QUERY="""
|
|
|
150 |
select call_disposition,count(1) from
|
|
|
151 |
(select * from (select * from callhistory where date(created)=date(now())
|
|
|
152 |
and call_type ='onboarding' and agent_id=%s order by created desc)
|
|
|
153 |
as a group by retailer_id)
|
|
|
154 |
a1 group by date(created), call_disposition,agent_id;
|
|
|
155 |
"""
|
|
|
156 |
ONBOARDING_QUERY_LOGIN_TIME="""
|
|
|
157 |
select agent_id,TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='onboarding' and date(created)=date(now());
|
|
|
158 |
"""
|
|
|
159 |
ONBOARDING_QUERY_DURATION="""
|
|
|
160 |
select sum(duration_sec) from callhistory where call_type ='onboarding' and date(created)=date(now());
|
|
|
161 |
"""
|
|
|
162 |
AGENT_ONBOARDING_QUERY_LOGIN_TIME="""
|
|
|
163 |
select TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='onboarding' and date(created)=date(now()) and agent_id=%s;
|
|
|
164 |
"""
|
|
|
165 |
AGENT_ONBOARDING_QUERY_DURATION="""
|
|
|
166 |
select sum(duration_sec) from callhistory where call_type ='onboarding' and date(created)=date(now()) and agent_id=%s;
|
|
|
167 |
"""
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
def getDbConnection():
|
|
|
172 |
return MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
def generateFreshCallingReport():
|
|
|
176 |
datesql=FRESH_QUERY
|
|
|
177 |
conn = getDbConnection()
|
|
|
178 |
|
|
|
179 |
cursor = conn.cursor()
|
|
|
180 |
cursor.execute(datesql)
|
|
|
181 |
result = cursor.fetchall()
|
|
|
182 |
global workbook
|
|
|
183 |
workbook = xlwt.Workbook()
|
|
|
184 |
worksheet = workbook.add_sheet("Fresh")
|
|
|
185 |
boldStyle = xlwt.XFStyle()
|
|
|
186 |
newStyle= xlwt.XFStyle()
|
|
|
187 |
style = xlwt.XFStyle()
|
|
|
188 |
pattern = xlwt.Pattern()
|
|
|
189 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
190 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
191 |
style.pattern = pattern
|
|
|
192 |
f = xlwt.Font()
|
|
|
193 |
f.bold = True
|
|
|
194 |
boldStyle.font = f
|
|
|
195 |
|
|
|
196 |
column = 0
|
|
|
197 |
row = 0
|
|
|
198 |
currentList=[]
|
|
|
199 |
|
|
|
200 |
worksheet.write(0,0,'Call Disposition Type',style)
|
|
|
201 |
worksheet.write(0,1,'Count',style)
|
|
|
202 |
|
|
|
203 |
worksheet.write(1, column, 'Call Later', newStyle)
|
|
|
204 |
worksheet.write(2,column, 'Ringing No Answer', newStyle)
|
|
|
205 |
worksheet.write(3,column, 'Not Reachable', newStyle)
|
|
|
206 |
worksheet.write(4,column, 'Switched Off', newStyle)
|
|
|
207 |
worksheet.write(5,column, 'Invalid Number', newStyle)
|
|
|
208 |
worksheet.write(6,column, 'Wrong Number', newStyle)
|
|
|
209 |
worksheet.write(7,column, 'Hang Up', newStyle)
|
|
|
210 |
worksheet.write(8,column, 'Retailer Not Interested', newStyle)
|
|
|
211 |
worksheet.write(9,column, 'Already Profitmandi user', boldStyle)
|
|
|
212 |
worksheet.write(10,column, 'Verified Link Sent', boldStyle)
|
|
|
213 |
worksheet.write(11,column, 'Accessory Retailer', newStyle)
|
|
|
214 |
worksheet.write(12,column, 'Service Center Retailer', newStyle)
|
|
|
215 |
worksheet.write(13,column, 'Not a Retailer', newStyle)
|
|
|
216 |
worksheet.write(14,column, 'Recharge Retailer', newStyle)
|
|
|
217 |
worksheet.write(15,column, 'Contactable Data', newStyle)
|
|
|
218 |
worksheet.write(16,column, 'Non Contactable Data', newStyle)
|
|
|
219 |
worksheet.write(17,column, 'Agents Logged In', style)
|
|
|
220 |
worksheet.write(18,column, 'Average Login Time (In Hrs)', style)
|
|
|
221 |
worksheet.write(19,column, 'Total Dialed Out', style)
|
|
|
222 |
worksheet.write(20,column, 'Average Dialed Out per agent', style)
|
|
|
223 |
worksheet.write(21,column, 'Average Call Duration (In Hrs)', style)
|
|
|
224 |
contactableData=0
|
|
|
225 |
nonContactableData=0
|
|
|
226 |
|
|
|
227 |
for r in result:
|
|
|
228 |
row = dispositionMap.get(r[0])+1
|
|
|
229 |
if dispositionMap.get(r[0]) == 1 or dispositionMap.get(r[0]) == 2 or dispositionMap.get(r[0]) == 3 or dispositionMap.get(r[0]) == 4:
|
|
|
230 |
nonContactableData+=int(r[1])
|
|
|
231 |
else:
|
|
|
232 |
contactableData+=r[1]
|
|
|
233 |
currentList.append(str(row))
|
|
|
234 |
column = 1
|
|
|
235 |
worksheet.write(row, column, r[1])
|
|
|
236 |
|
|
|
237 |
remainingList = list(set(freshList) - set(currentList))
|
|
|
238 |
for i,val in enumerate(remainingList):
|
|
|
239 |
row = int(val)
|
|
|
240 |
column = 1
|
|
|
241 |
worksheet.write(row, column, 0)
|
|
|
242 |
totalDispositions=contactableData+nonContactableData
|
|
|
243 |
worksheet.write(15,1,(contactableData/float(totalDispositions))*100)
|
|
|
244 |
worksheet.write(16,1,(nonContactableData/float(totalDispositions))*100)
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
conn.close()
|
|
|
248 |
datesql=FRESH_QUERY_LOGIN_TIME
|
|
|
249 |
conn = getDbConnection()
|
|
|
250 |
|
|
|
251 |
cursor = conn.cursor()
|
|
|
252 |
cursor.execute(datesql)
|
|
|
253 |
result = cursor.fetchall()
|
|
|
254 |
agentLoginList=[]
|
|
|
255 |
loginTime=0
|
|
|
256 |
for r in result:
|
|
|
257 |
loginTime+=r[1].seconds
|
|
|
258 |
agentLoginList.append(str(r[0]))
|
|
|
259 |
averageLoginTime=loginTime/len(list(set(agentLoginList)))
|
|
|
260 |
hours=averageLoginTime/3600
|
|
|
261 |
minutesLeft=(averageLoginTime%3600)/60
|
|
|
262 |
worksheet.write(17,1,len(list(set(agentLoginList))))
|
|
|
263 |
worksheet.write(18,1,str(hours) + ':'+ str(minutesLeft))
|
|
|
264 |
worksheet.write(19,1,totalDispositions)
|
| 15395 |
manas |
265 |
print 'Avg' + str(totalDispositions/len(list(set(agentLoginList))))
|
|
|
266 |
print 'list' + list(set(agentLoginList))
|
|
|
267 |
worksheet.write(20,1,totalDispositions/len(list(set(agentLoginList))))
|
| 15394 |
manas |
268 |
conn.close()
|
|
|
269 |
datesql=FRESH_QUERY_DURATION
|
|
|
270 |
conn = getDbConnection()
|
|
|
271 |
|
|
|
272 |
cursor = conn.cursor()
|
|
|
273 |
cursor.execute(datesql)
|
|
|
274 |
result = cursor.fetchall()
|
|
|
275 |
for r in result:
|
|
|
276 |
totalCallDuration= r[0]
|
|
|
277 |
averageCallDuration=totalCallDuration/len(list(set(agentLoginList)))
|
|
|
278 |
hours=averageCallDuration/3600
|
|
|
279 |
minutesLeft=(averageCallDuration%3600)/60
|
|
|
280 |
worksheet.write(21,1,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
281 |
|
|
|
282 |
workbook.save(TMP_FILE)
|
|
|
283 |
#sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
def generateAgentWiseFreshCallingReport():
|
|
|
287 |
|
|
|
288 |
agentId=3
|
|
|
289 |
#global workbook
|
|
|
290 |
rb = open_workbook(TMP_FILE,formatting_info=True)
|
|
|
291 |
workbook = copy(rb)
|
|
|
292 |
numberOfSheets=rb.nsheets
|
|
|
293 |
print 'Number of sheets ' + str(numberOfSheets)
|
|
|
294 |
sheet=rb.sheet_by_index(numberOfSheets-1)
|
|
|
295 |
worksheet = workbook.get_sheet(numberOfSheets-1)
|
|
|
296 |
|
|
|
297 |
boldStyle = xlwt.XFStyle()
|
|
|
298 |
newStyle= xlwt.XFStyle()
|
|
|
299 |
style = xlwt.XFStyle()
|
|
|
300 |
pattern = xlwt.Pattern()
|
|
|
301 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
302 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
303 |
style.pattern = pattern
|
|
|
304 |
f = xlwt.Font()
|
|
|
305 |
f.bold = True
|
|
|
306 |
boldStyle.font = f
|
|
|
307 |
|
|
|
308 |
column = agentId
|
|
|
309 |
row = 25
|
|
|
310 |
worksheet.write(row,column-1,'Call Disposition Type',style)
|
|
|
311 |
worksheet.write(row+1, column-1, 'Call Later', newStyle)
|
|
|
312 |
worksheet.write(row+2,column-1, 'Ringing No Answer', newStyle)
|
|
|
313 |
worksheet.write(row+3,column-1, 'Not Reachable', newStyle)
|
|
|
314 |
worksheet.write(row+4,column-1, 'Switched Off', newStyle)
|
|
|
315 |
worksheet.write(row+5,column-1, 'Invalid Number', newStyle)
|
|
|
316 |
worksheet.write(row+6,column-1, 'Wrong Number', newStyle)
|
|
|
317 |
worksheet.write(row+7,column-1, 'Hang Up', newStyle)
|
|
|
318 |
worksheet.write(row+8,column-1, 'Retailer Not Interested', newStyle)
|
|
|
319 |
worksheet.write(row+9,column-1, 'Already Profitmandi user', boldStyle)
|
|
|
320 |
worksheet.write(row+10,column-1, 'Verified Link Sent', boldStyle)
|
|
|
321 |
worksheet.write(row+11,column-1, 'Accessory Retailer', newStyle)
|
|
|
322 |
worksheet.write(row+12,column-1, 'Service Center Retailer', newStyle)
|
|
|
323 |
worksheet.write(row+13,column-1, 'Not a Retailer', newStyle)
|
|
|
324 |
worksheet.write(row+14,column-1, 'Recharge Retailer', newStyle)
|
|
|
325 |
worksheet.write(row+15,column-1, 'Contactable Data', newStyle)
|
|
|
326 |
worksheet.write(row+16,column-1, 'Non Contactable Data', newStyle)
|
|
|
327 |
worksheet.write(row+17,column-1, 'Total Dialed Out', style)
|
|
|
328 |
worksheet.write(row+18,column-1, 'Login Time (In Hrs)', style)
|
|
|
329 |
worksheet.write(row+19,column-1, 'Call Duration (In Hrs)', style)
|
|
|
330 |
|
|
|
331 |
columnId=agentId
|
|
|
332 |
while True:
|
|
|
333 |
if agentId >5 :
|
|
|
334 |
break
|
|
|
335 |
else:
|
|
|
336 |
datesql=AGENT_FRESH_QUERY %(agentId)
|
|
|
337 |
conn = getDbConnection()
|
|
|
338 |
|
|
|
339 |
cursor = conn.cursor()
|
|
|
340 |
cursor.execute(datesql)
|
|
|
341 |
result = cursor.fetchall()
|
|
|
342 |
|
|
|
343 |
currentList=[]
|
|
|
344 |
contactableData=0
|
|
|
345 |
nonContactableData=0
|
|
|
346 |
if cursor.rowcount ==0:
|
|
|
347 |
|
|
|
348 |
agentId+=1
|
|
|
349 |
continue
|
|
|
350 |
else:
|
|
|
351 |
for r in result:
|
|
|
352 |
row = dispositionMap.get(r[0])+26
|
|
|
353 |
if dispositionMap.get(r[0]) == 1 or dispositionMap.get(r[0]) == 2 or dispositionMap.get(r[0]) == 3 or dispositionMap.get(r[0]) == 4:
|
|
|
354 |
nonContactableData+=int(r[1])
|
|
|
355 |
else:
|
|
|
356 |
contactableData+=r[1]
|
|
|
357 |
currentList.append(str(dispositionMap.get(r[0])))
|
|
|
358 |
column = agentId
|
|
|
359 |
remainingList = list(set(freshList) - set(currentList))
|
|
|
360 |
|
|
|
361 |
worksheet.write(row, columnId, r[1])
|
|
|
362 |
for i,val in enumerate(remainingList):
|
|
|
363 |
row = int(val)+26
|
|
|
364 |
column = agentId
|
|
|
365 |
worksheet.write(row, columnId, 0)
|
|
|
366 |
totalDialedOut = contactableData+nonContactableData
|
|
|
367 |
worksheet.write(25+15,columnId,(contactableData/float(totalDialedOut))*100)
|
|
|
368 |
worksheet.write(25+16,columnId,(nonContactableData/float(totalDialedOut))*100)
|
|
|
369 |
worksheet.write(25+17,columnId,totalDialedOut)
|
|
|
370 |
conn.close()
|
|
|
371 |
|
|
|
372 |
name_query=AGENT_NAME_QUERY %(agentId)
|
|
|
373 |
conn = getDbConnection()
|
|
|
374 |
column=agentId
|
|
|
375 |
cursor = conn.cursor()
|
|
|
376 |
cursor.execute(name_query)
|
|
|
377 |
result = cursor.fetchall()
|
|
|
378 |
for r in result:
|
|
|
379 |
worksheet.write(25,columnId,r,style)
|
|
|
380 |
|
|
|
381 |
conn.close()
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
name_query=AGENT_FRESH_QUERY_LOGIN_TIME %(agentId)
|
|
|
385 |
conn = getDbConnection()
|
|
|
386 |
column=agentId
|
|
|
387 |
cursor = conn.cursor()
|
|
|
388 |
cursor.execute(name_query)
|
|
|
389 |
result = cursor.fetchall()
|
|
|
390 |
loginTime=0
|
|
|
391 |
for r in result:
|
|
|
392 |
loginTime+=r[0].seconds
|
|
|
393 |
|
|
|
394 |
hours=loginTime/3600
|
|
|
395 |
minutesLeft=(loginTime%3600)/60
|
|
|
396 |
worksheet.write(25+18,columnId,str(hours)+':'+str(minutesLeft))
|
|
|
397 |
conn.close()
|
|
|
398 |
|
|
|
399 |
name_query=AGENT_FRESH_QUERY_DURATION %(agentId)
|
|
|
400 |
conn = getDbConnection()
|
|
|
401 |
column=agentId
|
|
|
402 |
cursor = conn.cursor()
|
|
|
403 |
cursor.execute(name_query)
|
|
|
404 |
result = cursor.fetchall()
|
|
|
405 |
loginTime=0
|
|
|
406 |
for r in result:
|
|
|
407 |
loginTime+=r[0]
|
|
|
408 |
hours=loginTime/3600
|
|
|
409 |
minutesLeft=(loginTime%3600)/60
|
|
|
410 |
worksheet.write(25+19,columnId,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
411 |
conn.close()
|
|
|
412 |
|
|
|
413 |
agentId+=1
|
|
|
414 |
columnId+=1
|
|
|
415 |
workbook.save(TMP_FILE)
|
|
|
416 |
#sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
|
|
|
417 |
|
|
|
418 |
def generateFollowUpCallingReport():
|
|
|
419 |
datesql=FOLLOW_UP_QUERY
|
|
|
420 |
conn = getDbConnection()
|
|
|
421 |
|
|
|
422 |
cursor = conn.cursor()
|
|
|
423 |
cursor.execute(datesql)
|
|
|
424 |
result = cursor.fetchall()
|
|
|
425 |
rb = open_workbook(TMP_FILE,formatting_info=True)
|
|
|
426 |
workbook = copy(rb)
|
|
|
427 |
|
|
|
428 |
worksheet = workbook.add_sheet("FollowUp")
|
|
|
429 |
boldStyle = xlwt.XFStyle()
|
|
|
430 |
newStyle= xlwt.XFStyle()
|
|
|
431 |
style = xlwt.XFStyle()
|
|
|
432 |
pattern = xlwt.Pattern()
|
|
|
433 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
434 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
435 |
style.pattern = pattern
|
|
|
436 |
f = xlwt.Font()
|
|
|
437 |
f.bold = True
|
|
|
438 |
boldStyle.font = f
|
|
|
439 |
|
|
|
440 |
column = 0
|
|
|
441 |
row = 0
|
|
|
442 |
currentList=[]
|
|
|
443 |
|
|
|
444 |
worksheet.write(0,0,'Call Disposition Type',style)
|
|
|
445 |
worksheet.write(0,1,'Count',style)
|
|
|
446 |
|
|
|
447 |
worksheet.write(1, column, 'Call Later', newStyle)
|
|
|
448 |
worksheet.write(2,column, 'Ringing No Answer', newStyle)
|
|
|
449 |
worksheet.write(3,column, 'Not Reachable', newStyle)
|
|
|
450 |
worksheet.write(4,column, 'Switched Off', newStyle)
|
|
|
451 |
worksheet.write(5,column, 'Retailer Not Interested', newStyle)
|
|
|
452 |
worksheet.write(6,column, 'Already Profitmandi user', boldStyle)
|
|
|
453 |
worksheet.write(7,column, 'Verified Link Sent', boldStyle)
|
|
|
454 |
worksheet.write(8,column, 'Not a retailer', boldStyle)
|
|
|
455 |
worksheet.write(9,column, 'Contactable Data', newStyle)
|
|
|
456 |
worksheet.write(10,column, 'Non Contactable Data', newStyle)
|
|
|
457 |
worksheet.write(11,column, 'Agents Logged In', style)
|
|
|
458 |
worksheet.write(12,column, 'Average Login Time (In Hrs)', style)
|
|
|
459 |
worksheet.write(13,column, 'Total Dialed Out', style)
|
|
|
460 |
worksheet.write(14,column, 'Average Dialed Out per agent', style)
|
|
|
461 |
worksheet.write(15,column, 'Average Call Duration (In Hrs)', style)
|
|
|
462 |
|
|
|
463 |
contactableData=0
|
|
|
464 |
nonContactableData=0
|
|
|
465 |
totalDispositions=0
|
|
|
466 |
print result
|
|
|
467 |
for r in result:
|
|
|
468 |
row = followUpDispositionMap.get(r[0])+1
|
|
|
469 |
if followUpDispositionMap.get(r[0]) == 1 or followUpDispositionMap.get(r[0]) == 2 or followUpDispositionMap.get(r[0]) == 3 or followUpDispositionMap.get(r[0]) == 4:
|
|
|
470 |
nonContactableData+=int(r[1])
|
|
|
471 |
else:
|
|
|
472 |
contactableData+=r[1]
|
|
|
473 |
currentList.append(str(row))
|
|
|
474 |
column = 1
|
|
|
475 |
worksheet.write(row, column, r[1])
|
|
|
476 |
|
|
|
477 |
remainingList = list(set(followUpList) - set(currentList))
|
|
|
478 |
print remainingList
|
|
|
479 |
for i,val in enumerate(remainingList):
|
|
|
480 |
row = int(val)
|
|
|
481 |
print row
|
|
|
482 |
column = 1
|
|
|
483 |
worksheet.write(row, column, 0)
|
|
|
484 |
totalDispositions=contactableData+nonContactableData
|
|
|
485 |
worksheet.write(9,1,(contactableData/float(totalDispositions))*100)
|
|
|
486 |
worksheet.write(10,1,(nonContactableData/float(totalDispositions))*100)
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
conn.close()
|
|
|
490 |
datesql=FOLLOW_UP_QUERY_LOGIN_TIME
|
|
|
491 |
conn = getDbConnection()
|
|
|
492 |
|
|
|
493 |
cursor = conn.cursor()
|
|
|
494 |
cursor.execute(datesql)
|
|
|
495 |
result = cursor.fetchall()
|
|
|
496 |
agentLoginList=[]
|
|
|
497 |
averageLoginTime=0
|
|
|
498 |
loginTime=0
|
|
|
499 |
for r in result:
|
|
|
500 |
loginTime+=r[1].seconds
|
|
|
501 |
agentLoginList.append(str(r[0]))
|
|
|
502 |
averageLoginTime=loginTime/len(list(set(agentLoginList)))
|
|
|
503 |
hours=averageLoginTime/3600
|
|
|
504 |
minutesLeft=(averageLoginTime%3600)/60
|
|
|
505 |
worksheet.write(11,1,len(list(set(agentLoginList))))
|
|
|
506 |
worksheet.write(12,1,str(hours) + ':'+ str(minutesLeft))
|
|
|
507 |
worksheet.write(13,1,totalDispositions)
|
|
|
508 |
worksheet.write(14,1,(contactableData+nonContactableData)/len(list(set(agentLoginList))))
|
|
|
509 |
conn.close()
|
|
|
510 |
datesql=FOLLOW_UP_QUERY_DURATION
|
|
|
511 |
conn = getDbConnection()
|
|
|
512 |
|
|
|
513 |
cursor = conn.cursor()
|
|
|
514 |
cursor.execute(datesql)
|
|
|
515 |
result = cursor.fetchall()
|
|
|
516 |
for r in result:
|
|
|
517 |
totalCallDuration= r[0]
|
|
|
518 |
averageCallDuration=totalCallDuration/len(list(set(agentLoginList)))
|
|
|
519 |
hours=averageCallDuration/3600
|
|
|
520 |
minutesLeft=(averageCallDuration%3600)/60
|
|
|
521 |
worksheet.write(15,1,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
522 |
workbook.save(TMP_FILE)
|
|
|
523 |
#sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
def generateAgentWiseFollowupCallingReport():
|
|
|
527 |
|
|
|
528 |
agentId=3
|
|
|
529 |
rb = open_workbook(TMP_FILE,formatting_info=True)
|
|
|
530 |
workbook = copy(rb)
|
|
|
531 |
numberOfSheets=rb.nsheets
|
|
|
532 |
print 'Number of sheets ' + str(numberOfSheets)
|
|
|
533 |
sheet=rb.sheet_by_index(numberOfSheets-1)
|
|
|
534 |
worksheet = workbook.get_sheet(numberOfSheets-1)
|
|
|
535 |
boldStyle = xlwt.XFStyle()
|
|
|
536 |
newStyle= xlwt.XFStyle()
|
|
|
537 |
style = xlwt.XFStyle()
|
|
|
538 |
pattern = xlwt.Pattern()
|
|
|
539 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
540 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
541 |
style.pattern = pattern
|
|
|
542 |
f = xlwt.Font()
|
|
|
543 |
f.bold = True
|
|
|
544 |
boldStyle.font = f
|
|
|
545 |
|
|
|
546 |
column = agentId
|
|
|
547 |
row = 25
|
|
|
548 |
worksheet.write(row,column-1,'Call Disposition Type',style)
|
|
|
549 |
worksheet.write(row+1, column-1, 'Call Later', newStyle)
|
|
|
550 |
worksheet.write(row+2,column-1, 'Ringing No Answer', newStyle)
|
|
|
551 |
worksheet.write(row+3,column-1, 'Not Reachable', newStyle)
|
|
|
552 |
worksheet.write(row+4,column-1, 'Switched Off', newStyle)
|
|
|
553 |
worksheet.write(row+5,column-1, 'Retailer Not Interested', newStyle)
|
|
|
554 |
worksheet.write(row+6,column-1, 'Already Profitmandi user', boldStyle)
|
|
|
555 |
worksheet.write(row+7,column-1, 'Verified Link Sent', boldStyle)
|
|
|
556 |
worksheet.write(row+8,column-1, 'Not a Retailer', newStyle)
|
|
|
557 |
worksheet.write(row+9,column-1, 'Contactable Data', newStyle)
|
|
|
558 |
worksheet.write(row+10,column-1, 'Non Contactable Data', newStyle)
|
|
|
559 |
worksheet.write(row+11,column-1, 'Total Dialed Out', style)
|
|
|
560 |
worksheet.write(row+12,column-1, 'Login Time (In Hrs)', style)
|
|
|
561 |
worksheet.write(row+13,column-1, 'Call Duration (In Hrs)', style)
|
|
|
562 |
|
|
|
563 |
columnId=agentId
|
|
|
564 |
while True:
|
|
|
565 |
if agentId >5 :
|
|
|
566 |
break
|
|
|
567 |
else:
|
|
|
568 |
datesql=AGENT_FOLLOW_UP_QUERY %(agentId)
|
|
|
569 |
conn = getDbConnection()
|
|
|
570 |
|
|
|
571 |
cursor = conn.cursor()
|
|
|
572 |
cursor.execute(datesql)
|
|
|
573 |
result = cursor.fetchall()
|
|
|
574 |
|
|
|
575 |
currentList=[]
|
|
|
576 |
contactableData=0
|
|
|
577 |
nonContactableData=0
|
|
|
578 |
if cursor.rowcount ==0:
|
|
|
579 |
agentId+=1
|
|
|
580 |
continue
|
|
|
581 |
else:
|
|
|
582 |
print result
|
|
|
583 |
for r in result:
|
|
|
584 |
row = followUpDispositionMap.get(r[0])+26
|
|
|
585 |
if followUpDispositionMap.get(r[0]) == 1 or followUpDispositionMap.get(r[0]) == 2 or followUpDispositionMap.get(r[0]) == 3 or followUpDispositionMap.get(r[0]) == 4:
|
|
|
586 |
nonContactableData+=int(r[1])
|
|
|
587 |
else:
|
|
|
588 |
contactableData+=r[1]
|
|
|
589 |
currentList.append(str(followUpDispositionMap.get(r[0])+1))
|
|
|
590 |
column = agentId
|
|
|
591 |
worksheet.write(row, columnId, r[1])
|
|
|
592 |
remainingList = list(set(followUpList) - set(currentList))
|
|
|
593 |
|
|
|
594 |
for i,val in enumerate(remainingList):
|
|
|
595 |
row = int(val)+25
|
|
|
596 |
column = agentId
|
|
|
597 |
worksheet.write(row, columnId, 0)
|
|
|
598 |
totalDialedOut = contactableData+nonContactableData
|
|
|
599 |
worksheet.write(25+9,columnId,(contactableData/float(totalDialedOut))*100)
|
|
|
600 |
worksheet.write(25+10,columnId,(nonContactableData/float(totalDialedOut))*100)
|
|
|
601 |
worksheet.write(25+11,columnId,totalDialedOut)
|
|
|
602 |
conn.close()
|
|
|
603 |
|
|
|
604 |
name_query=AGENT_NAME_QUERY %(agentId)
|
|
|
605 |
conn = getDbConnection()
|
|
|
606 |
column=agentId
|
|
|
607 |
cursor = conn.cursor()
|
|
|
608 |
cursor.execute(name_query)
|
|
|
609 |
result = cursor.fetchall()
|
|
|
610 |
for r in result:
|
|
|
611 |
worksheet.write(25,columnId,r,style)
|
|
|
612 |
|
|
|
613 |
conn.close()
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
name_query=AGENT_FOLLOW_UP_QUERY_LOGIN_TIME %(agentId)
|
|
|
617 |
conn = getDbConnection()
|
|
|
618 |
column=agentId
|
|
|
619 |
cursor = conn.cursor()
|
|
|
620 |
cursor.execute(name_query)
|
|
|
621 |
result = cursor.fetchall()
|
|
|
622 |
loginTime=0
|
|
|
623 |
for r in result:
|
|
|
624 |
loginTime+=r[0].seconds
|
|
|
625 |
|
|
|
626 |
hours=loginTime/3600
|
|
|
627 |
minutesLeft=(loginTime%3600)/60
|
|
|
628 |
worksheet.write(25+12,columnId,str(hours)+':'+str(minutesLeft))
|
|
|
629 |
conn.close()
|
|
|
630 |
|
|
|
631 |
name_query=AGENT_FOLLOW_UP_QUERY_DURATION %(agentId)
|
|
|
632 |
conn = getDbConnection()
|
|
|
633 |
column=agentId
|
|
|
634 |
cursor = conn.cursor()
|
|
|
635 |
cursor.execute(name_query)
|
|
|
636 |
result = cursor.fetchall()
|
|
|
637 |
loginTime=0
|
|
|
638 |
for r in result:
|
|
|
639 |
loginTime+=r[0]
|
|
|
640 |
hours=loginTime/3600
|
|
|
641 |
minutesLeft=(loginTime%3600)/60
|
|
|
642 |
worksheet.write(25+13,columnId,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
643 |
conn.close()
|
|
|
644 |
|
|
|
645 |
agentId+=1
|
|
|
646 |
columnId+=1
|
|
|
647 |
workbook.save(TMP_FILE)
|
|
|
648 |
#sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
|
|
|
649 |
|
|
|
650 |
def generateOnBoardingCallingReport():
|
|
|
651 |
datesql=ONBOARDING_QUERY
|
|
|
652 |
conn = getDbConnection()
|
|
|
653 |
|
|
|
654 |
cursor = conn.cursor()
|
|
|
655 |
cursor.execute(datesql)
|
|
|
656 |
result = cursor.fetchall()
|
|
|
657 |
rb = open_workbook(TMP_FILE,formatting_info=True)
|
|
|
658 |
workbook = copy(rb)
|
|
|
659 |
|
|
|
660 |
worksheet = workbook.add_sheet("Onboarding")
|
|
|
661 |
boldStyle = xlwt.XFStyle()
|
|
|
662 |
newStyle= xlwt.XFStyle()
|
|
|
663 |
style = xlwt.XFStyle()
|
|
|
664 |
pattern = xlwt.Pattern()
|
|
|
665 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
666 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
667 |
style.pattern = pattern
|
|
|
668 |
f = xlwt.Font()
|
|
|
669 |
f.bold = True
|
|
|
670 |
boldStyle.font = f
|
|
|
671 |
|
|
|
672 |
column = 0
|
|
|
673 |
row = 0
|
|
|
674 |
currentList=[]
|
|
|
675 |
|
|
|
676 |
worksheet.write(0,0,'Call Disposition Type',style)
|
|
|
677 |
worksheet.write(0,1,'Count',style)
|
|
|
678 |
worksheet.write(1, column, 'Call Later', newStyle)
|
|
|
679 |
worksheet.write(2,column, 'Ringing No Answer', newStyle)
|
|
|
680 |
worksheet.write(3,column, 'Not Reachable', newStyle)
|
|
|
681 |
worksheet.write(4,column, 'Switched Off', newStyle)
|
|
|
682 |
worksheet.write(5,column, 'Successful', newStyle)
|
|
|
683 |
worksheet.write(6,column, 'Contactable Data', newStyle)
|
|
|
684 |
worksheet.write(7,column, 'Non Contactable Data', newStyle)
|
|
|
685 |
worksheet.write(8,column, 'Agents Logged In', style)
|
|
|
686 |
worksheet.write(9,column, 'Average Login Time (In Hrs)', style)
|
|
|
687 |
worksheet.write(10,column, 'Total Dialed Out', style)
|
|
|
688 |
worksheet.write(11,column, 'Average Dialed Out per agent', style)
|
|
|
689 |
worksheet.write(12,column, 'Average Call Duration (In Hrs)', style)
|
|
|
690 |
|
|
|
691 |
contactableData=0
|
|
|
692 |
nonContactableData=0
|
|
|
693 |
totalDispositions=0
|
|
|
694 |
print result
|
|
|
695 |
for r in result:
|
|
|
696 |
row = onBoardingDispositionMap.get(r[0])+1
|
|
|
697 |
if onBoardingDispositionMap.get(r[0]) == 1 or onBoardingDispositionMap.get(r[0]) == 2 or onBoardingDispositionMap.get(r[0]) == 3:
|
|
|
698 |
nonContactableData+=int(r[1])
|
|
|
699 |
else:
|
|
|
700 |
contactableData+=r[1]
|
|
|
701 |
currentList.append(str(row))
|
|
|
702 |
column = 1
|
|
|
703 |
worksheet.write(row, column, r[1])
|
|
|
704 |
|
|
|
705 |
remainingList = list(set(onBoardingList) - set(currentList))
|
|
|
706 |
print remainingList
|
|
|
707 |
for i,val in enumerate(remainingList):
|
|
|
708 |
row = int(val)
|
|
|
709 |
print row
|
|
|
710 |
column = 1
|
|
|
711 |
worksheet.write(row, column, 0)
|
|
|
712 |
totalDispositions=contactableData+nonContactableData
|
|
|
713 |
worksheet.write(6,1,(contactableData/float(totalDispositions))*100)
|
|
|
714 |
worksheet.write(7,1,(nonContactableData/float(totalDispositions))*100)
|
|
|
715 |
|
|
|
716 |
|
|
|
717 |
conn.close()
|
|
|
718 |
datesql=ONBOARDING_QUERY_LOGIN_TIME
|
|
|
719 |
conn = getDbConnection()
|
|
|
720 |
|
|
|
721 |
cursor = conn.cursor()
|
|
|
722 |
cursor.execute(datesql)
|
|
|
723 |
result = cursor.fetchall()
|
|
|
724 |
agentLoginList=[]
|
|
|
725 |
averageLoginTime=0
|
|
|
726 |
loginTime=0
|
|
|
727 |
for r in result:
|
|
|
728 |
loginTime+=r[1].seconds
|
|
|
729 |
agentLoginList.append(str(r[0]))
|
|
|
730 |
averageLoginTime=loginTime/len(list(set(agentLoginList)))
|
|
|
731 |
hours=averageLoginTime/3600
|
|
|
732 |
minutesLeft=(averageLoginTime%3600)/60
|
|
|
733 |
worksheet.write(8,1,len(list(set(agentLoginList))))
|
|
|
734 |
worksheet.write(9,1,str(hours) + ':'+ str(minutesLeft))
|
|
|
735 |
worksheet.write(10,1,totalDispositions)
|
|
|
736 |
worksheet.write(11,1,(contactableData+nonContactableData)/len(list(set(agentLoginList))))
|
|
|
737 |
conn.close()
|
|
|
738 |
datesql=ONBOARDING_QUERY_DURATION
|
|
|
739 |
conn = getDbConnection()
|
|
|
740 |
|
|
|
741 |
cursor = conn.cursor()
|
|
|
742 |
cursor.execute(datesql)
|
|
|
743 |
result = cursor.fetchall()
|
|
|
744 |
for r in result:
|
|
|
745 |
totalCallDuration= r[0]
|
|
|
746 |
averageCallDuration=totalCallDuration/len(list(set(agentLoginList)))
|
|
|
747 |
hours=averageCallDuration/3600
|
|
|
748 |
minutesLeft=(averageCallDuration%3600)/60
|
|
|
749 |
worksheet.write(12,1,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
750 |
workbook.save(TMP_FILE)
|
|
|
751 |
#sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
def generateAgentWiseOnboardingCallingReport():
|
|
|
755 |
|
|
|
756 |
agentId=3
|
|
|
757 |
rb = open_workbook(TMP_FILE,formatting_info=True)
|
|
|
758 |
workbook = copy(rb)
|
|
|
759 |
numberOfSheets=rb.nsheets
|
|
|
760 |
print 'Number of sheets ' + str(numberOfSheets)
|
|
|
761 |
sheet=rb.sheet_by_index(numberOfSheets-1)
|
|
|
762 |
worksheet = workbook.get_sheet(numberOfSheets-1)
|
|
|
763 |
boldStyle = xlwt.XFStyle()
|
|
|
764 |
newStyle= xlwt.XFStyle()
|
|
|
765 |
style = xlwt.XFStyle()
|
|
|
766 |
pattern = xlwt.Pattern()
|
|
|
767 |
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
|
|
|
768 |
pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
|
|
|
769 |
style.pattern = pattern
|
|
|
770 |
f = xlwt.Font()
|
|
|
771 |
f.bold = True
|
|
|
772 |
boldStyle.font = f
|
|
|
773 |
|
|
|
774 |
column = agentId
|
|
|
775 |
row = 25
|
|
|
776 |
|
|
|
777 |
worksheet.write(row,column-1,'Call Disposition Type',style)
|
|
|
778 |
worksheet.write(row+1, column-1, 'Call Later', newStyle)
|
|
|
779 |
worksheet.write(row+2,column-1, 'Ringing No Answer', newStyle)
|
|
|
780 |
worksheet.write(row+3,column-1, 'Not Reachable', newStyle)
|
|
|
781 |
worksheet.write(row+4,column-1, 'Switched Off', newStyle)
|
|
|
782 |
worksheet.write(row+5,column-1, 'Successful', newStyle)
|
|
|
783 |
worksheet.write(row+6,column-1, 'Contactable Data', newStyle)
|
|
|
784 |
worksheet.write(row+7,column-1, 'Non Contactable Data', newStyle)
|
|
|
785 |
worksheet.write(row+8,column-1, 'Total Dialed Out', style)
|
|
|
786 |
worksheet.write(row+9,column-1, 'Login Time (In Hrs)', style)
|
|
|
787 |
worksheet.write(row+10,column-1, 'Call Duration (In Hrs)', style)
|
|
|
788 |
|
|
|
789 |
columnId=agentId
|
|
|
790 |
while True:
|
|
|
791 |
if agentId >5 :
|
|
|
792 |
break
|
|
|
793 |
else:
|
|
|
794 |
datesql=AGENT_ONBOARDING_QUERY %(agentId)
|
|
|
795 |
conn = getDbConnection()
|
|
|
796 |
|
|
|
797 |
cursor = conn.cursor()
|
|
|
798 |
cursor.execute(datesql)
|
|
|
799 |
result = cursor.fetchall()
|
|
|
800 |
|
|
|
801 |
currentList=[]
|
|
|
802 |
contactableData=0
|
|
|
803 |
nonContactableData=0
|
|
|
804 |
if cursor.rowcount ==0:
|
|
|
805 |
agentId+=1
|
|
|
806 |
continue
|
|
|
807 |
else:
|
|
|
808 |
print result
|
|
|
809 |
for r in result:
|
|
|
810 |
row = onBoardingDispositionMap.get(r[0])+26
|
|
|
811 |
if onBoardingDispositionMap.get(r[0]) == 1 or onBoardingDispositionMap.get(r[0]) == 2 or onBoardingDispositionMap.get(r[0]) == 3 or followUpDispositionMap.get(r[0]) == 4:
|
|
|
812 |
nonContactableData+=int(r[1])
|
|
|
813 |
else:
|
|
|
814 |
contactableData+=r[1]
|
|
|
815 |
currentList.append(str(onBoardingDispositionMap.get(r[0])+1))
|
|
|
816 |
column = agentId
|
|
|
817 |
worksheet.write(row, columnId, r[1])
|
|
|
818 |
remainingList = list(set(onBoardingList) - set(currentList))
|
|
|
819 |
|
|
|
820 |
for i,val in enumerate(remainingList):
|
|
|
821 |
row = int(val)+25
|
|
|
822 |
column = agentId
|
|
|
823 |
worksheet.write(row, columnId, 0)
|
|
|
824 |
totalDialedOut = contactableData+nonContactableData
|
|
|
825 |
worksheet.write(25+6,columnId,(contactableData/float(totalDialedOut))*100)
|
|
|
826 |
worksheet.write(25+7,columnId,(nonContactableData/float(totalDialedOut))*100)
|
|
|
827 |
worksheet.write(25+8,columnId,totalDialedOut)
|
|
|
828 |
conn.close()
|
|
|
829 |
|
|
|
830 |
name_query=AGENT_NAME_QUERY %(agentId)
|
|
|
831 |
conn = getDbConnection()
|
|
|
832 |
column=agentId
|
|
|
833 |
cursor = conn.cursor()
|
|
|
834 |
cursor.execute(name_query)
|
|
|
835 |
result = cursor.fetchall()
|
|
|
836 |
for r in result:
|
|
|
837 |
worksheet.write(25,columnId,r,style)
|
|
|
838 |
|
|
|
839 |
conn.close()
|
|
|
840 |
|
|
|
841 |
|
|
|
842 |
name_query=ONBOARDING_QUERY_LOGIN_TIME %(agentId)
|
|
|
843 |
conn = getDbConnection()
|
|
|
844 |
column=agentId
|
|
|
845 |
cursor = conn.cursor()
|
|
|
846 |
cursor.execute(name_query)
|
|
|
847 |
result = cursor.fetchall()
|
|
|
848 |
loginTime=0
|
|
|
849 |
for r in result:
|
|
|
850 |
loginTime+=r[0].seconds
|
|
|
851 |
|
|
|
852 |
hours=loginTime/3600
|
|
|
853 |
minutesLeft=(loginTime%3600)/60
|
|
|
854 |
worksheet.write(25+9,columnId,str(hours)+':'+str(minutesLeft))
|
|
|
855 |
conn.close()
|
|
|
856 |
|
|
|
857 |
name_query=ONBOARDING_QUERY_DURATION %(agentId)
|
|
|
858 |
conn = getDbConnection()
|
|
|
859 |
column=agentId
|
|
|
860 |
cursor = conn.cursor()
|
|
|
861 |
cursor.execute(name_query)
|
|
|
862 |
result = cursor.fetchall()
|
|
|
863 |
loginTime=0
|
|
|
864 |
for r in result:
|
|
|
865 |
loginTime+=r[0]
|
|
|
866 |
hours=loginTime/3600
|
|
|
867 |
minutesLeft=(loginTime%3600)/60
|
|
|
868 |
worksheet.write(25+10,columnId,str(int(hours))+':'+str(int(minutesLeft)))
|
|
|
869 |
conn.close()
|
|
|
870 |
|
|
|
871 |
agentId+=1
|
|
|
872 |
columnId+=1
|
|
|
873 |
workbook.save(TMP_FILE)
|
|
|
874 |
|
|
|
875 |
|
|
|
876 |
|
|
|
877 |
def main():
|
|
|
878 |
generateFreshCallingReport()
|
|
|
879 |
generateAgentWiseFreshCallingReport()
|
|
|
880 |
generateFollowUpCallingReport()
|
|
|
881 |
generateAgentWiseFollowupCallingReport()
|
|
|
882 |
generateOnBoardingCallingReport()
|
|
|
883 |
generateAgentWiseOnboardingCallingReport()
|
|
|
884 |
|
|
|
885 |
def sendmail(email, message, fileName, title):
|
|
|
886 |
if email == "":
|
|
|
887 |
return
|
|
|
888 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
889 |
mailServer.ehlo()
|
|
|
890 |
mailServer.starttls()
|
|
|
891 |
mailServer.ehlo()
|
|
|
892 |
|
|
|
893 |
# Create the container (outer) email message.
|
|
|
894 |
msg = MIMEMultipart()
|
|
|
895 |
msg['Subject'] = title
|
|
|
896 |
msg.preamble = title
|
|
|
897 |
html_msg = MIMEText(message, 'html')
|
|
|
898 |
msg.attach(html_msg)
|
|
|
899 |
|
|
|
900 |
fileMsg = MIMEBase('application', 'vnd.ms-excel')
|
|
|
901 |
fileMsg.set_payload(file(TMP_FILE).read())
|
|
|
902 |
encoders.encode_base64(fileMsg)
|
|
|
903 |
fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
904 |
msg.attach(fileMsg)
|
|
|
905 |
print 'Sending report'
|
|
|
906 |
#MAILTO = ['manas.kapoor@saholic.com','rajneesh.arora@saholic.com']
|
|
|
907 |
MAILTO = ['manas.kapoor@saholic.com']
|
|
|
908 |
mailServer.login(SENDER, PASSWORD)
|
|
|
909 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
910 |
|
|
|
911 |
if __name__ == '__main__':
|
|
|
912 |
main()
|