Commit cad2a999d502711b28acc26fe99bd4cea800aae6
- Diff rendering mode:
- inline
- side by side
report.py
(34 / 24)
  | |||
1 | 1 | import argparse | |
2 | 2 | import datetime | |
3 | 3 | import query | |
4 | import gmail | ||
5 | import mailConfig | ||
4 | 6 | ||
5 | 7 | parser = argparse.ArgumentParser(description="""Generate report for the date specified. | |
6 | 8 | Start and end date default to present day. | |
… | … | ||
12 | 12 | parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") | |
13 | 13 | parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") | |
14 | 14 | parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="End time (HH:MM:SS)") | |
15 | parser.add_argument('-p','--print', type=bool, default=True, help="Print report on command line") | ||
16 | parser.add_argument('-m','--mail', type=bool, default=False, help="Mail report to addressess in mailConfig.py") | ||
15 | 17 | ||
16 | 18 | ||
17 | 19 | args = parser.parse_args() | |
18 | 20 | startDate = args.start_date + " " + args.start_time | |
19 | 21 | endDate = args.end_date + " " + args.end_time | |
20 | 22 | ||
21 | |||
22 | 23 | postings = query.Query('lb_postings') | |
23 | print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) | ||
24 | print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) | ||
25 | print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) | ||
26 | |||
27 | 24 | callDetails = query.Query('cdr') | |
28 | 25 | average_call_length = callDetails.average(startDate, endDate) | |
29 | 26 | audio_minutes = callDetails.sum(startDate, endDate) | |
… | … | ||
30 | 30 | mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink') | |
31 | 31 | mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata') | |
32 | 32 | ||
33 | if args.mail is False: | ||
34 | print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) | ||
35 | print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) | ||
36 | print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) | ||
37 | print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) | ||
38 | print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) | ||
39 | print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) | ||
40 | print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) | ||
41 | print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) | ||
42 | print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) | ||
43 | print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) | ||
44 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) | ||
45 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) | ||
46 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) | ||
47 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) | ||
48 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) | ||
49 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) | ||
50 | print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) | ||
51 | print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) | ||
52 | print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) | ||
53 | print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) | ||
54 | print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) | ||
55 | print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) | ||
33 | 56 | ||
34 | print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) | ||
35 | print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) | ||
36 | print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) | ||
37 | print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) | ||
38 | print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) | ||
39 | print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) | ||
40 | print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) | ||
41 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) | ||
42 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) | ||
43 | print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) | ||
44 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) | ||
45 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) | ||
46 | print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) | ||
47 | print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) | ||
48 | print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) | ||
49 | print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) | ||
50 | print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) | ||
51 | print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) | ||
52 | print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) | ||
57 | else: | ||
58 | report = '{0}: {1}\n'.format("Number of postings published", postings.posts(startDate, endDate)) + '{0}: {1}\n'.format("Number of recordings made", postings.recordings(startDate, endDate)) + '{0}: {1}\n'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) + '{0}: {1}\n'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) + '{0}: {1}\n'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) + '{0}: {1}\n'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) + '{0}: {1}\n'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) + '{0}: {1}\n'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) + '{0}: {1:.4f}\n'.format("Average length of calls", average_call_length) + '{0}: {1:.4f}\n'.format("Total number of audio minutes played", audio_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) + '{0}: {1}\n'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) + '{0}: {1}\n'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) + '{0}: {1}\n'.format("Least active hour for mobilink",mobilink_load["minLoad"]) + '{0}: {1}\n'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) + '{0}: {1}\n'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) + '{0}: {1}\n'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) | ||
59 | |||
60 | |||
61 | mail = gmail.GMail(mailConfig.username, mailConfig.password) | ||
62 | message = gmail.Message(mailConfig.subject, mailConfig.to, text=report) | ||
63 | mail.send(message) |