Commit cad2a999d502711b28acc26fe99bd4cea800aae6

  • avatar
  • arvind
  • Tue Jan 14 20:12:36 IST 2014
Feature addition
    - reporter.py can now send mails, set --mail True and specifiy recipients in
    mailConfig.py as "foo@bar.org, rajesh@email.in"
report.py
(34 / 24)
  
11import argparse
22import datetime
33import query
4import gmail
5import mailConfig
46
57parser = argparse.ArgumentParser(description="""Generate report for the date specified.
68 Start and end date default to present day.
1212parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)")
1313parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)")
1414parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="End time (HH:MM:SS)")
15parser.add_argument('-p','--print', type=bool, default=True, help="Print report on command line")
16parser.add_argument('-m','--mail', type=bool, default=False, help="Mail report to addressess in mailConfig.py")
1517
1618
1719args = parser.parse_args()
1820startDate = args.start_date + " " + args.start_time
1921endDate = args.end_date + " " + args.end_time
2022
21
2223postings = query.Query('lb_postings')
23print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate))
24print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate))
25print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate))
26
2724callDetails = query.Query('cdr')
2825average_call_length = callDetails.average(startDate, endDate)
2926audio_minutes = callDetails.sum(startDate, endDate)
3030mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink')
3131mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata')
3232
33if 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"])
3356
34print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate))
35print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink'))
36print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata'))
37print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate))
38print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30))
39print '{0}: {1:.4f}'.format("Average length of calls", average_call_length)
40print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes)
41print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes)
42print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes)
43print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes)
44print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes)
45print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes)
46print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)
47print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"])
48print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"])
49print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"])
50print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"])
51print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"])
52print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"])
57else:
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)