Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 58a78495358a4b9a7231ca1c91d85b14109e5662

  • avatar
  • Gustavo <gustavo @gusta…-HP.(none)>
  • Fri Feb 08 14:17:29 EST 2013
  • Tree SHA1: 62e7a70
  • Parent SHA1: e63fe93 (Fix issue when start_date > last_record_date. In this case asume that this rrd file is newer althoug has older records, and set as start_date = first_record_date)
  • raw diff | raw patch
sql report fixes
  
1414#
1515# You should have received a copy of the GNU General Public License
1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
17from __future__ import print_function
1817
1918import argparse
20from stats_consolidation.db import *
19from sugar_stats_consolidation.db import *
2120import sys
2221parser = argparse.ArgumentParser()
2322parser.add_argument('--query',required=True)
2828
2929args = parser.parse_args()
3030
31_LOG_FORMAT='[%(asctime)s]-%(levelname)s-\'%(name)s\': %(message)s'
3132
32"""try:"""
33re = DB_Stats (args.db_name, args.db_user, args.db_pass)
34re.connect()
35if args.query == 'activity_most_used':
36 activity = re.most_activity_used(args.start_date, args.end_date);
37 print ("**************************************************************************************************************")
38 print ("From: {} -> {}:".format(args.start_date, args.end_date))
39 print ("THE MOST USED ACTIVITY: {}, TIME: {} hrs / {} mins / {} secs".format(activity[0], (activity[1]/60/60),(activity[1]/60),activity[1]))
40 print ("***************************************************************************************************************")
4133
42if args.query == 'frequency_usage':
43 ts_end = long (datetime.strptime(args.end_date, "%Y-%m-%d").strftime("%s"))
44 ts_start = long (datetime.strptime(args.start_date, "%Y-%m-%d").strftime("%s"))
34log = logging.getLogger(__name__)
35log.setLevel(logging.DEBUG)
36ch = logging.StreamHandler()
37ch.setFormatter(logging.Formatter(_LOG_FORMAT))
38log.addHandler(ch)
4539
46 fres = re.frequency_usage(args.start_date, args.end_date);
47 f_x_day = (fres / ((ts_end - ts_start)/(60*60*24)))/60
48 print ("**************************************************************************************************************")
49 print ("From: {} -> {}:".format(args.start_date, args.end_date))
50 print("Frequency usage: %.2f min / day" % (f_x_day))
51 print ("**************************************************************************************************************")
52"""
53print ("Error: {}".format(sys.exc_info()[0]))
54"""
40
41def main():
42 """try:"""
43 re = DB_Stats (args.db_name, args.db_user, args.db_pass)
44 re.connect()
45 if args.query == 'activity_most_used':
46 activity = re.most_activity_used(args.start_date, args.end_date);
47 log.debug("**************************************************************************************************************")
48 log.debug('From: %s-> %s:', args.start_date, args.end_date)
49 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])
50 print ("***************************************************************************************************************")
51
52 if args.query == 'frequency_usage':
53 ts_end = long (datetime.strptime(args.end_date, "%Y-%m-%d").strftime("%s"))
54 ts_start = long (datetime.strptime(args.start_date, "%Y-%m-%d").strftime("%s"))
55
56 fres = re.frequency_usage(args.start_date, args.end_date);
57 f_x_day = (fres / ((ts_end - ts_start)/(60*60*24)))/60
58 print ("**************************************************************************************************************")
59 print ("From: {0} -> {1}:".format(args.start_date, args.end_date))
60 print("Frequency usage: %.2f min / day" % (f_x_day))
61 print ("**************************************************************************************************************")
62 """
63 print ("Error: {}".format(sys.exc_info()[0]))
64 """
65
66if __name__ == '__main__':
67 main()