Commit 9d54d1e44c93e7859f9b267221931dc6b2865aae
Added new queries
- Added query to count calls less than a specified duration
- Modified the query for missed calls to return count for a specific modem, if provided
| | | | 40 | sum = res.sum/60 | 40 | sum = res.sum/60 |
---|
41 | return sum | 41 | return sum |
---|
42 | | 42 | |
---|
43 | def missedCalls(self, date, dateRange): | | def missedCalls(self, date, dateRange): |
---|
44 | return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') | | | return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') | |
---|
| | 43 | def missedCalls(self, date, dateRange, modem=None): | | | 44 | if modem is None: |
---|
| | 45 | return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') | |
---|
45 | (self.t.lt.dcontext == 'mobilinktata')) & | 46 | (self.t.lt.dcontext == 'mobilinktata')) & |
---|
46 | (self.t.lt.calldate.between(date, dateRange))).count() | 47 | (self.t.lt.calldate.between(date, dateRange))).count() |
---|
| | 48 | else: |
---|
| | 49 | return self.t.lt.query.filter(self.t.lt.dcontext == modem, self.t.lt.calldate.between(date, dateRange)).count() |
---|
47 | | 50 | |
---|
48 | def answeredCalls(self, date, dateRange): | 51 | def answeredCalls(self, date, dateRange): |
---|
49 | return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', | 52 | return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', |
---|
50 | self.t.lt.calldate.between(date, dateRange)).count() | 53 | self.t.lt.calldate.between(date, dateRange)).count() |
---|
| | 54 | |
---|
| | 55 | def filter_calls_by_duration(self, date, dateRange, duration): |
---|
| | 56 | return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', self.t.lt.duration < duration, self.t.lt.calldate.between(date, dateRange)).count() |
---|
| | | | 7 | parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") | 7 | parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") |
---|
8 | parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") | 8 | parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") |
---|
9 | parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)") | 9 | parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)") |
---|
| | 10 | |
---|
| | 11 | |
---|
10 | args = parser.parse_args() | 12 | args = parser.parse_args() |
---|
11 | startDate = args.start_date + " " + args.start_time | 13 | startDate = args.start_date + " " + args.start_time |
---|
12 | endDate = args.end_date + " " + args.end_time | 14 | endDate = args.end_date + " " + args.end_time |
---|
… | | … | |
---|
27 | channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate) | 27 | channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate) |
---|
28 | | 28 | |
---|
29 | | 29 | |
---|
30 | # avg_query = callDetails.lt.query.with_entities(func.avg(callDetails.lt.duration).label('average'), | | # avg_query = callDetails.lt.query.with_entities(func.avg(callDetails.lt.duration).label('average'), |
---|
31 | # func.sum(callDetails.lt.duration).label('sum')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.calldate.between(date, dateRange)) | | # func.sum(callDetails.lt.duration).label('sum')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.calldate.between(date, dateRange)) |
---|
32 | # sumCh1_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh1')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.20%'), callDetails.lt.calldate.between(date, dateRange)) | | # sumCh1_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh1')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.20%'), callDetails.lt.calldate.between(date, dateRange)) |
---|
33 | # sumCh2_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh2')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.21%'), callDetails.lt.calldate.between(date, dateRange)) | | # sumCh2_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh2')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.21%'), callDetails.lt.calldate.between(date, dateRange)) |
---|
34 | # sumCh3_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh3')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.22%'), callDetails.lt.calldate.between(date, dateRange)) | | # sumCh3_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh3')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.22%'), callDetails.lt.calldate.between(date, dateRange)) |
---|
35 | | 30 | |
---|
36 | # average = 0 | | # average = 0 |
---|
37 | # sum = 0 | | # sum = 0 |
---|
38 | # sumCh1 = 0 | | # sumCh1 = 0 |
---|
39 | # sumCh2 = 0 | | # sumCh2 = 0 |
---|
40 | # sumCh3 = 0 | | # sumCh3 = 0 |
---|
41 | # for res in sumCh1_query.all(): | | # for res in sumCh1_query.all(): |
---|
42 | # sumCh1 = res.sumCh1/60 | | # sumCh1 = res.sumCh1/60 |
---|
43 | | | |
---|
44 | # for res in sumCh2_query.all(): | | # for res in sumCh2_query.all(): |
---|
45 | # sumCh2 = res.sumCh2/60 | | # sumCh2 = res.sumCh2/60 |
---|
46 | | | |
---|
47 | # for res in sumCh3_query.all(): | | # for res in sumCh3_query.all(): |
---|
48 | # sumCh3 = res.sumCh3/60 | | # sumCh3 = res.sumCh3/60 |
---|
49 | | | |
---|
50 | # for res in avg_query.all(): | | # for res in avg_query.all(): |
---|
51 | # average = res.average/60 #The duration recorded is in seconds, convert it to | | # average = res.average/60 #The duration recorded is in seconds, convert it to |
---|
52 | # #minutes | | # #minutes |
---|
53 | # sum = res.sum/60 | | # sum = res.sum/60 |
---|
54 | | | |
---|
55 | print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) | 31 | print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) |
---|
| | 32 | print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) |
---|
| | 33 | print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) |
---|
56 | print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) | 34 | print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) |
---|
57 | print '{0}: {1}'.format("Average length of calls", average_call_length) | | print '{0}: {1}'.format("Average length of calls", average_call_length) |
---|
58 | print '{0}: {1}'.format("Total number of audio minutes played", audio_minutes) | | print '{0}: {1}'.format("Total number of audio minutes played", audio_minutes) |
---|
59 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) | | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) |
---|
60 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) | | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) |
---|
61 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) | | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) |
---|
62 | print '{0}: {1}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) | | print '{0}: {1}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) |
---|
63 | print '{0}: {1}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) | | print '{0}: {1}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) |
---|
64 | print '{0}: {1}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) | | print '{0}: {1}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) |
---|
| | 35 | print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) | | | 36 | print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) |
---|
| | 37 | print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) |
---|
| | 38 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) |
---|
| | 39 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) |
---|
| | 40 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) |
---|
| | 41 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) |
---|
| | 42 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) |
---|
| | 43 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) |
---|