1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/usr/bin/env python
# Copyright (C) 2012, Gustavo Duarte
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
from sugar_stats_consolidation.db import *
import sys
import logging
parser = argparse.ArgumentParser()
parser.add_argument('--query',required=True)
parser.add_argument('--start_date',required=True)
parser.add_argument('--end_date',required=True)
parser.add_argument('--db_name',required=True)
parser.add_argument('--db_user',required=True)
parser.add_argument('--db_pass',required=True)
args = parser.parse_args()
"""
_LOG_FORMAT='[%(asctime)s]-%(levelname)s-\'%(name)s\': %(message)s'
"""
_LOG_FORMAT='%(message)s'
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(_LOG_FORMAT))
log.addHandler(ch)
logging.getLogger('sugar_stats_consolidation.db').addHandler(ch)
def main():
re = DB_Stats (args.db_name, args.db_user, args.db_pass)
re.connect()
if args.query == 'activity_most_used':
activity = re.most_activity_used(args.start_date, args.end_date);
log.debug("**************************************************************************************************************")
log.debug(" Most Activity used ")
log.debug('NAME: %s', activity[0])
log.debug('PERIOD: %s-> %s', args.start_date, args.end_date)
log.debug('TIME: %.2f hrs / %.2f mins / %.2f secs', (activity[1]/60/60), (activity[1]/60), activity[1])
log.debug("***************************************************************************************************************")
if args.query == 'frequency_usage':
ts_end = long (datetime.strptime(args.end_date, "%Y-%m-%d").strftime("%s"))
ts_start = long (datetime.strptime(args.start_date, "%Y-%m-%d").strftime("%s"))
fres = re.frequency_usage(args.start_date, args.end_date);
f_x_day = (fres / ((ts_end - ts_start)/(60*60*24)))/60
f_total = (fres / 60)
log.debug("**************************************************************************************************************")
log.debug(" Fequency Usage ")
log.debug('PERIOD: %s-> %s', args.start_date, args.end_date)
log.debug('USAGE PER DAY: %.2f min / day', (f_x_day))
log.debug('USAGE TOTAL: %.2f min', (f_total))
log.debug("**************************************************************************************************************")
if __name__ == '__main__':
main()
|