diff options
author | Gustavo Duarte AC <gduarte@activitycentral.com> | 2013-02-19 20:16:52 (GMT) |
---|---|---|
committer | Gustavo Duarte AC <gduarte@activitycentral.com> | 2013-02-19 20:16:52 (GMT) |
commit | 9082f866c243cb5dc6af9cdff8f2b2b201697f50 (patch) | |
tree | 007831377b55073886c49cce5c0dbca625f5db84 | |
parent | fd0bca7d7c69d298f90503e2799248fe02a12bff (diff) |
Improves:
+ Add query scitp to set school for a specific user defined by machine_sn
-rwxr-xr-x | sql/make_report | 15 | ||||
-rwxr-xr-x | sql/rep_set_school.sh | 13 | ||||
-rw-r--r-- | sugar_stats_consolidation/db.py | 12 | ||||
-rw-r--r-- | sugar_stats_consolidation/rrd_files.py | 4 | ||||
-rwxr-xr-x | sugar_stats_consolidation/run.sh | 3 |
5 files changed, 41 insertions, 6 deletions
diff --git a/sql/make_report b/sql/make_report index 5bd19e1..329f5c6 100755 --- a/sql/make_report +++ b/sql/make_report @@ -23,14 +23,15 @@ 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('--start_date',required=False) +parser.add_argument('--end_date',required=False) parser.add_argument('--db_name',required=True) parser.add_argument('--db_user',required=True) parser.add_argument('--db_pass',required=True) parser.add_argument('--activity',required=False) parser.add_argument('--school',required=False) parser.add_argument('--log_level',required=False) +parser.add_argument('--machine_sn',required=False) args = parser.parse_args() @@ -100,6 +101,14 @@ def activity_time (re, start, end, activity, school=None): log.info('FOCUS %s secs', time[1]) log.info("**************************************************************************************************************") +def update_school (re, machine_sn, school): + re.rep_update_school(machine_sn, school); + + log.info("**************************************************************************************************************") + log.info(" Set School name to User ") + log.info('SCHOOL: %s', school) + log.info('MACHINE_SN: %s', machine_sn) + log.info("**************************************************************************************************************") def main(): @@ -112,6 +121,8 @@ def main(): activity_most_used(re, args.start_date, args.end_date, args.school); elif args.query == 'frequency_usage': frequency_usage(re, args.start_date, args.end_date, args.school) + elif args.query == 'update_school': + update_school(re, args.machine_sn, args.school) elif args.query == 'all': activity_most_used(re, args.start_date, args.end_date,args.school); frequency_usage(re, args.start_date, args.end_date, args.school) diff --git a/sql/rep_set_school.sh b/sql/rep_set_school.sh new file mode 100755 index 0000000..888b848 --- /dev/null +++ b/sql/rep_set_school.sh @@ -0,0 +1,13 @@ +#!/bin/bash +DB_NAME=statistics +DB_USER=root +DB_PASS=gustavo + +QUERY=update_school + +LOG_LEVEL=debug +SCHOOL=activitycentral +MACHINE_SN=777788889999 + +./make_report --query $QUERY --school $SCHOOL --machine_sn $MACHINE_SN --db_name $DB_NAME --db_user $DB_USER --db_pass $DB_PASS --log_level $LOG_LEVEL + diff --git a/sugar_stats_consolidation/db.py b/sugar_stats_consolidation/db.py index 4123b40..5edaaa8 100644 --- a/sugar_stats_consolidation/db.py +++ b/sugar_stats_consolidation/db.py @@ -392,11 +392,21 @@ class DB_Stats: except mysql.connector.Error as err: - log.error("MySQL on fequency_usage_by_school %s: %s", cursor.statement, err) + log.error("MySQL on %s: %s", cursor.statement, err) cursor1.close() cursor2.close() + def rep_update_school(self, machine_sn, school): + cursor = self.cnx.cursor() + try: + log.debug("Set school name: %s to user with machine_sn: %s", school, machine_sn) + cursor.execute ("UPDATE Users SET school = %s WHERE machine_sn = %s", (school, machine_sn)) + except mysql.connector.Error as err: + log.error("MySQL on %s: %s", cursor.statement, err) + + cursor.close() + #========================================================================================================= # A U X I L I A R M E T H O D S #========================================================================================================= diff --git a/sugar_stats_consolidation/rrd_files.py b/sugar_stats_consolidation/rrd_files.py index 67a856b..21c48df 100644 --- a/sugar_stats_consolidation/rrd_files.py +++ b/sugar_stats_consolidation/rrd_files.py @@ -146,10 +146,10 @@ class RRD: return l[idx] def get_uuid_from_file(self,path): - return open (os.path.join(path, "machine_uuid")).next() + return open (os.path.join(path, "machine_uuid")).next().strip("\"") def get_machine_sn_from_file(self,path): - return open (os.path.join(path, "machine_sn")).next() + return open (os.path.join(path, "machine_sn")).next().strip("\"") def get_user_hash(self): diff --git a/sugar_stats_consolidation/run.sh b/sugar_stats_consolidation/run.sh index eabf495..05bb6ca 100755 --- a/sugar_stats_consolidation/run.sh +++ b/sugar_stats_consolidation/run.sh @@ -1,4 +1,5 @@ -DB_USER="root"SS="gustavo" +DB_USER="root" +DB_PASS="gustavo" DB_NAME="statistics" RRD_PATH=/var/lib/sugar-stats/rrd APP_PATH=/home/ceibal/ac/statistics-consolidation |