Commit 9d54d1e44c93e7859f9b267221931dc6b2865aae

  • avatar
  • arvind
  • Thu Jan 09 20:51:20 IST 2014
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 --------------------------------+++++++++++++
  • Diff rendering mode:
  • inline
  • side by side

query.py

40 sum = res.sum/6040 sum = res.sum/60
41 return sum41 return sum
4242
43 def missedCalls(self, date, dateRange):
44 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()
4750
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()

report.py

7parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)")7parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)")
8parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)")8parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)")
9parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)")9parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)")
10
11
10args = parser.parse_args()12args = parser.parse_args()
11startDate = args.start_date + " " + args.start_time13startDate = args.start_date + " " + args.start_time
12endDate = args.end_date + " " + args.end_time14endDate = args.end_date + " " + args.end_time
27channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate)27channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate)
2828
2929
30# 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))
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))
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))
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))
3530
36# average = 0
37# sum = 0
38# sumCh1 = 0
39# sumCh2 = 0
40# sumCh3 = 0
41# for res in sumCh1_query.all():
42# sumCh1 = res.sumCh1/60
43
44# for res in sumCh2_query.all():
45# sumCh2 = res.sumCh2/60
46
47# for res in sumCh3_query.all():
48# sumCh3 = res.sumCh3/60
49
50# for res in avg_query.all():
51# average = res.average/60 #The duration recorded is in seconds, convert it to
52# #minutes
53# sum = res.sum/60
54
55print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate))31print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate))
32print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink'))
33print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata'))
56print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate))34print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate))
57print '{0}: {1}'.format("Average length of calls", average_call_length)
58print '{0}: {1}'.format("Total number of audio minutes played", audio_minutes)
59print '{0}: {1}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes)
60print '{0}: {1}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes)
61print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes)
62print '{0}: {1}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes)
63print '{0}: {1}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes)
64print '{0}: {1}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)
35print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30))
36print '{0}: {1:.4f}'.format("Average length of calls", average_call_length)
37print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes)
38print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes)
39print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes)
40print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes)
41print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes)
42print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes)
43print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)