From 9d54d1e44c93e7859f9b267221931dc6b2865aae Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 9 Jan 2014 20:51:20 +0530 Subject: [PATCH] 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 --- query.py | 12 +++++++++--- report.py | 45 +++++++++++++-------------------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/query.py b/query.py index f86543c..0d61283 100644 --- a/query.py +++ b/query.py @@ -40,11 +40,17 @@ class Query: 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() \ No newline at end of file + 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() \ No newline at end of file diff --git a/report.py b/report.py index b819297..ce9c3de 100644 --- a/report.py +++ b/report.py @@ -7,6 +7,8 @@ parser.add_argument('-s','--start-date', type=str, default=datetime.datetime.str 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,38 +27,17 @@ channel2_minutes = callDetails.load('SIP/10.0.0.21', startDate, endDate) 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) -- 1.7.10.4