--- a/query.py +++ b/query.py @@ -40,12 +40,18 @@ sum = res.sum/60 return sum - def missedCalls(self, date, dateRange): - return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') | + def missedCalls(self, date, dateRange, modem=None): + if modem is None: + return self.t.lt.query.filter(((self.t.lt.dcontext == 'mobilink') | (self.t.lt.dcontext == 'mobilinktata')) & (self.t.lt.calldate.between(date, dateRange))).count() + else: + return self.t.lt.query.filter(self.t.lt.dcontext == modem, self.t.lt.calldate.between(date, dateRange)).count() def answeredCalls(self, date, dateRange): return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', self.t.lt.calldate.between(date, dateRange)).count() + + def filter_calls_by_duration(self, date, dateRange, duration): + return self.t.lt.query.filter(self.t.lt.dcontext == 'callback', self.t.lt.duration < duration, self.t.lt.calldate.between(date, dateRange)).count() --- a/report.py +++ b/report.py @@ -7,6 +7,8 @@ parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)") + + args = parser.parse_args() startDate = args.start_date + " " + args.start_time endDate = args.end_date + " " + args.end_time @@ -25,39 +27,18 @@ channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate) -# avg_query = callDetails.lt.query.with_entities(func.avg(callDetails.lt.duration).label('average'), -# func.sum(callDetails.lt.duration).label('sum')).filter(callDetails.lt.dcontext == "callback", 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)) -# 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)) -# 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)) -# average = 0 -# sum = 0 -# sumCh1 = 0 -# sumCh2 = 0 -# sumCh3 = 0 -# for res in sumCh1_query.all(): -# sumCh1 = res.sumCh1/60 - -# for res in sumCh2_query.all(): -# sumCh2 = res.sumCh2/60 - -# for res in sumCh3_query.all(): -# sumCh3 = res.sumCh3/60 - -# for res in avg_query.all(): -# average = res.average/60 #The duration recorded is in seconds, convert it to -# #minutes -# sum = res.sum/60 - print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) +print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) +print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) -print '{0}: {1}'.format("Average length of calls", average_call_length) -print '{0}: {1}'.format("Total number of audio minutes played", audio_minutes) -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.21", channel2_minutes) -print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) -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.21", channel2_minutes/audio_minutes) -print '{0}: {1}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) +print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) +print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) +print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) +print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) +print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) +print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) +print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) +print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) +print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)