Commit 300e5f4f9859e130c47befda68a0b20aa2b115de
- Diff rendering mode:
- inline
- side by side
logger.py
(2 / 5)
  | |||
3 | 3 | import config | |
4 | 4 | import datetime | |
5 | 5 | ||
6 | |||
6 | 7 | engine = sqlalchemy.create_engine(config.URI) | |
7 | 8 | metadata = sqlalchemy.MetaData(bind=engine) | |
8 | 9 | session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=engine)) | |
… | … | ||
23 | 23 | ||
24 | 24 | ||
25 | 25 | class Logger: | |
26 | def __init__(self): | ||
27 | pass | ||
28 | |||
29 | def getTable(self, tablename): | ||
26 | def __init__(self, tablename): | ||
30 | 27 | """This method loads a table from the database and maps it to LoadedTable class. | |
31 | 28 | The loaded table is available through the "lt" data member.""" | |
32 | 29 | table = sqlalchemy.Table(tablename, metadata, autoload=True) | |
33 | 30 | self.lt = tableFactory(tablename) | |
34 | 31 | sqlalchemy.orm.mapper(self.lt, table) | |
35 | return table |
report.py
(54 / 52)
  | |||
1 | import logger | ||
2 | from sqlalchemy.sql import func | ||
1 | import argparse | ||
2 | import datetime | ||
3 | import query | ||
3 | 4 | ||
5 | parser = argparse.ArgumentParser(description='Generate report for the date specified.') | ||
6 | parser.add_argument('-s','--start-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="Start date (YYYY-MM-DD)") | ||
7 | parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") | ||
8 | parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") | ||
9 | parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="Start time (HH:MM:SS)") | ||
10 | args = parser.parse_args() | ||
11 | startDate = args.start_date + " " + args.start_time | ||
12 | endDate = args.end_date + " " + args.end_time | ||
4 | 13 | ||
5 | date = raw_input("Enter the date for which you want reports?(YYYY-MM-DD)") | ||
6 | dateRange = date + " 23:59:59" | ||
7 | postings = logger.Logger() | ||
8 | postings.getTable('lb_postings') | ||
9 | print '{0}: {1}'.format("Number of postings published", | ||
10 | postings.lt.query.filter(postings.lt.status == 3, | ||
11 | postings.lt.posted.between(date, dateRange)).count()) | ||
12 | print '{0}: {1}'.format("Number of recordings made", | ||
13 | postings.lt.query.filter(postings.lt.posted.between(date, | ||
14 | dateRange)).count()) | ||
15 | print '{0}: {1}'.format("Number of impact stories", | ||
16 | postings.lt.query.filter(postings.lt.title.like('impact%'), | ||
17 | postings.lt.posted.between(date, dateRange)).count()) | ||
18 | 14 | ||
19 | callDetails = logger.Logger() | ||
20 | callDetails.getTable('cdr') | ||
21 | avg_query = callDetails.lt.query.with_entities(func.avg(callDetails.lt.duration).label('average'), | ||
22 | func.sum(callDetails.lt.duration).label('sum')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.calldate.between(date, dateRange)) | ||
23 | sumCh1_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh1')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.20%'), callDetails.lt.calldate.between(date, dateRange)) | ||
24 | sumCh2_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh2')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.21%'), callDetails.lt.calldate.between(date, dateRange)) | ||
25 | sumCh3_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh3')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.22%'), callDetails.lt.calldate.between(date, dateRange)) | ||
15 | postings = query.Query('lb_postings') | ||
16 | print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) | ||
17 | print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) | ||
18 | print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) | ||
26 | 19 | ||
27 | average = 0 | ||
28 | sum = 0 | ||
29 | sumCh1 = 0 | ||
30 | sumCh2 = 0 | ||
31 | sumCh3 = 0 | ||
32 | for res in sumCh1_query.all(): | ||
33 | sumCh1 = res.sumCh1/60 | ||
20 | callDetails = query.Query('cdr') | ||
21 | average_call_length = callDetails.average(startDate, endDate) | ||
22 | audio_minutes = callDetails.sum(startDate, endDate) | ||
23 | channel1_minutes = callDetails.load('SIP/10.0.0.20', startDate, endDate) | ||
24 | channel2_minutes = callDetails.load('SIP/10.0.0.21', startDate, endDate) | ||
25 | channel3_minutes = callDetails.load('SIP/10.0.0.22', startDate, endDate) | ||
34 | 26 | ||
35 | for res in sumCh2_query.all(): | ||
36 | sumCh2 = res.sumCh2/60 | ||
37 | 27 | ||
38 | for res in sumCh3_query.all(): | ||
39 | sumCh3 = res.sumCh3/60 | ||
28 | # avg_query = callDetails.lt.query.with_entities(func.avg(callDetails.lt.duration).label('average'), | ||
29 | # func.sum(callDetails.lt.duration).label('sum')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.calldate.between(date, dateRange)) | ||
30 | # sumCh1_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh1')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.20%'), callDetails.lt.calldate.between(date, dateRange)) | ||
31 | # sumCh2_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh2')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.21%'), callDetails.lt.calldate.between(date, dateRange)) | ||
32 | # sumCh3_query = callDetails.lt.query.with_entities(func.sum(callDetails.lt.duration).label('sumCh3')).filter(callDetails.lt.dcontext == "callback", callDetails.lt.channel.like('SIP/10.0.0.22%'), callDetails.lt.calldate.between(date, dateRange)) | ||
40 | 33 | ||
41 | for res in avg_query.all(): | ||
42 | average = res.average/60 #The duration recorded is in seconds, convert it to | ||
43 | #minutes | ||
44 | sum = res.sum/60 | ||
34 | # average = 0 | ||
35 | # sum = 0 | ||
36 | # sumCh1 = 0 | ||
37 | # sumCh2 = 0 | ||
38 | # sumCh3 = 0 | ||
39 | # for res in sumCh1_query.all(): | ||
40 | # sumCh1 = res.sumCh1/60 | ||
45 | 41 | ||
46 | print '{0}: {1}'.format("Number of missed calls", | ||
47 | callDetails.lt.query.filter(((callDetails.lt.dcontext == 'mobilink') | | ||
48 | (callDetails.lt.dcontext == 'mobilinktata')) & | ||
49 | (callDetails.lt.calldate.between(date, dateRange))).count()) | ||
50 | print '{0}: {1}'.format("Number of calls answered", | ||
51 | callDetails.lt.query.filter(callDetails.lt.dcontext == 'callback', | ||
52 | callDetails.lt.calldate.between(date, dateRange)).count()) | ||
53 | print '{0}: {1}'.format("Average length of calls", average) | ||
54 | print '{0}: {1}'.format("Total number of audio minutes played", sum) | ||
55 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.20", sumCh1) | ||
56 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.21", sumCh2) | ||
57 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", sumCh3) | ||
58 | print '{0}: {1}'.format("Load on channel 10.0.0.20", sumCh1/sum) | ||
59 | print '{0}: {1}'.format("Load on channel 10.0.0.21", sumCh2/sum) | ||
60 | print '{0}: {1}'.format("Load on channel 10.0.0.22", sumCh3/sum) | ||
42 | # for res in sumCh2_query.all(): | ||
43 | # sumCh2 = res.sumCh2/60 | ||
44 | |||
45 | # for res in sumCh3_query.all(): | ||
46 | # sumCh3 = res.sumCh3/60 | ||
47 | |||
48 | # for res in avg_query.all(): | ||
49 | # average = res.average/60 #The duration recorded is in seconds, convert it to | ||
50 | # #minutes | ||
51 | # sum = res.sum/60 | ||
52 | |||
53 | print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) | ||
54 | print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) | ||
55 | print '{0}: {1}'.format("Average length of calls", average_call_length) | ||
56 | print '{0}: {1}'.format("Total number of audio minutes played", audio_minutes) | ||
57 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) | ||
58 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) | ||
59 | print '{0}: {1}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) | ||
60 | print '{0}: {1}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) | ||
61 | print '{0}: {1}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) | ||
62 | print '{0}: {1}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) |