300e5f4 by Arvind at 2014-01-09 1
import argparse
2
import datetime
3
import query
4
200085d by Arvind at 2014-01-09 5
parser = argparse.ArgumentParser(description="""Generate report for the date specified.
6
                                 Start and end date default to present day.
7
                                 Start time defaults to 00:00:00.
8
                                 End time defaults to 23:59:59.""")
300e5f4 by Arvind at 2014-01-09 9
parser.add_argument('-s','--start-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="Start date (YYYY-MM-DD)")
10
parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)")
11
parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)")
200085d by Arvind at 2014-01-09 12
parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="End time (HH:MM:SS)")
9d54d1e by Arvind at 2014-01-09 13
14
300e5f4 by Arvind at 2014-01-09 15
args = parser.parse_args()
16
startDate = args.start_date + " " + args.start_time
17
endDate = args.end_date + " " + args.end_time
18
19
20
postings = query.Query('lb_postings')
21
print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate))
22
print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate))
23
print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate))
24
25
callDetails = query.Query('cdr')
26
average_call_length = callDetails.average(startDate, endDate)
27
audio_minutes = callDetails.sum(startDate, endDate)
28
channel1_minutes = callDetails.load('SIP/10.0.0.20', startDate, endDate)
29
channel2_minutes = callDetails.load('SIP/10.0.0.21', startDate, endDate)
30
channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate)
2e37597 by Arvind at 2014-01-14 31
mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink')
32
mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata')
300e5f4 by Arvind at 2014-01-09 33
34
35
print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate))
9d54d1e by Arvind at 2014-01-09 36
print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink'))
37
print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata'))
300e5f4 by Arvind at 2014-01-09 38
print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate))
9d54d1e by Arvind at 2014-01-09 39
print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30))
40
print '{0}: {1:.4f}'.format("Average length of calls", average_call_length)
41
print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes)
42
print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes)
43
print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes)
44
print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes)
45
print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes)
46
print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes)
47
print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)
2e37597 by Arvind at 2014-01-14 48
print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"])
49
print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"])
50
print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"])
51
print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"])
52
print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"])
53
print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"])