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
|
#!/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/>.
from __future__ import print_function
import argparse
from 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()
"""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);
print ("**************************************************************************************************************")
print ("From: {} -> {}:".format(args.start_date, args.end_date))
print ("THE MOST USED ACTIVITY: {}, TIME: {} hrs / {} mins / {} secs".format(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: {} -> {}:".format(args.start_date, args.end_date))
print("Frequency usage: %.2f min / day" % (f_x_day))
print ("**************************************************************************************************************")
"""
print ("Error: {}".format(sys.exc_info()[0]))
"""
|