def createhistory(graph, rrddef, rrdline, historycount, colors, historystep = None, hidedetails = False): '''Multiplies rrddef and rrdline to create a set of history views. Colors is a list of color values, first is the latest. Returns list of the new lines for eg. changing description.''' import copy r = [] if historystep is None: historystep = graph.end - graph.start for i in range(historycount): offset = historycount * historystep newdef = copy.copy(rrddef) newdef.start -= offset newdef.end -= offset newdef.history += offset graph.defs.append(newdef) newline = copy.copy(rrdline) newline.rrddef = newdef newline.color = colors[i] if hidedetails: newline.description = None newline.writeinfo = False graph.lines.append(newline) r.append(newline) return r timeunits = {'m' : 60, 'h' : 3600, 'd' : 86400, 'w' : 604800} def parsetime(timedesc): '''Parses a time description, it can be either unix timestamp, time & date in format YYYY-MM-DDTHH-MM or relative time as a negative number''' import re, datetime, time timedesc = timedesc.strip() results = re.findall('^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d)-(\d\d)', timedesc) if results: year, month, day, hours, minutes = results[0] d = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes)) return int(d.strftime("%s")) else: if timeunits.has_key(timedesc[-1]): timestamp = int(timedesc[:-1]) * timeunits[timedesc[-1]] else: timestamp = int(timedesc) if timestamp <= 0: return time.time() + timestamp else: return timestamp