Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sql/make_report
blob: 699d62a4005d715f986b16a9be75a22f291de3a2 (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
#!/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
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 = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(_LOG_FORMAT))
log.addHandler(ch)


def main():
	"""try:"""
	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('From: %s-> %s:', args.start_date, args.end_date)
		log.debug('THE MOST USED ACTIVITY: %s, TIME: %s hrs / %s mins / %s secs', activity[0], (activity[1]/60/60),(activity[1]/60),activity[1])
		print ("***************************************************************************************************************")

	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
		print ("**************************************************************************************************************")
		print ("From: {0} -> {1}:".format(args.start_date, args.end_date))
		print("Frequency usage: %.2f min / day" % (f_x_day))
		print ("**************************************************************************************************************")
	"""
	print ("Error: {}".format(sys.exc_info()[0]))
	"""

if __name__ == '__main__':
    main()