info.py (1772:a3a83e812a5e) | info.py (1929:fb189519cb06) |
---|---|
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 --- 13 unchanged lines hidden (view full) --- 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 27from __future__ import division 28import operator, re, types 29 | 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 --- 13 unchanged lines hidden (view full) --- 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 27from __future__ import division 28import operator, re, types 29 |
30source = None 31display_run = 0 32global globalTicks 33globalTicks = None | 30def unproxy(proxy): 31 if hasattr(proxy, '__unproxy__'): 32 return proxy.__unproxy__() |
34 | 33 |
35def total(f): 36 if isinstance(f, FormulaStat): 37 v = f.value 38 else: 39 v = f | 34 return proxy |
40 | 35 |
41 f = FormulaStat() 42 if isinstance(v, (list, tuple)): 43 f.value = reduce(operator.add, v) 44 else: 45 f.value = v | 36def scalar(stat): 37 stat = unproxy(stat) 38 assert(stat.__scalar__() != stat.__vector__()) 39 return stat.__scalar__() |
46 | 40 |
47 return f | 41def vector(stat): 42 stat = unproxy(stat) 43 assert(stat.__scalar__() != stat.__vector__()) 44 return stat.__vector__() |
48 | 45 |
49def unaryop(op, f): 50 if isinstance(f, FormulaStat): 51 v = f.value 52 else: 53 v = f | 46def value(stat, *args): 47 stat = unproxy(stat) 48 return stat.__value__(*args) |
54 | 49 |
55 if isinstance(v, (list, tuple)): 56 return map(op, v) 57 else: 58 return op(v) | 50def values(stat, run): 51 stat = unproxy(stat) 52 result = [] 53 for i in xrange(len(stat)): 54 val = value(stat, run.run, i) 55 if val is None: 56 return None 57 result.append(val) 58 return result |
59 | 59 |
60def zerodiv(lv, rv): 61 if rv == 0.0: 62 return 0.0 63 else: 64 return operator.truediv(lv, rv) | 60def total(stat, run): 61 return sum(values(stat, run)) |
65 | 62 |
66def wrapop(op, lv, rv): 67 if isinstance(lv, str): 68 return lv | 63def len(stat): 64 stat = unproxy(stat) 65 return stat.__len__() |
69 | 66 |
70 if isinstance(rv, str): 71 return rv | 67class Value(object): 68 def __scalar__(self): 69 raise AttributeError, "must define __scalar__ for %s" % (type (self)) 70 def __vector__(self): 71 raise AttributeError, "must define __vector__ for %s" % (type (self)) |
72 | 72 |
73 return op(lv, rv) | 73 def __add__(self, other): 74 return BinaryProxy(operator.__add__, self, other) 75 def __sub__(self, other): 76 return BinaryProxy(operator.__sub__, self, other) 77 def __mul__(self, other): 78 return BinaryProxy(operator.__mul__, self, other) 79 def __div__(self, other): 80 return BinaryProxy(operator.__div__, self, other) 81 def __truediv__(self, other): 82 return BinaryProxy(operator.__truediv__, self, other) 83 def __floordiv__(self, other): 84 return BinaryProxy(operator.__floordiv__, self, other) |
74 | 85 |
75def same(lrun, rrun): 76 for lx,rx in zip(lrun.keys(),rrun.keys()): 77 if lx != rx: 78 print 'lx != rx' 79 print lx, rx 80 print lrun.keys() 81 print rrun.keys() 82 return False 83 for ly,ry in zip(lrun[lx].keys(),rrun[rx].keys()): 84 if ly != ry: 85 print 'ly != ry' 86 print ly, ry 87 print lrun[lx].keys() 88 print rrun[rx].keys() 89 return False 90 return True | 86 def __radd__(self, other): 87 return BinaryProxy(operator.__add__, other, self) 88 def __rsub__(self, other): 89 return BinaryProxy(operator.__sub__, other, self) 90 def __rmul__(self, other): 91 return BinaryProxy(operator.__mul__, other, self) 92 def __rdiv__(self, other): 93 return BinaryProxy(operator.__div__, other, self) 94 def __rtruediv__(self, other): 95 return BinaryProxy(operator.__truediv__, other, self) 96 def __rfloordiv__(self, other): 97 return BinaryProxy(operator.__floordiv__, other, self) |
91 | 98 |
99 def __neg__(self): 100 return UnaryProxy(operator.__neg__, self) 101 def __pos__(self): 102 return UnaryProxy(operator.__pos__, self) 103 def __abs__(self): 104 return UnaryProxy(operator.__abs__, self) |
|
92 | 105 |
93def binaryop(op, lf, rf): 94 result = {} | 106class Scalar(Value): 107 def __scalar__(self): 108 return True |
95 | 109 |
96 if isinstance(lf, FormulaStat) and isinstance(rf, FormulaStat): 97 lv = lf.value 98 rv = rf.value | 110 def __vector__(self): 111 return False |
99 | 112 |
100 theruns = [] 101 for r in lv.keys(): 102 if rv.has_key(r): 103 if same(lv[r], rv[r]): 104 theruns.append(r) 105 else: 106 raise AttributeError | 113 def __value__(self, run): 114 raise AttributeError, '__value__ must be defined' |
107 | 115 |
108 for run in theruns: 109 result[run] = {} 110 for x in lv[run].keys(): 111 result[run][x] = {} 112 for y in lv[run][x].keys(): 113 result[run][x][y] = wrapop(op, lv[run][x][y], 114 rv[run][x][y]) 115 elif isinstance(lf, FormulaStat): 116 lv = lf.value 117 for run in lv.keys(): 118 result[run] = {} 119 for x in lv[run].keys(): 120 result[run][x] = {} 121 for y in lv[run][x].keys(): 122 result[run][x][y] = wrapop(op, lv[run][x][y], rf) 123 elif isinstance(rf, FormulaStat): 124 rv = rf.value 125 for run in rv.keys(): 126 result[run] = {} 127 for x in rv[run].keys(): 128 result[run][x] = {} 129 for y in rv[run][x].keys(): 130 result[run][x][y] = wrapop(op, lf, rv[run][x][y]) | 116class VectorItemProxy(Value): 117 def __init__(self, proxy, index): 118 self.proxy = proxy 119 self.index = index |
131 | 120 |
132 return result | 121 def __scalar__(self): 122 return True |
133 | 123 |
134def sums(x, y): 135 if isinstance(x, (list, tuple)): 136 return map(lambda x, y: x + y, x, y) 137 else: 138 return x + y | 124 def __vector__(self): 125 return False |
139 | 126 |
140def alltrue(seq): 141 return reduce(lambda x, y: x and y, seq) | 127 def __value__(self, run): 128 return value(self.proxy, run, self.index) |
142 | 129 |
143def allfalse(seq): 144 return not reduce(lambda x, y: x or y, seq) | 130class Vector(Value): 131 def __scalar__(self): 132 return False |
145 | 133 |
146def enumerate(seq): 147 return map(None, range(len(seq)), seq) | 134 def __vector__(self): 135 return True |
148 | 136 |
149def cmp(a, b): 150 if a < b: 151 return -1 152 elif a == b: 153 return 0 154 else: 155 return 1 | 137 def __value__(self, run, index): 138 raise AttributeError, '__value__ must be defined' |
156 | 139 |
157class Statistic(object): | 140 def __getitem__(self, index): 141 return VectorItemProxy(self, index) |
158 | 142 |
159 def __init__(self, data): 160 self.__dict__.update(data.__dict__) 161 if not self.__dict__.has_key('value'): 162 self.__dict__['value'] = None 163 if not self.__dict__.has_key('bins'): 164 self.__dict__['bins'] = None 165 if not self.__dict__.has_key('ticks'): 166 self.__dict__['ticks'] = None 167 if 'vc' not in self.__dict__: 168 self.vc = {} | 143class ScalarConstant(Scalar): 144 def __init__(self, constant): 145 self.constant = constant 146 def __value__(self, run): 147 return self.constant |
169 | 148 |
170 def __getattribute__(self, attr): 171 if attr == 'ticks': 172 if self.__dict__['ticks'] != globalTicks: 173 self.__dict__['value'] = None 174 self.__dict__['ticks'] = globalTicks 175 return self.__dict__['ticks'] 176 if attr == 'value': 177 if self.__dict__['ticks'] != globalTicks: 178 if self.__dict__['ticks'] != None and \ 179 len(self.__dict__['ticks']) == 1: 180 self.vc[self.__dict__['ticks'][0]] = self.__dict__['value'] 181 self.__dict__['ticks'] = globalTicks 182 if len(globalTicks) == 1 and self.vc.has_key(globalTicks[0]): 183 self.__dict__['value'] = self.vc[globalTicks[0]] 184 else: 185 self.__dict__['value'] = None 186 if self.__dict__['value'] == None: 187 self.__dict__['value'] = self.getValue() 188 return self.__dict__['value'] 189 else: 190 return super(Statistic, self).__getattribute__(attr) | 149class VectorConstant(Vector): 150 def __init__(self, constant): 151 self.constant = constant 152 def __value__(self, run, index): 153 return self.constant[index] 154 def __len__(self): 155 return len(self.constant) |
191 | 156 |
157def WrapValue(value): 158 if isinstance(value, (int, long, float)): 159 return ScalarConstant(value) 160 if isinstance(value, (list, tuple)): 161 return VectorConstant(value) 162 if isinstance(value, Value): 163 return value 164 165 raise AttributeError, 'Only values can be wrapped' 166 167class Statistic(object): 168 def __getattr__(self, attr): 169 if attr in ('data', 'x', 'y'): 170 result = self.source.data(self, self.bins, self.ticks) 171 self.data = result.data 172 self.x = result.x 173 self.y = result.y 174 return super(Statistic, self).__getattribute__(attr) 175 |
|
192 def __setattr__(self, attr, value): | 176 def __setattr__(self, attr, value): |
193 if attr == 'bins' or attr == 'ticks': 194 if attr == 'bins': 195 if value is not None: 196 value = source.getBin(value) 197 #elif attr == 'ticks' and type(value) is str: 198 # value = [ int(x) for x in value.split() ] | 177 if attr == 'stat': 178 raise AttributeError, '%s is read only' % stat 179 if attr in ('source', 'bins', 'ticks'): 180 if getattr(self, attr) != value: 181 if hasattr(self, 'data'): 182 delattr(self, 'data') |
199 | 183 |
200 self.__dict__[attr] = value 201 self.__dict__['value'] = None 202 self.vc = {} 203 else: 204 super(Statistic, self).__setattr__(attr, value) | 184 super(Statistic, self).__setattr__(attr, value) |
205 | 185 |
206 def getValue(self): 207 raise AttributeError, 'getValue() must be defined' | 186class ValueProxy(Value): 187 def __getattr__(self, attr): 188 if attr == '__value__': 189 if scalar(self): 190 return self.__scalarvalue__ 191 if vector(self): 192 return self.__vectorvalue__ 193 if attr == '__len__': 194 if vector(self): 195 return self.__vectorlen__ 196 return super(ValueProxy, self).__getattribute__(attr) |
208 | 197 |
209 def zero(self): 210 return False | 198class UnaryProxy(ValueProxy): 199 def __init__(self, op, arg): 200 self.op = op 201 self.arg = WrapValue(arg) |
211 | 202 |
212 def __ne__(self, other): 213 return not (self == other) | 203 def __scalar__(self): 204 return scalar(self.arg) |
214 | 205 |
215 def __str__(self): 216 return '%f' % (float(self)) | 206 def __vector__(self): 207 return vector(self.arg) |
217 | 208 |
218class FormulaStat(object): 219 def __add__(self, other): 220 f = FormulaStat() 221 f.value = binaryop(operator.add, self, other) 222 return f 223 def __sub__(self, other): 224 f = FormulaStat() 225 f.value = binaryop(operator.sub, self, other) 226 return f 227 def __mul__(self, other): 228 f = FormulaStat() 229 f.value = binaryop(operator.mul, self, other) 230 return f 231 def __truediv__(self, other): 232 f = FormulaStat() 233 f.value = binaryop(zerodiv, self, other) 234 return f 235 def __mod__(self, other): 236 f = FormulaStat() 237 f.value = binaryop(operator.mod, self, other) 238 return f 239 def __radd__(self, other): 240 f = FormulaStat() 241 f.value = binaryop(operator.add, other, self) 242 return f 243 def __rsub__(self, other): 244 f = FormulaStat() 245 f.value = binaryop(operator.sub, other, self) 246 return f 247 def __rmul__(self, other): 248 f = FormulaStat() 249 f.value = binaryop(operator.mul, other, self) 250 return f 251 def __rtruediv__(self, other): 252 f = FormulaStat() 253 f.value = binaryop(zerodiv, other, self) 254 return f 255 def __rmod__(self, other): 256 f = FormulaStat() 257 f.value = binaryop(operator.mod, other, self) 258 return f 259 def __neg__(self): 260 f = FormulaStat() 261 f.value = unaryop(operator.neg, self) 262 return f 263 def __getitem__(self, idx): 264 f = FormulaStat() 265 f.value = {} 266 for key in self.value.keys(): 267 f.value[key] = {} 268 f.value[key][0] = {} 269 f.value[key][0][0] = self.value[key][idx][0] 270 return f | 209 def __scalarvalue__(self, run): 210 val = value(self.arg, run) 211 if val is None: 212 return None 213 return self.op(val) |
271 | 214 |
272 def __float__(self): 273 if isinstance(self.value, FormulaStat): 274 return float(self.value) 275 if not self.value.has_key(display_run): 276 return (1e300*1e300) 277 if len(self.value[display_run]) == 1: 278 return self.value[display_run][0][0] 279 else: 280 #print self.value[display_run] 281 return self.value[display_run][4][0] 282 #raise ValueError | 215 def __vectorvalue__(self, run, index): 216 val = value(self.arg, run, index) 217 if val is None: 218 return None 219 return self.op(val) |
283 | 220 |
284 def display(self): 285 import display 286 d = display.VectorDisplay() 287 d.flags = 0 288 d.precision = 1 289 d.name = 'formula' 290 d.desc = 'formula' 291 val = self.value[display_run] 292 d.value = [ val[x][0] for x in val.keys() ] 293 d.display() | 221 def __vectorlen__(self): 222 return len(unproxy(self.arg)) |
294 | 223 |
224class BinaryProxy(ValueProxy): 225 def __init__(self, op, arg0, arg1): 226 super(BinaryProxy, self).__init__() 227 self.op = op 228 self.arg0 = WrapValue(arg0) 229 self.arg1 = WrapValue(arg1) |
|
295 | 230 |
296class Scalar(Statistic,FormulaStat): 297 def getValue(self): 298 return source.data(self, self.bins, self.ticks) | 231 def __scalar__(self): 232 return scalar(self.arg0) and scalar(self.arg1) |
299 | 233 |
300 def display(self): 301 import display 302 p = display.Print() 303 p.name = self.name 304 p.desc = self.desc 305 p.value = float(self) 306 p.flags = self.flags 307 p.precision = self.precision 308 if display.all or (self.flags & flags.printable): 309 p.display() | 234 def __vector__(self): 235 return vector(self.arg0) or vector(self.arg1) |
310 | 236 |
311 def comparable(self, other): 312 return self.name == other.name | 237 def __scalarvalue__(self, run): 238 val0 = value(self.arg0, run) 239 val1 = value(self.arg1, run) 240 if val0 is None or val1 is None: 241 return None 242 return self.op(val0, val1) |
313 | 243 |
314 def __eq__(self, other): 315 return self.value == other.value | 244 def __vectorvalue__(self, run, index): 245 if scalar(self.arg0): 246 val0 = value(self.arg0, run) 247 if vector(self.arg0): 248 val0 = value(self.arg0, run, index) 249 if scalar(self.arg1): 250 val1 = value(self.arg1, run) 251 if vector(self.arg1): 252 val1 = value(self.arg1, run, index) |
316 | 253 |
317 def __isub__(self, other): 318 self.value -= other.value 319 return self | 254 if val0 is None or val1 is None: 255 return None |
320 | 256 |
321 def __iadd__(self, other): 322 self.value += other.value 323 return self | 257 return self.op(val0, val1) |
324 | 258 |
325 def __itruediv__(self, other): 326 if not other: 327 return self 328 self.value /= other 329 return self | 259 def __vectorlen__(self): 260 if vector(self.arg0) and scalar(self.arg1): 261 return len(self.arg0) 262 if scalar(self.arg0) and vector(self.arg1): 263 return len(self.arg1) |
330 | 264 |
331class Vector(Statistic,FormulaStat): 332 def getValue(self): 333 return source.data(self, self.bins, self.ticks); | 265 len0 = len(self.arg0) 266 len1 = len(self.arg1) |
334 | 267 |
335 def display(self): 336 import display 337 if not display.all and not (self.flags & flags.printable): 338 return | 268 if len0 != len1: 269 raise AttributeError, \ 270 "vectors of different lengths %d != %d" % (len0, len1) |
339 | 271 |
340 d = display.VectorDisplay() 341 d.__dict__.update(self.__dict__) 342 d.display() | 272 return len0 |
343 | 273 |
344 def comparable(self, other): 345 return self.name == other.name and \ 346 len(self.value) == len(other.value) | 274class Proxy(Value): 275 def __init__(self, name, dict): 276 self.name = name 277 self.dict = dict |
347 | 278 |
348 def __eq__(self, other): 349 if isinstance(self.value, (list, tuple)) != \ 350 isinstance(other.value, (list, tuple)): 351 return False | 279 def __unproxy__(self): 280 return unproxy(self.dict[self.name]) |
352 | 281 |
353 if isinstance(self.value, (list, tuple)): 354 if len(self.value) != len(other.value): 355 return False 356 else: 357 for v1,v2 in zip(self.value, other.value): 358 if v1 != v2: 359 return False 360 return True 361 else: 362 return self.value == other.value | 282 def __getitem__(self, index): 283 return ItemProxy(self, index) |
363 | 284 |
364 def __isub__(self, other): 365 self.value = binaryop(operator.sub, self.value, other.value) 366 return self | 285 def __getattr__(self, attr): 286 return AttrProxy(self, attr) |
367 | 287 |
368 def __iadd__(self, other): 369 self.value = binaryop(operator.add, self.value, other.value) 370 return self | 288class ItemProxy(Proxy): 289 def __init__(self, proxy, index): 290 self.proxy = proxy 291 self.index = index |
371 | 292 |
372 def __itruediv__(self, other): 373 if not other: 374 return self 375 if isinstance(self.value, (list, tuple)): 376 for i in xrange(len(self.value)): 377 self.value[i] /= other 378 else: 379 self.value /= other 380 return self | 293 def __unproxy__(self): 294 return unproxy(unproxy(self.proxy)[self.index]) |
381 | 295 |
382class Formula(Vector): 383 def getValue(self): 384 formula = re.sub(':', '__', self.formula) 385 x = eval(formula, source.stattop) 386 return x.value | 296class AttrProxy(Proxy): 297 def __init__(self, proxy, attr): 298 self.proxy = proxy 299 self.attr = attr |
387 | 300 |
388 def comparable(self, other): 389 return self.name == other.name and \ 390 compare(self.dist, other.dist) | 301 def __unproxy__(self): 302 return unproxy(getattr(unproxy(self.proxy), self.attr)) |
391 | 303 |
392 def __eq__(self, other): 393 return self.value == other.value | 304class ProxyGroup(object): 305 def __init__(self, dict=None, **kwargs): 306 self.__dict__['dict'] = {} |
394 | 307 |
395 def __isub__(self, other): 396 return self | 308 if dict is not None: 309 self.dict.update(dict) |
397 | 310 |
398 def __iadd__(self, other): 399 return self | 311 if kwargs: 312 self.dict.update(kwargs) |
400 | 313 |
401 def __itruediv__(self, other): 402 if not other: 403 return self 404 return self | 314 def __getattr__(self, name): 315 return Proxy(name, self.dict) |
405 | 316 |
406class SimpleDist(object): | 317 def __setattr__(self, attr, value): 318 self.dict[attr] = value 319 320class ScalarStat(Statistic,Scalar): 321 def __value__(self, run): 322 if run not in self.data: 323 return None 324 return self.data[run][0][0] 325 326 def display(self, run=None): 327 import display 328 p = display.Print() 329 p.name = self.name 330 p.desc = self.desc 331 p.value = value(self, run) 332 p.flags = self.flags 333 p.precision = self.precision 334 if display.all or (self.flags & flags.printable): 335 p.display() 336 337class VectorStat(Statistic,Vector): 338 def __value__(self, run, item): 339 if run not in self.data: 340 return None 341 return self.data[run][item][0] 342 343 def __len__(self): 344 return self.x 345 346 def display(self, run=None): 347 import display 348 d = display.VectorDisplay() 349 d.name = self.name 350 d.desc = self.desc 351 d.value = [ value(self, run, i) for i in xrange(len(self)) ] 352 d.flags = self.flags 353 d.precision = self.precision 354 d.display() 355 356class Formula(Value): 357 def __getattribute__(self, attr): 358 if attr not in ( '__scalar__', '__vector__', '__value__', '__len__' ): 359 return super(Formula, self).__getattribute__(attr) 360 361 formula = re.sub(':', '__', self.formula) 362 value = eval(formula, self.source.stattop) 363 return getattr(value, attr) 364 365class SimpleDist(Statistic): |
407 def __init__(self, sums, squares, samples): 408 self.sums = sums 409 self.squares = squares 410 self.samples = samples 411 | 366 def __init__(self, sums, squares, samples): 367 self.sums = sums 368 self.squares = squares 369 self.samples = samples 370 |
412 def getValue(self): 413 return 0.0 414 | |
415 def display(self, name, desc, flags, precision): 416 import display 417 p = display.Print() 418 p.flags = flags 419 p.precision = precision 420 421 if self.samples > 0: 422 p.name = name + ".mean" --- 54 unchanged lines hidden (view full) --- 477 self.under = under 478 self.vec = vec 479 self.over = over 480 self.min = min 481 self.max = max 482 self.bsize = bsize 483 self.size = size 484 | 371 def display(self, name, desc, flags, precision): 372 import display 373 p = display.Print() 374 p.flags = flags 375 p.precision = precision 376 377 if self.samples > 0: 378 p.name = name + ".mean" --- 54 unchanged lines hidden (view full) --- 433 self.under = under 434 self.vec = vec 435 self.over = over 436 self.min = min 437 self.max = max 438 self.bsize = bsize 439 self.size = size 440 |
485 def getValue(self): 486 return 0.0 487 | |
488 def display(self, name, desc, flags, precision): 489 import display 490 p = display.Print() 491 p.flags = flags 492 p.precision = precision 493 494 p.name = name + '.min_val' 495 p.value = self.minval --- 73 unchanged lines hidden (view full) --- 569 if self.samples: 570 self.under /= other 571 for i in xrange(len(self.vec)): 572 self.vec[i] /= other 573 self.over /= other 574 return self 575 576class Dist(Statistic): | 441 def display(self, name, desc, flags, precision): 442 import display 443 p = display.Print() 444 p.flags = flags 445 p.precision = precision 446 447 p.name = name + '.min_val' 448 p.value = self.minval --- 73 unchanged lines hidden (view full) --- 522 if self.samples: 523 self.under /= other 524 for i in xrange(len(self.vec)): 525 self.vec[i] /= other 526 self.over /= other 527 return self 528 529class Dist(Statistic): |
577 def getValue(self): 578 return 0.0 579 | |
580 def display(self): 581 import display 582 if not display.all and not (self.flags & flags.printable): 583 return 584 585 self.dist.display(self.name, self.desc, self.flags, self.precision) 586 587 def comparable(self, other): --- 13 unchanged lines hidden (view full) --- 601 602 def __itruediv__(self, other): 603 if not other: 604 return self 605 self.dist /= other 606 return self 607 608class VectorDist(Statistic): | 530 def display(self): 531 import display 532 if not display.all and not (self.flags & flags.printable): 533 return 534 535 self.dist.display(self.name, self.desc, self.flags, self.precision) 536 537 def comparable(self, other): --- 13 unchanged lines hidden (view full) --- 551 552 def __itruediv__(self, other): 553 if not other: 554 return self 555 self.dist /= other 556 return self 557 558class VectorDist(Statistic): |
609 def getValue(self): 610 return 0.0 611 | |
612 def display(self): 613 import display 614 if not display.all and not (self.flags & flags.printable): 615 return 616 617 if isinstance(self.dist, SimpleDist): 618 return 619 --- 69 unchanged lines hidden (view full) --- 689 if isinstance(self.dist, (list, tuple)): 690 for dist in self.dist: 691 dist /= other 692 else: 693 self.dist /= other 694 return self 695 696class Vector2d(Statistic): | 559 def display(self): 560 import display 561 if not display.all and not (self.flags & flags.printable): 562 return 563 564 if isinstance(self.dist, SimpleDist): 565 return 566 --- 69 unchanged lines hidden (view full) --- 636 if isinstance(self.dist, (list, tuple)): 637 for dist in self.dist: 638 dist /= other 639 else: 640 self.dist /= other 641 return self 642 643class Vector2d(Statistic): |
697 def getValue(self): 698 return 0.0 699 | |
700 def display(self): 701 import display 702 if not display.all and not (self.flags & flags.printable): 703 return 704 705 d = display.VectorDisplay() 706 d.__dict__.update(self.__dict__) 707 --- 35 unchanged lines hidden (view full) --- 743 def __iadd__(self, other): 744 return self 745 746 def __itruediv__(self, other): 747 if not other: 748 return self 749 return self 750 | 644 def display(self): 645 import display 646 if not display.all and not (self.flags & flags.printable): 647 return 648 649 d = display.VectorDisplay() 650 d.__dict__.update(self.__dict__) 651 --- 35 unchanged lines hidden (view full) --- 687 def __iadd__(self, other): 688 return self 689 690 def __itruediv__(self, other): 691 if not other: 692 return self 693 return self 694 |
751def NewStat(data): | 695def NewStat(source, data): |
752 stat = None 753 if data.type == 'SCALAR': | 696 stat = None 697 if data.type == 'SCALAR': |
754 stat = Scalar(data) | 698 stat = ScalarStat() |
755 elif data.type == 'VECTOR': | 699 elif data.type == 'VECTOR': |
756 stat = Vector(data) | 700 stat = VectorStat() |
757 elif data.type == 'DIST': | 701 elif data.type == 'DIST': |
758 stat = Dist(data) | 702 stat = Dist() |
759 elif data.type == 'VECTORDIST': | 703 elif data.type == 'VECTORDIST': |
760 stat = VectorDist(data) | 704 stat = VectorDist() |
761 elif data.type == 'VECTOR2D': | 705 elif data.type == 'VECTOR2D': |
762 stat = Vector2d(data) | 706 stat = Vector2d() |
763 elif data.type == 'FORMULA': | 707 elif data.type == 'FORMULA': |
764 stat = Formula(data) | 708 stat = Formula() |
765 | 709 |
710 stat.__dict__['source'] = source 711 stat.__dict__['bins'] = None 712 stat.__dict__['ticks'] = None 713 stat.__dict__.update(data.__dict__) 714 |
|
766 return stat 767 | 715 return stat 716 |