Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo <gustavo@gustavo-HP.(none)>2013-02-08 21:13:46 (GMT)
committer Gustavo <gustavo@gustavo-HP.(none)>2013-02-08 21:13:46 (GMT)
commit1978034bc7ff892b83b23097715194239a2d6b95 (patch)
tree711f058a4b6704957c2010f701a2790ebcadbb50
parent32c801387b66df2a987c6dc548295ea2a941dad3 (diff)
Fix most_used_activity report
-rwxr-xr-xsql/make_report13
-rwxr-xr-xsql/report.sh4
-rw-r--r--sugar_stats_consolidation/consolidation.py2
-rwxr-xr-xsugar_stats_consolidation/consolidation_run1
-rw-r--r--sugar_stats_consolidation/db.py12
-rwxr-xr-xsugar_stats_consolidation/run.sh2
6 files changed, 23 insertions, 11 deletions
diff --git a/sql/make_report b/sql/make_report
index 699d62a..7dc6805 100755
--- a/sql/make_report
+++ b/sql/make_report
@@ -18,6 +18,9 @@
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)
@@ -28,7 +31,10 @@ 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__)
@@ -37,6 +43,8 @@ ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(_LOG_FORMAT))
log.addHandler(ch)
+logging.getLogger('sugar_stats_consolidation.db').addHandler(ch)
+
def main():
"""try:"""
@@ -46,8 +54,9 @@ def main():
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 ("***************************************************************************************************************")
+ log.debug('THE MOST USED ACTIVITY: %s', activity[0])
+ log.debug('TIME: %s hrs / %s mins / %s 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"))
diff --git a/sql/report.sh b/sql/report.sh
index 6e2c5d4..0a01ec0 100755
--- a/sql/report.sh
+++ b/sql/report.sh
@@ -1,7 +1,7 @@
#!/bin/bash
QUERY=activity_most_used
-START_DATE=2013-02-00
-END_DATE=2013-02-30
+START_DATE=2013-02-01
+END_DATE=2013-02-28
DB_NAME=statistics
DB_USER=root
DB_PASS=gustavo
diff --git a/sugar_stats_consolidation/consolidation.py b/sugar_stats_consolidation/consolidation.py
index 4e0058e..b5a980b 100644
--- a/sugar_stats_consolidation/consolidation.py
+++ b/sugar_stats_consolidation/consolidation.py
@@ -16,6 +16,8 @@ class Consolidation:
self.base_path = path
try:
self.date_start = db.get_date_last_record()
+ if self.date_start == 0:
+ self.date_start = None
self.db = db
except Exception as e:
log.error('Exception: %s ', e)
diff --git a/sugar_stats_consolidation/consolidation_run b/sugar_stats_consolidation/consolidation_run
index 8730381..46b676d 100755
--- a/sugar_stats_consolidation/consolidation_run
+++ b/sugar_stats_consolidation/consolidation_run
@@ -14,7 +14,6 @@
#
# 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
import logging
diff --git a/sugar_stats_consolidation/db.py b/sugar_stats_consolidation/db.py
index f1bd0ec..898f7b9 100644
--- a/sugar_stats_consolidation/db.py
+++ b/sugar_stats_consolidation/db.py
@@ -230,20 +230,22 @@ class DB_Stats:
ts_start = datetime.strptime(start, "%Y-%m-%d")
ts_end = datetime.strptime(end, "%Y-%m-%d")
-
+ log.debug('Getting activity most used from: %s -> %s', start, end)
rows = cursor1.fetchall()
for name in rows:
+ log.debug('Activity found: %s', name[0])
if (name[0] != 'system') and (name[0] != 'journal') and (name[0] != 'network') and (name[0] != 'shell'):
- cursor2.execute ("SELECT SUM(data) FROM Usages WHERE (resource_name = %s) AND (start_date > %s) AND (start_date < %s)",
- (name[0],ts_start, ts_end))
+ cursor2.execute (
+ "SELECT SUM(data) FROM Usages WHERE (resource_name = %s) AND (start_date > %s) AND (start_date < %s)",
+ (name[0],ts_start, ts_end))
uptime = cursor2.fetchone()
if uptime[0] > uptime_last:
uptime_last= uptime[0]
activity_name = name[0]
except mysql.connector.Error as err:
log.error('MySQL on most_activity_used', err)
- except:
- log.error('most_activity_used Fail')
+ except Exception as e:
+ log.error('most_activity_used Fail: %s', e)
cursor1.close()
cursor2.close()
diff --git a/sugar_stats_consolidation/run.sh b/sugar_stats_consolidation/run.sh
index b86c2cf..8e0e31e 100755
--- a/sugar_stats_consolidation/run.sh
+++ b/sugar_stats_consolidation/run.sh
@@ -2,7 +2,7 @@
DB_USER="root"
DB_PASS="gustavo"
DB_NAME="statistics"
-RRD_PATH=~/AC/school-server/sugar-stats-debian/rrd
+RRD_PATH=/var/lib/sugar-stats/rrd
LOG_PATH=./
./consolidation_run --db_user $DB_USER --db_pass $DB_PASS --db_name $DB_NAME --rrd_path $RRD_PATH --log_path $LOG_PATH