Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_stats_consolidation/rrd_files.py
diff options
context:
space:
mode:
Diffstat (limited to 'sugar_stats_consolidation/rrd_files.py')
-rw-r--r--sugar_stats_consolidation/rrd_files.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/sugar_stats_consolidation/rrd_files.py b/sugar_stats_consolidation/rrd_files.py
index dec2c43..67a856b 100644
--- a/sugar_stats_consolidation/rrd_files.py
+++ b/sugar_stats_consolidation/rrd_files.py
@@ -1,8 +1,12 @@
import rrdtool
import os
import sys
+import logging
from datetime import datetime
+log = logging.getLogger(__name__)
+
+
class RRD:
hdr_item = 0
@@ -17,15 +21,15 @@ class RRD:
if date_start == None or (date_start > rrdtool.last(str(os.path.join(path, name)))):
self.date_start = str(rrdtool.first(str(os.path.join (path,name))))
else:
- self.date_start = date_start
+ self.date_start = str(date_start)
if date_end == None:
self.date_end = str(rrdtool.last(str(os.path.join(path, name))))
else:
self.date_end = str(date_end)
- if self.date_start > self.date_end:
- raise Exception("No data available on rrd, from {0} to {1}".format( str(datetime.fromtimestamp(float(self.date_start))), str(datetime.fromtimestamp(float(self.date_end)))))
+ if float (self.date_start) > float(self.date_end):
+ raise Exception("Invalid date_start={0} and date_end={1}".format( str(datetime.fromtimestamp(float(self.date_start))), str(datetime.fromtimestamp(float(self.date_end)))))
self.user_hash = os.path.split(path)[1]
@@ -36,12 +40,16 @@ class RRD:
self.user_hash[:2],
self.user_hash
)
- """
+
self.uuid = self.get_uuid_from_file(self.user_path)
- """
- self.uuid = "for_tesing"
+ self.age = 0
+ self.sn = self.get_machine_sn_from_file(self.user_path)
+ self.school = "unkown"
+
- print "*******************************************"
+
+
+ print "******************************************"
print " creating a RRD instance "
print "start: " + str(datetime.fromtimestamp(float(self.date_start)))
print "end: " + str(datetime.fromtimestamp(float(self.date_end)))
@@ -49,10 +57,9 @@ class RRD:
print "RRD NAME: " + name
print "\n"
try:
- self.rrd = rrdtool.fetch (str(os.path.join(path,name)), 'AVERAGE', '-r 60', '-s '+ self.date_start, '-e '+self.date_end)
- except:
- raise Exception("rrdtool.fetch FAIL, from {0} to {1}".format( str(datetime.fromtimestamp(float(self.date_start))), str(datetime.fromtimestamp(float(self.date_end)))))
-
+ self.rrd = rrdtool.fetch (str(os.path.join(path,name)), 'AVERAGE', '-r 60', '-s '+ self.date_start, '-e '+ self.date_end)
+ except Exception as e:
+ raise Exception("rrdtool.fetch: {0}".format(e))
print " DS "
for item in self.DS.keys():
idx = self.get_ds_index (item)
@@ -140,6 +147,9 @@ class RRD:
def get_uuid_from_file(self,path):
return open (os.path.join(path, "machine_uuid")).next()
+
+ def get_machine_sn_from_file(self,path):
+ return open (os.path.join(path, "machine_sn")).next()
def get_user_hash(self):
@@ -147,6 +157,16 @@ class RRD:
def get_uuid (self):
return self.uuid
+
+ def get_sn (self):
+ return self.sn
+
+ def get_school (self):
+ return self.school
+
+ def get_age (self):
+ return self.age
+
"""
For some reason, sometimes for a while activity is running, statistics library register several values as None.