-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra.py
772 lines (728 loc) · 28.6 KB
/
extra.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
from django.shortcuts import render
from elasticsearch import Elasticsearch
import pandas as pd
import numpy as np
from elasticsearch import helpers
from decouple import config
from rest_framework import fields
from rest_framework.serializers import Serializer
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
import json
import utils.response_handler as rh
import random
from auth_login.models import Reporting
from auth_login.serializers import Reportingserializer
import xmltodict
from urllib.request import urlopen
import requests
class Softskillview(APIView):
def post(self,request,format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
fields=["Curiousity","Paraphrasing", "Active Listening","Probing", "Clarity", "Responsiveness","Rate of speech (WPM)" ,"Voice volume"]
fields1=["Rate of speech (WPM)" ,"Voice volume"]
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
for field in fields:
if field not in fields1:
search_params["aggs"]={
"Avg_softskills": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
final_data[field]=round(data["aggregations"]["Avg_softskills"]["value"]*100,2)
color=round(data["aggregations"]["Avg_softskills"]["value"]*100,2)
if color<=40:
final_data[field+"_color"]="#D65654"
final_data[field+"_range"]="Low"
elif color>40 and color<=75:
final_data[field+"_color"]="#F8DA77"
final_data[field+"_range"]="Medium"
else:
final_data[field+"_color"]="#4CC57E"
final_data[field+"_range"]="High"
else:
search_params["aggs"]={
"Rate_of_speech": {
"terms": {
"field": "Rate of speech (WPM)",
"size": 10000
}
},
"Voice_volume": {
"terms": {
"field": "Voice volume",
"size": 10000
}}
}
data=es.search(index='quality_works', body=search_params)
rate_of_speech_list=[]
voice_volume_list=[]
for k in data["aggregations"]["Rate_of_speech"]["buckets"]:
rate_of_speech_list.append(k["key"])
for k in data["aggregations"]["Voice_volume"]["buckets"]:
voice_volume_list.append(round(k["key"]*100))
final_data["rate_of_speech"]=rate_of_speech_list
final_data["max_rate_of_speech"]=max(rate_of_speech_list)
final_data["min_rate_of_speech"]=min(rate_of_speech_list)
final_data["voice_volume"]=voice_volume_list
final_data["max_voice_volume"]=max(voice_volume_list)
final_data["min_voice_volume"]=min(voice_volume_list)
r=rh.ResponseMsg(data=final_data, error=False, msg="Soft skills AVG Successfully GET!!!!!!!!!!!!!!!")
return Response(r.response)
class Processknowledgeview(APIView):
def post(self,request,format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
fields=["Information accuracy","Critical miss","Non-critical miss","Troubleshooting"]
fields1=["Call trasfer rate"]
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
for field in fields:
if field not in fields1:
search_params["aggs"]={
"Process_knowledge_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
final_data[field]=round(data["aggregations"]["Process_knowledge_avg"]["value"]*100)
color=round(data["aggregations"]["Process_knowledge_avg"]["value"]*100)
if color<=40:
final_data[field+"_color"]="#D65654"
elif color>40 and color<=75:
final_data[field+"_color"]="#F8DA77"
else:
final_data[field+"_color"]="#4CC57E"
else:
search_params["aggs"]={
"call_transfer_rate": {
"terms": {
"field": "Call trasfer rate",
"size": 10000
}
}
}
data=es.search(index='quality_works', body=search_params)
call_transfer_rate_list=[]
for k in data["aggregations"]["call_transfer_rate"]["buckets"]:
call_transfer_rate_list.append(round(k["key"]*100))
final_data["call_transfer_rate"]=call_transfer_rate_list
final_data["max_call_transfer_rate"]=max(call_transfer_rate_list)
final_data["min_call_transfer_rate"]=min(call_transfer_rate_list)
final_data["Deactivation"]=35
final_data["Deactivation_color"]="#D65654"
final_data["Plan Details"]=65
final_data["Plan Details_color"]="#F8DA77"
final_data["PORT"]=85
final_data["PORT_color"]="#4CC57E"
final_data["Signal"]=10
final_data["Signal_color"]="#D65654"
final_data["Activate"]=55
final_data["Activate_color"]="#F8DA77"
r=rh.ResponseMsg(data=final_data, error=False, msg="Process knowledge AVG Successfully GET!!!!!!!!!!!!!!!")
return Response(r.response)
class Sentimentview(APIView):
def post(self,request,format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
fields=["call start sentiment (Agent)","call end sentiment (Agent)","Overall sentiment(Agent)"]
final_data={}
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
for field in fields:
search_params["aggs"]={
"Avg_snetiment": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
final_data[field]=round(data["aggregations"]["Avg_snetiment"]["value"]*100)
color=round(data["aggregations"]["Avg_snetiment"]["value"]*100)
if color<=40:
final_data[field+"_color"]="#D65654"
elif color>40 and color<=75:
final_data[field+"_color"]="#F8DA77"
else:
final_data[field+"_color"]="#4CC57E"
r=rh.ResponseMsg(data=final_data, error=False, msg="Sentiments AVG Successfully GET!!!!!!!!!!!!!!!")
return Response(r.response)
class Salutationview(APIView):
def post(self,request,format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
call_opening_field=["Thanks for calling Matrix Solutions, How can I help you today?","Good Morning, Matrix Solutions. How can I able to help you?","Hello Matrix Solutions, I can help you with that!"]
customer_authentication_field=["Can you confirm your phone number please?","is your number 1234567890","Kindly confirm your ticket number pl?"]
on_hold_field=["Can I put you on hold while I fetch the info","Let me put you on hold while I get the needful information","Would you mind if I put you on hold to get the information"]
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
call_opening_list=[]
for field in call_opening_field:
search_params["aggs"]={
"salutation_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
call_opening_dict={}
call_opening_dict["key"]=field
call_opening_dict["value"]=round(data["aggregations"]["salutation_avg"]["value"]*100)
color=round(data["aggregations"]["salutation_avg"]["value"]*100)
if color<=40:
call_opening_dict["color"]="#D65654"
elif color>40 and color<=75:
call_opening_dict["color"]="#FFBF00"
else:
call_opening_dict["color"]="#4CC57E"
call_opening_list.append(call_opening_dict)
call_opening_dict={}
final_data["Call_Opening"]=call_opening_list
on_hold_list=[]
for field in on_hold_field:
search_params["aggs"]={
"salutation_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
on_hold_dict={}
on_hold_dict["key"]=field
on_hold_dict["value"]=round(data["aggregations"]["salutation_avg"]["value"]*100)
color=round(data["aggregations"]["salutation_avg"]["value"]*100)
if color<=40:
on_hold_dict["color"]="#D65654"
elif color>40 and color<=75:
on_hold_dict["color"]="#FFBF00"
else:
on_hold_dict["color"]="#4CC57E"
on_hold_list.append(on_hold_dict)
on_hold_dict={}
final_data["on_hold"]=on_hold_list
customer_authentication_list=[]
for field in customer_authentication_field:
search_params["aggs"]={
"salutation_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
customer_authentication_dict={}
customer_authentication_dict["key"]=field
customer_authentication_dict["value"]=round(data["aggregations"]["salutation_avg"]["value"]*100)
color=round(data["aggregations"]["salutation_avg"]["value"]*100)
if color<=40:
customer_authentication_dict["color"]="#D65654"
elif color>40 and color<=75:
customer_authentication_dict["color"]="#FFBF00"
else:
customer_authentication_dict["color"]="#4CC57E"
customer_authentication_list.append(customer_authentication_dict)
customer_authentication_dict={}
final_data["customer_authentication"]=customer_authentication_list
r=rh.ResponseMsg(data=final_data, error=False, msg="Salutation get successfully")
return Response(r.response)
class Callclosureview(APIView):
def post(self,request,format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
call_closure_field=["Thanks for calling Matrix Solutions, How can I help you today?","Good Morning, Matrix Solutions. How can I able to help you?","Hello Matrix Solutions, I can help you with that!"]
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
call_opening_list=[]
for field in call_closure_field:
search_params["aggs"]={
"callclosure_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
call_opening_dict={}
call_opening_dict["key"]=field
call_opening_dict["value"]=round(data["aggregations"]["callclosure_avg"]["value"]*100)
color=round(data["aggregations"]["callclosure_avg"]["value"]*100)
if color<=40:
call_opening_dict["color"]="#D65654"
elif color>40 and color<=75:
call_opening_dict["color"]="#F8DA77"
else:
call_opening_dict["color"]="#4CC57E"
call_opening_list.append(call_opening_dict)
call_opening_dict={}
final_data["Call_Opening"]=call_opening_list
final_data["Additional_Information"]=30
final_data["Additional_Information_color"]="#D65654"
final_data["Alternative_Channels"]=60
final_data["Alternative_Channels_color"]="#F8DA77"
final_data["Call_Summarizations"]=90
final_data["Call_Summarizations_color"]="#4CC57E"
r=rh.ResponseMsg(data=final_data, error=False, msg="Call Closure get successfully")
return Response(r.response)
class Voiceview(APIView):
def post(self,request, format=None):
lob_id=request.data.get("Lob_id")
team_id=request.data.get("Team_id")
agent_id=request.data.get("Agent_id")
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
voice_field=["overtalk incidents","Silence incidents"]
final_data={}
search_params={}
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": lob_id
}
}
team_query={
"match": {
"Team_id": team_id
}
}
agent_query={
"match": {
"Agent_id": agent_id
}
}
search_params["size"]=0
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_params["query"]=data
if(lob_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_params["query"]=data
if(team_id):
query2=team_query
data["bool"]["must"].append(query2)
search_params["query"]=data
if(agent_id):
query3=agent_query
data["bool"]["must"].append(query3)
search_params["query"]=data
search_params["size"]=0
search_params["query"]=query
for field in voice_field:
search_params["aggs"]={
"voice_avg": {
"avg": {
"field": field
}
}
}
data=es.search(index='quality_works', body=search_params)
final_data[field]=round(data["aggregations"]["voice_avg"]["value"])
r=rh.ResponseMsg(data=final_data, error=False, msg="Call Closure get successfully")
return Response(r.response)
class Allfilterview(APIView):
def post(self,request,format=None):
LOB_id=request.data.get('Lob_id')
team_list=request.data.get('Team_list')
# if team_list:
# team_list=json.loads(team_list)
agent_list=request.data.get('Agent_list')
# if agent_list:
# agent_list=json.loads(agent_list)
matrix_list=request.data.get('Matrix_list')
if matrix_list:
# matrix_list=json.loads(matrix_list)
matrix_name=Reporting.objects.filter(id__in=matrix_list)
Serializer=Reportingserializer(matrix_name, many=True)
matrix_dict=Serializer.data
start_date= request.data.get('start_date')
end_date=request.data.get('end_date')
search_param = {}
aggs_dict={
"Teams_and_lob": {
"multi_terms": {
"size": 10000,
"terms": [
{
"field": "LOB_id"
}, {
"field": "Team_id"
}
]
},
"aggs": {
"Teams_and_lob_name": {
"multi_terms": {
"size": 10000,
"terms": [
{
"field": "LOB.keyword"
}, {
"field": "Team name.keyword"
}
]
}
}
}
}
}
if (not LOB_id and team_list==None and start_date==None and end_date==None):
search_param["size"]=0
search_param["aggs"]=aggs_dict
else:
data={
"bool": {
"must": []
}
}
date_query={
"range": {
"Date of call": {
"gte": start_date,
"lte": end_date
}
}
}
lob_query= {
"match": {
"LOB_id": LOB_id
}
}
team_query={
"terms": {
"Team_id": team_list
}
}
agent_query={
"terms": {
"Agent_id": agent_list
}
}
if(start_date and end_date):
query=date_query
data["bool"]["must"].append(query)
search_param["query"]=data
search_param["aggs"]=aggs_dict
if(LOB_id):
query1=lob_query
data["bool"]["must"].append(query1)
search_param["query"]=data
search_param["aggs"]=aggs_dict
if(team_list):
query2=team_query
data["bool"]["must"].append(query2)
search_param["query"]=data
search_param["aggs"]=aggs_dict
if(agent_list):
query3=agent_query
data["bool"]["must"].append(query3)
search_param["query"]=data
search_param["aggs"]=aggs_dict
search_param["aggs"]["Teams_and_lob"]["multi_terms"]["terms"].append({
"field": "Agent_id"
})
search_param["aggs"]["Teams_and_lob"]["aggs"]["Teams_and_lob_name"]["multi_terms"]["terms"].append({
"field": "Name of associate.keyword"
})
search_param=json.dumps(search_param)
data=es.search(index='quality_works', body=search_param)
sub_list=[]
dic={}
sub_dic={}
column_list=["LOB","Team","Total Calls","CQ SCORES"]
if agent_list:
column_list=["Agent","LOB","Team","Total Calls"]
if matrix_list:
for j in matrix_dict:
dict_data=dict(j)
column_list.append(dict_data["Matrix_type"])
column_list.append("CQ SCORES")
elif matrix_list :
column_list=["LOB","Team","Total Calls"]
for j in matrix_dict:
dict_data=dict(j)
column_list.append(dict_data["Matrix_type"])
column_list.append("CQ SCORES")
for i in data["aggregations"]["Teams_and_lob"]["buckets"]:
if agent_list:
sub_dic["Agent_id"]=i["key"][2]
sub_dic["Agent"]=i["Teams_and_lob_name"]["buckets"][0]["key"][2]
sub_dic["LOB_id"]=i["key"][0]
sub_dic["LOB"]=i["Teams_and_lob_name"]["buckets"][0]["key"][0]
sub_dic["Team_id"]=i["key"][1]
sub_dic["Team"]=i["Teams_and_lob_name"]["buckets"][0]["key"][1]
sub_dic["Total Calls"]=i["doc_count"]
if matrix_list:
for j in matrix_dict:
dict_data=dict(j)
sub_dic[dict_data["Matrix_type"]]=dict_data["Weights"]
sub_dic["CQ SCORES"]=random.randint(20,200)
sub_list.append(sub_dic)
sub_dic={}
dic["att_array"]=column_list
dic["data"]=sub_list
r=rh.ResponseMsg(data=dic, error=False, msg="Filter Works Successfully!!!!!!!!!!!!!!!")
return Response(r.response)