--- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ #Ignore config file config.py +mailConfig.py +*.sql --- a/report.py +++ b/report.py @@ -3,7 +3,7 @@ import query import gmail import mailConfig - +from string import Template parser = argparse.ArgumentParser(description="""Generate report for the date specified. Start and end date default to present day. Start time defaults to 00:00:00. @@ -30,33 +30,62 @@ mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink') mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata') -if args.mail is False: - print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) - print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) - print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) - print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) - print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) - print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) - print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) - print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) - print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) - print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) - print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) - print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) - print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) - print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) - print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) - print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) - print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) - print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) - print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) - print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) - print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) - print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) -else: - 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"]) +def genReport(): + posts = '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) + + recordings = '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) + + impact_stories = '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) + + missed_calls = '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) + + missed_calls_mobilink = '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) + + missed_calls_mobilink_tata = '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate,'mobilinktata')) + + answered_calls = '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) + + filtered_calls = '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) + + average_Call_Length = '{0}: {1:.4f}'.format("Average length of calls", average_call_length) + + audio_Minutes = '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) + + ch1_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) + + ch2_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) + + ch3_minutes = '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) + + ch1_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) + + ch2_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) + + ch3_load = '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) + + mobilink_max_load = '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) + + mobilink_max_calls = '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) + + mobilink_min_load = '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) + + mobilink_tata_max_load = '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) + + mobilink_tata_max_calls = '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) + + mobilink_tata_min_load = '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) + + 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') + 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) + return report + +if args.mail is False: + report = genReport() + print report +else: + report = genReport() subject = mailConfig.subject.format(startDate, endDate) report = mailConfig.text.format(startDate, endDate) + '\n' + report mail = gmail.GMail(mailConfig.username, mailConfig.password)