Deleted Added
sdiff udiff text old ( 2343:a2b4a6ccee56 ) new ( 2665:a124942bacb8 )
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

--- 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
27import MySQLdb, re, string
28
29def statcmp(a, b):
30 v1 = a.split('.')
31 v2 = b.split('.')
32
33 last = min(len(v1), len(v2)) - 1

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

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

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

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

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

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

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

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

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

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

--- 18 unchanged lines hidden ---