def query(self, op, stat, ticks, group=False): sql = 'select ' sql += 'dt_stat as stat, ' sql += 'dt_run as run, ' sql += 'dt_x as x, ' sql += 'dt_y as y, ' if group: sql += 'dt_tick as tick, ' sql += '%s(dt_data) as data ' % op sql += 'from data ' sql += 'where ' if isinstance(stat, list): val = ' or '.join([ 'dt_stat=%d' % s.stat for s in stat ]) sql += ' (%s)' % val else: sql += ' dt_stat=%d' % stat.stat if self.runs != None and len(self.runs): val = ' or '.join([ 'dt_run=%d' % r for r in self.runs ]) sql += ' and (%s)' % val if ticks != None and len(ticks): val = ' or '.join([ 'dt_tick=%d' % s for s in ticks ]) sql += ' and (%s)' % val sql += ' group by dt_stat,dt_run,dt_x,dt_y' if group: sql += ',dt_tick' return sql
def query(self, op, stat, ticks, group=False): sql = 'select ' sql += 'dt_stat as stat, ' sql += 'dt_run as run, ' sql += 'dt_x as x, ' sql += 'dt_y as y, ' if group: sql += 'dt_tick as tick, ' sql += '%s(dt_data) as data ' % op sql += 'from data ' sql += 'where ' if isinstance(stat, list): val = ' or '.join(['dt_stat=%d' % s.stat for s in stat]) sql += ' (%s)' % val else: sql += ' dt_stat=%d' % stat.stat if self.runs != None and len(self.runs): val = ' or '.join(['dt_run=%d' % r for r in self.runs]) sql += ' and (%s)' % val if ticks != None and len(ticks): val = ' or '.join(['dt_tick=%d' % s for s in ticks]) sql += ' and (%s)' % val sql += ' group by dt_stat,dt_run,dt_x,dt_y' if group: sql += ',dt_tick' return sql
def __init__(self, row): if len(row) != 5: raise 'stat db error' self.stat = int(row[0]) self.run = int(row[1]) self.x = int(row[2]) self.y = int(row[3]) self.data = float(row[4])
def statcmp(a, b): v1 = a.split('.') v2 = b.split('.') last = min(len(v1), len(v2)) - 1 for i, j in zip(v1[0:last], v2[0:last]): if i != j: return cmp(i, j) # Special compare for last element. if len(v1) == len(v2): return cmp(v1[last], v2[last]) else: return cmp(len(v1), len(v2))
def statcmp(a, b): v1 = a.split('.') v2 = b.split('.') last = min(len(v1), len(v2)) - 1 for i,j in zip(v1[0:last], v2[0:last]): if i != j: return cmp(i, j) # Special compare for last element. if len(v1) == len(v2): return cmp(v1[last], v2[last]) else: return cmp(len(v1), len(v2))
def append(self, stat): statname = re.sub(':', '__', stat.name) path = string.split(statname, '.') pathtop = path[0] fullname = '' x = self while len(path) > 1: name = path.pop(0) if not x.__dict__.has_key(name): x.__dict__[name] = Node(fullname + name) x = x.__dict__[name] fullname = '%s%s.' % (fullname, name) name = path.pop(0) x.__dict__[name] = stat self.stattop[pathtop] = self.__dict__[pathtop] self.statdict[statname] = stat self.statlist.append(statname)