Commit d48d677892ecf54454fa509f929899ab436a5df2

  • avatar
  • arvind
  • Wed Jan 15 18:23:03 IST 2014
Refactoring code, genReport() returns a string of the report, easy to feed to
mail or to stdout.
Updating .gitignore
.gitignore
(2 / 0)
  
1111
1212#Ignore config file
1313config.py
14mailConfig.py
15*.sql
report.py
(55 / 26)
  
33import query
44import gmail
55import mailConfig
6
6from string import Template
77parser = argparse.ArgumentParser(description="""Generate report for the date specified.
88 Start and end date default to present day.
99 Start time defaults to 00:00:00.
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"])
5633
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"])
34def genReport():
5935
36 posts = '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate))
37
38 recordings = '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate))
39
40 impact_stories = '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate))
41
42 missed_calls = '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate))
43
44 missed_calls_mobilink = '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink'))
45
46 missed_calls_mobilink_tata = '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate,'mobilinktata'))
47
48 answered_calls = '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate))
49
50 filtered_calls = '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30))
51
52 average_Call_Length = '{0}: {1:.4f}'.format("Average length of calls", average_call_length)
53
54 audio_Minutes = '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes)
55
56 ch1_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes)
57
58 ch2_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes)
59
60 ch3_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes)
61
62 ch1_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes)
63
64 ch2_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes)
65
66 ch3_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes)
67
68 mobilink_max_load = '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"])
69
70 mobilink_max_calls = '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"])
71
72 mobilink_min_load = '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"])
73
74 mobilink_tata_max_load = '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"])
75
76 mobilink_tata_max_calls = '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"])
77
78 mobilink_tata_min_load = '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"])
79
80 t =Template('$posts\n$recordings\n$impact_stories\n$missed_calls\n$missed_calls_mobilink\n$missed_calls_mobilink_tata\n$answered_calls\n$filtered_calls\n$average_call_length\n$audio_minutes\n$ch1_minutes\n$ch2_minutes\n$ch3_minutes\n$ch1_load\n$ch2_load\n$ch3_load\n$mobilink_max_load\n$mobilink_max_calls\n$mobilink_min_load\n$mobilink_tata_max_load\n$mobilink_tata_max_calls\n$mobilink_tata_min_load')
81 report = t.substitute(posts=posts,recordings=recordings,impact_stories=impact_stories,missed_calls=missed_calls,missed_calls_mobilink=missed_calls_mobilink,missed_calls_mobilink_tata=missed_calls_mobilink_tata,answered_calls=answered_calls,filtered_calls=filtered_calls,average_call_length=average_Call_Length,audio_minutes=audio_Minutes,ch1_minutes=ch1_minutes,ch2_minutes=ch2_minutes,ch3_minutes=ch3_minutes,ch1_load=ch1_load,ch2_load=ch2_load,ch3_load=ch3_load,mobilink_max_load=mobilink_max_load,mobilink_max_calls=mobilink_max_calls,mobilink_min_load=mobilink_min_load,mobilink_tata_max_load=mobilink_tata_max_load,mobilink_tata_max_calls=mobilink_tata_max_calls,mobilink_tata_min_load=mobilink_tata_min_load)
82 return report
83
84if args.mail is False:
85 report = genReport()
86 print report
87else:
88 report = genReport()
6089 subject = mailConfig.subject.format(startDate, endDate)
6190 report = mailConfig.text.format(startDate, endDate) + '\n' + report
6291 mail = gmail.GMail(mailConfig.username, mailConfig.password)