Deleted Added
sdiff udiff text old ( 2665:a124942bacb8 ) new ( 2716:b9114064d77a )
full compact
1# Copyright (c) 2003-2004 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 123 unchanged lines hidden (view full) ---

132 self.allStatNames = {}
133
134 self.allSubData = {}
135
136 self.allRuns = []
137 self.allRunIds = {}
138 self.allRunNames = {}
139
140 self.allFormulas = {}
141
142 self.stattop = {}
143 self.statdict = {}
144 self.statlist = []
145
146 self.mode = 'sum';
147 self.runs = None
148 self.ticks = None
149 self.method = 'sum'
150 self._method = type(self).sum
151
152 def get(self, job, stat, system=None):
153 run = self.allRunNames.get(str(job), None)
154 if run is None:
155 return None

--- 54 unchanged lines hidden (view full) ---

210 self.query('''select rn_id,rn_name,rn_sample,rn_user,rn_project
211 from runs''')
212 for result in self.cursor.fetchall():
213 run = RunData(result);
214 self.allRuns.append(run)
215 self.allRunIds[run.run] = run
216 self.allRunNames[run.name] = run
217
218 self.query('select sd_stat,sd_x,sd_y,sd_name,sd_descr from subdata')
219 for result in self.cursor.fetchall():
220 subdata = SubData(result)
221 if self.allSubData.has_key(subdata.stat):
222 self.allSubData[subdata.stat].append(subdata)
223 else:
224 self.allSubData[subdata.stat] = [ subdata ]
225

--- 6 unchanged lines hidden (view full) ---

232 import info
233 for result in self.cursor.fetchall():
234 stat = info.NewStat(self, StatData(result))
235 self.append(stat)
236 self.allStats.append(stat)
237 self.allStatIds[stat.stat] = stat
238 self.allStatNames[stat.name] = stat
239
240 # Name: listruns
241 # Desc: Prints all runs matching a given user, if no argument
242 # is given all runs are returned
243 def listRuns(self, user=None):
244 print '%-40s %-10s %-5s' % ('run name', 'user', 'id')
245 print '-' * 62
246 for run in self.allRuns:
247 if user == None or user == run.user:

--- 87 unchanged lines hidden (view full) ---

335
336 if type(stat) is str:
337 rx = re.compile(stat)
338 for stat in self.allStats:
339 if rx.match(stat.name):
340 ret.append(stat)
341 return ret
342
343 #########################################
344 # get the data
345 #
346 def query(self, op, stat, ticks, group=False):
347 sql = 'select '
348 sql += 'dt_stat as stat, '
349 sql += 'dt_run as run, '
350 sql += 'dt_x as x, '
351 sql += 'dt_y as y, '
352 if group:
353 sql += 'dt_tick as tick, '
354 sql += '%s(dt_data) as data ' % op

--- 5 unchanged lines hidden (view full) ---

360 sql += ' (%s)' % val
361 else:
362 sql += ' dt_stat=%d' % stat.stat
363
364 if self.runs != None and len(self.runs):
365 val = ' or '.join([ 'dt_run=%d' % r for r in self.runs ])
366 sql += ' and (%s)' % val
367
368 if ticks != None and len(ticks):
369 val = ' or '.join([ 'dt_tick=%d' % s for s in ticks ])
370 sql += ' and (%s)' % val
371
372 sql += ' group by dt_stat,dt_run,dt_x,dt_y'
373 if group:
374 sql += ',dt_tick'
375 return sql
376
377 # Name: sum
378 # Desc: given a run, a stat and an array of samples, total the samples
379 def sum(self, *args, **kwargs):
380 return self.query('sum', *args, **kwargs)
381
382 # Name: avg
383 # Desc: given a run, a stat and an array of samples, average the samples
384 def avg(self, stat, ticks):
385 return self.query('avg', *args, **kwargs)
386
387 # Name: stdev
388 # Desc: given a run, a stat and an array of samples, get the standard
389 # deviation
390 def stdev(self, stat, ticks):
391 return self.query('stddev', *args, **kwargs)
392
393 def __setattr__(self, attr, value):
394 super(Database, self).__setattr__(attr, value)
395 if attr != 'method':
396 return
397
398 if value == 'sum':
399 self._method = self.sum
400 elif value == 'avg':
401 self._method = self.avg
402 elif value == 'stdev':
403 self._method = self.stdev
404 else:
405 raise AttributeError, "can only set get to: sum | avg | stdev"
406
407 def data(self, stat, ticks=None):
408 if ticks is None:
409 ticks = self.ticks
410 sql = self._method(self, stat, ticks)
411 self.query(sql)
412
413 runs = {}
414 xmax = 0
415 ymax = 0
416 for x in self.cursor.fetchall():
417 data = Data(x)
418 if not runs.has_key(data.run):

--- 18 unchanged lines hidden ---