db.py (2665:a124942bacb8) | db.py (2716:b9114064d77a) |
---|---|
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 | 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.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 | 140 self.allFormulas = {} 141 142 self.stattop = {} 143 self.statdict = {} 144 self.statlist = [] 145 146 self.mode = 'sum'; 147 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 | 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 |
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 | 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 |
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 | 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 |
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 # | 343 ######################################### 344 # get the data 345 # |
397 def inner(self, op, stat, bins, ticks, group=False): | 346 def query(self, op, stat, 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 | 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 |
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 | 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 |
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 | 377 # 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) | 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) |
445 446 # Name: avg | 381 382 # 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) | 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) |
453 454 # Name: stdev | 386 387 # 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) | 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) |
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 | 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 |
476 def data(self, stat, bins=None, ticks=None): 477 if bins is None: 478 bins = self.bins | 407 def data(self, stat, ticks=None): |
479 if ticks is None: 480 ticks = self.ticks | 408 if ticks is None: 409 ticks = self.ticks |
481 sql = self._method(self, stat, bins, ticks) | 410 sql = self._method(self, stat, 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 --- | 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 --- |