Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sql/make_report
blob: f09b40be630384c469f6d38eab73f7b68f5ed063 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/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 activity_most_used(re, start, end):
	activity = re.most_activity_used(start, end);
	log.debug("**************************************************************************************************************")
	log.debug("                                     Most Activity used                                                       ")
	log.debug('NAME:     %s', activity[0])
	log.debug('INTERVAL: %s-> %s', start, end)
	log.debug('TIME:     %.2f hrs / %.2f mins / %.2f secs', (activity[1]/60/60), (activity[1]/60), activity[1])
	log.debug("***************************************************************************************************************")

def frequency_usage(re, start, end):
	ts_end   = long (datetime.strptime(end, "%Y-%m-%d").strftime("%s"))
	ts_start = long (datetime.strptime(start, "%Y-%m-%d").strftime("%s"))

	fres = re.frequency_usage(start, end);
	f_x_day = (fres / ((ts_end - ts_start)/(60*60*24)))/60
	f_total = (fres / 60)
	log.debug("**************************************************************************************************************")
	log.debug("                                     Fequency Usage                                                           ")
	log.debug('INTERVAL: %s-> %s', start, end)
	log.debug('PER DAY:  %.2f min / day', (f_x_day))
	log.debug('TOTAL:    %.2f min', (f_total))
	log.debug("**************************************************************************************************************")



def main():
	re = DB_Stats (args.db_name, args.db_user, args.db_pass)
	re.connect()
	
	if args.query == 'activity_most_used':
		activity_most_used(re, args.start_date, args.end_date);
	elif args.query == 'frequency_usage':
		frequency_usage(re, args.start_date, args.end_date)
	elif args.query == 'all':
		activity_most_used(re, args.start_date, args.end_date);
		frequency_usage(re, args.start_date, args.end_date)
	else:
		log.error("Query option unkwon: %s", args.query)
		
	re.close()

if __name__ == '__main__':
    main()