2 from monitor import database
3 from datetime import datetime, timedelta
8 from monitor import config
10 def datetime_fromstr(str):
13 tup = time.strptime(str, "%Y-%m-%d")
15 tup = time.strptime(str, "%Y-%m-%d-%H:%M")
17 tup = time.strptime(str, "%m/%d/%Y")
19 tup = time.strptime(str, "%m/%d/%Y")
20 ret = datetime.fromtimestamp(time.mktime(tup))
23 def get_filefromglob(d, str, path="archive-pdb", returnlist=False):
24 # TODO: This is aweful.
25 startpath = os.getcwd()
26 os.chdir(config.MONITOR_SCRIPT_ROOT + "/" + path)
28 #archive = database.SPickle(path)
29 glob_str = "%s*.%s.pkl" % (d.strftime("%Y-%m-%d"), str)
30 fg_list = [ x[:-4] for x in glob.glob(glob_str) ]
35 return sorted(fg_list)
39 def get_archive(path):
40 full_path = config.MONITOR_SCRIPT_ROOT + "/" + path
41 return database.SPickle(full_path)
43 def print_graph(data, begin, end, xaxis, offset=500, window=100):
53 s1 = map(lambda x: x-delta, s1)
56 diff_low = map(lambda x: x[0]-x[1], rlow)
57 diff_high = map(lambda x: x[0]+x[1], rhigh)
58 s1 = map(lambda x: str(x), s1)
59 diff_low = map(lambda x: str(x), diff_low)
60 diff_high = map(lambda x: str(x), diff_high)
64 print "http://chart.apis.google.com/chart?cht=lc&chds=0,100&chxt=x,y&chxl=0:%s1:|500|550|600&chs=700x200&chm=F,aaaaaa,1,-1,2&chd=t1:%s" % (xaxis, ",".join(s1) + "|" + ",".join(diff_low) + "|" + ",".join(s1) + "|" + ",".join(s1) +"|" + ",".join(diff_high) )
66 def get_xaxis(list, width=16, wide=False):
72 if list_len == 0: return "||"
74 is_even = list_len % 2 == 0
76 # xaxis = "|" + list[0][:width] + "|" + list[-1][:width] + "|"
78 xaxis = "|" + list[0][:width] + "|" + list[list_len/2 + 1][:width] + "|" + list[-1][:width] + "|"