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 --- 9 unchanged lines hidden (view full) --- 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26# 27# Authors: Nathan Binkert |
28 29import MySQLdb, re, string 30 31def statcmp(a, b): 32 v1 = a.split('.') 33 v2 = b.split('.') 34 35 last = min(len(v1), len(v2)) - 1 --- 96 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.allBins = [] 141 self.allBinIds = {} 142 self.allBinNames = {} 143 |
144 self.allFormulas = {} 145 146 self.stattop = {} 147 self.statdict = {} 148 self.statlist = [] 149 150 self.mode = 'sum'; 151 self.runs = None |
152 self.bins = None |
153 self.ticks = None 154 self.method = 'sum' 155 self._method = type(self).sum 156 157 def get(self, job, stat, system=None): 158 run = self.allRunNames.get(str(job), None) 159 if run is None: 160 return None --- 54 unchanged lines hidden (view full) --- 215 self.query('''select rn_id,rn_name,rn_sample,rn_user,rn_project 216 from runs''') 217 for result in self.cursor.fetchall(): 218 run = RunData(result); 219 self.allRuns.append(run) 220 self.allRunIds[run.run] = run 221 self.allRunNames[run.name] = run 222 |
223 self.query('select * from bins') 224 for id,name in self.cursor.fetchall(): 225 self.allBinIds[int(id)] = name 226 self.allBinNames[name] = int(id) 227 |
228 self.query('select sd_stat,sd_x,sd_y,sd_name,sd_descr from subdata') 229 for result in self.cursor.fetchall(): 230 subdata = SubData(result) 231 if self.allSubData.has_key(subdata.stat): 232 self.allSubData[subdata.stat].append(subdata) 233 else: 234 self.allSubData[subdata.stat] = [ subdata ] 235 --- 6 unchanged lines hidden (view full) --- 242 import info 243 for result in self.cursor.fetchall(): 244 stat = info.NewStat(self, StatData(result)) 245 self.append(stat) 246 self.allStats.append(stat) 247 self.allStatIds[stat.stat] = stat 248 self.allStatNames[stat.name] = stat 249 |
250 # Name: listbins 251 # Desc: Prints all bins matching regex argument, if no argument 252 # is given all bins are returned 253 def listBins(self, regex='.*'): 254 print '%-50s %-10s' % ('bin name', 'id') 255 print '-' * 61 256 names = self.allBinNames.keys() 257 names.sort() 258 for name in names: 259 id = self.allBinNames[name] 260 print '%-50s %-10d' % (name, id) 261 |
262 # Name: listruns 263 # Desc: Prints all runs matching a given user, if no argument 264 # is given all runs are returned 265 def listRuns(self, user=None): 266 print '%-40s %-10s %-5s' % ('run name', 'user', 'id') 267 print '-' * 62 268 for run in self.allRuns: 269 if user == None or user == run.user: --- 87 unchanged lines hidden (view full) --- 357 358 if type(stat) is str: 359 rx = re.compile(stat) 360 for stat in self.allStats: 361 if rx.match(stat.name): 362 ret.append(stat) 363 return ret 364 |
365 def getBin(self, bins): 366 if type(bins) is not list: 367 bins = [ bins ] 368 369 ret = [] 370 for bin in bins: 371 if type(bin) is int: 372 ret.append(bin) 373 elif type(bin) is str: 374 ret.append(self.allBinNames[bin]) 375 else: 376 for name,id in self.allBinNames.items(): 377 if bin.match(name): 378 ret.append(id) 379 380 return ret 381 382 def getNotBin(self, bin): 383 map = {} 384 for bin in getBin(bin): 385 map[bin] = 1 386 387 ret = [] 388 for bin in self.allBinIds.keys(): 389 if not map.has_key(bin): 390 ret.append(bin) 391 392 return ret 393 |
394 ######################################### 395 # get the data 396 # |
397 def inner(self, op, stat, bins, ticks, group=False): |
398 sql = 'select ' 399 sql += 'dt_stat as stat, ' 400 sql += 'dt_run as run, ' 401 sql += 'dt_x as x, ' 402 sql += 'dt_y as y, ' 403 if group: 404 sql += 'dt_tick as tick, ' 405 sql += '%s(dt_data) as data ' % op --- 5 unchanged lines hidden (view full) --- 411 sql += ' (%s)' % val 412 else: 413 sql += ' dt_stat=%d' % stat.stat 414 415 if self.runs != None and len(self.runs): 416 val = ' or '.join([ 'dt_run=%d' % r for r in self.runs ]) 417 sql += ' and (%s)' % val 418 |
419 if bins != None and len(bins): 420 val = ' or '.join([ 'dt_bin=%d' % b for b in bins ]) 421 sql += ' and (%s)' % val 422 |
423 if ticks != None and len(ticks): 424 val = ' or '.join([ 'dt_tick=%d' % s for s in ticks ]) 425 sql += ' and (%s)' % val 426 427 sql += ' group by dt_stat,dt_run,dt_x,dt_y' 428 if group: 429 sql += ',dt_tick' 430 return sql 431 |
432 def outer(self, op_out, op_in, stat, bins, ticks): 433 sql = self.inner(op_in, stat, bins, ticks, True) 434 sql = 'select stat,run,x,y,%s(data) from (%s) as tb ' % (op_out, sql) 435 sql += 'group by stat,run,x,y' 436 return sql 437 |
438 # Name: sum |
439 # Desc: given a run, a stat and an array of samples and bins, 440 # sum all the bins and then get the standard deviation of the 441 # samples for non-binned runs. This will just return the average 442 # of samples, however a bin array still must be passed 443 def sum(self, stat, bins, ticks): 444 return self.inner('sum', stat, bins, ticks) |
445 446 # Name: avg |
447 # Desc: given a run, a stat and an array of samples and bins, 448 # sum all the bins and then average the samples for non-binned 449 # runs this will just return the average of samples, however 450 # a bin array still must be passed 451 def avg(self, stat, bins, ticks): 452 return self.outer('avg', 'sum', stat, bins, ticks) |
453 454 # Name: stdev |
455 # Desc: given a run, a stat and an array of samples and bins, 456 # sum all the bins and then get the standard deviation of the 457 # samples for non-binned runs. This will just return the average 458 # of samples, however a bin array still must be passed 459 def stdev(self, stat, bins, ticks): 460 return self.outer('stddev', 'sum', stat, bins, ticks) |
461 462 def __setattr__(self, attr, value): 463 super(Database, self).__setattr__(attr, value) 464 if attr != 'method': 465 return 466 467 if value == 'sum': 468 self._method = self.sum 469 elif value == 'avg': 470 self._method = self.avg 471 elif value == 'stdev': 472 self._method = self.stdev 473 else: 474 raise AttributeError, "can only set get to: sum | avg | stdev" 475 |
476 def data(self, stat, bins=None, ticks=None): 477 if bins is None: 478 bins = self.bins |
479 if ticks is None: 480 ticks = self.ticks |
481 sql = self._method(self, stat, bins, ticks) |
482 self.query(sql) 483 484 runs = {} 485 xmax = 0 486 ymax = 0 487 for x in self.cursor.fetchall(): 488 data = Data(x) 489 if not runs.has_key(data.run): --- 18 unchanged lines hidden --- |