Commit db3c81d76337f9a49a88265f2da2b42594cc2712

  • avatar
  • arvind
  • Tue Mar 11 21:07:37 IST 2014
Readability counts.
Breaking lines longer than 80.
Minutes of a call should be counted after the user has answered the call
not since the call has been started. This value is stored in the billsec
column of cdr table.
Answered calls should be counted when there is a disposition of
answered, likewise for unanswered calls.
Count number of calls which went unaccounted for, as in failed/busy/no
answer with dcontext as default.
query.py
(61 / 21)
  
2121 self.t.lt.posted.between(date, dateRange)).count()
2222
2323
24 def totalMinutes(self, channel, date, dateRange):
25 query = self.t.lt.query.with_entities(func.sum(self.t.lt.duration).label('sum')).filter(self.t.lt.dcontext == "callback", self.t.lt.channel.like(channel+'%'), self.t.lt.calldate.between(date, dateRange))
24 def totalMinutes(self, date, dateRange, channel=None):
25 query = self.t.lt.query.with_entities(
26 func.sum(self.t.lt.billsec).label('sum')).filter(
27 self.t.lt.dcontext == "callback",
28 self.t.lt.disposition == "ANSWERED",
29 self.t.lt.calldate.between(date, dateRange))
30
31 if channel is not None:
32 query = query.filter(self.t.lt.channel.like(channel+'%'))
33
2634 sum = 0
2735 for res in query:
2836 if res.sum is not None:
3939
4040
4141 def average(self, date, dateRange):
42 query = self.t.lt.query.with_entities(func.avg(self.t.lt.duration).label('average')).filter(self.t.lt.dcontext == "callback", self.t.lt.calldate.between(date, dateRange))
42 query = self.t.lt.query.with_entities(
43 func.avg(self.t.lt.billsec).label('average')).filter(
44 self.t.lt.dcontext == "callback",
45 self.t.lt.disposition == "ANSWERED",
46 self.t.lt.calldate.between(date, dateRange))
47
4348 average = 0
4449 for res in query:
4550 if res.average is not None:
4651 average = res.average/60
4752 return round(average, 4)
4853
49 def sum(self, date, dateRange):
50 query = self.t.lt.query.with_entities(func.sum(self.t.lt.duration).label('sum')).filter(self.t.lt.dcontext == "callback", self.t.lt.calldate.between(date, dateRange))
51 sum = 0
52 for res in query:
53 if res.sum is not None:
54 sum = res.sum/60
55 return round(sum, 4)
54 # def sum(self, date, dateRange):
55 # query = self.t.lt.query.with_entities(
56 # func.sum(self.t.lt.billsec).label('sum')).filter(
57 # self.t.lt.dcontext == "callback",
58 # self.t.lt.disposition == "ANSWERED",
59 # self.t.lt.calldate.between(date, dateRange))
60 # sum = 0
61 # for res in query:
62 # if res.sum is not None:
63 # sum = res.sum/60
64 # return round(sum, 4)
5665
5766
5867 def missedCalls(self, date, dateRange, modem=None):
5968 if modem is None:
6069 return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') |
61 (self.t.lt.dcontext == 'mobilinktata')) &
62 (self.t.lt.calldate.between(date, dateRange))).count()
70 (self.t.lt.dcontext ==
71 'mobilinktata')) &
72 (self.t.lt.calldate.between(date,
73 dateRange))).count()
6374 else:
64 return self.t.lt.query.filter(self.t.lt.dcontext == modem, self.t.lt.calldate.between(date, dateRange)).count()
75 return self.t.lt.query.filter(self.t.lt.dcontext == modem,
76 self.t.lt.calldate.between(date,
77 dateRange)).count()
6578
6679
80 def unAccountedCalls(self, date, dateRange):
81 return self.t.lt.query.filter(self.t.lt.dcontext == 'default',
82 self.t.lt.calldate.between(date,
83 dateRange)).count()
84
85
6786 def answeredCalls(self, date, dateRange):
6887 return self.t.lt.query.filter(self.t.lt.dcontext == 'callback',
69 self.t.lt.calldate.between(date, dateRange)).count()
88 self.t.lt.disposition == 'ANSWERED',
89 self.t.lt.calldate.between(date,
90 dateRange)).count()
7091
7192
72 def filter_calls_by_duration(self, date, dateRange, duration):
73 return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', self.t.lt.duration < duration, self.t.lt.calldate.between(date, dateRange)).count()
93 def filter_calls_by_duration(self, date, dateRange, billsec):
94 return self.t.lt.query.filter(
95 self.t.lt.dcontext == 'callback', self.t.lt.billsec < billsec,
96 self.t.lt.calldate.between(date, dateRange)).count()
7497
7598
7699 def call_distribution(self, date, dateRange, dcontext):
77100 startTimeStamp = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
78101 endTimeStamp = datetime.datetime.strptime(dateRange, '%Y-%m-%d %H:%M:%S')
79 result = self.t.lt.query.filter(self.t.lt.dcontext == dcontext, self.t.lt.calldate.between(date, dateRange))
102 result = self.t.lt.query.filter(
103 self.t.lt.dcontext == dcontext, self.t.lt.calldate.between(date, dateRange))
80104 slots = {}
81105 while(startTimeStamp - endTimeStamp <= datetime.timedelta(0)):
82106 date1 = startTimeStamp
83107 date2 = startTimeStamp + datetime.timedelta(seconds=3600)
84108 startTimeStamp = date2
85109 if slots.has_key('{0}-{1}'.format(date1.strftime('%H'), date2.strftime('%H'))):
86 slots['{0}-{1}'.format(date1.strftime('%H'), date2.strftime('%H'))] += result.filter(self.t.lt.calldate.between(date1, date2)).count()
110 slots['{0}-{1}'.format(date1.strftime('%H'),
111 date2.strftime('%H'))] += result.filter(
112 self.t.lt.calldate.between(date1, date2)).count()
87113 else:
88 slots['{0}-{1}'.format(date1.strftime('%H'), date2.strftime('%H'))] = result.filter(self.t.lt.calldate.between(date1, date2)).count()
114 slots['{0}-{1}'.format(date1.strftime('%H'),
115 date2.strftime('%H'))] = result.filter(
116 self.t.lt.calldate.between(date1, date2)).count()
89117
90118 maxLoad = max(slots, key = lambda x: slots.get(x) )
91119 minLoad = []
124124
125125
126126 def calls_unanswered(self, date, dateRange):
127 return self.t.lt.query.filter(self.t.lt.dcontext=='default', self.t.lt.calldate.between(date,dateRange)).count()
127 return self.t.lt.query.filter(self.t.lt.disposition == 'NO ANSWER',
128 self.t.lt.dcontext == 'callback',
129 self.t.lt.calldate.between(date,dateRange)).count()
128130
129131
130132 def max_duration_UC(self, date, dateRange):
131 query = self.t.lt.query.with_entities(func.max(self.t.lt.duration).label('duration')).filter(self.t.lt.dcontext=='default', self.t.lt.calldate.between(date,dateRange))
133 query = self.t.lt.query.with_entities(
134 func.max(self.t.lt.duration).label('duration')).filter(
135 self.t.lt.dcontext=='default', self.t.lt.calldate.between(date,dateRange))
132136 duration = 0
133137 for result in query:
134138 if result.duration is not None:
report.py
(5 / 3)
  
2525postings = query.Query('lb_postings')
2626callDetails = query.Query('cdr')
2727average_call_length = callDetails.average(startDate, endDate)
28audio_minutes = callDetails.sum(startDate, endDate)
28audio_minutes = callDetails.totalMinutes(startDate, endDate)
2929mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink')
3030mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata')
3131
3737 """
3838 minutes = {}
3939 for ip in conf.ip_addr:
40 minutes[ip] = callDetails.totalMinutes(ip, startDate, endDate)
40 minutes[ip] = callDetails.totalMinutes(startDate, endDate, ip)
4141 return minutes
4242
4343def individual_load():
9898 callDetails.calls_unanswered(startDate, endDate),
9999
100100 "Maximum_duration_of_unanswered_call":
101 callDetails.max_duration_UC(startDate, endDate)
101 callDetails.max_duration_UC(startDate, endDate),
102
103 "Number of calls failed permanently": callDetails.unAccountedCalls(startDate, endDate)
102104 })
103105
104106def genReport():