display.py (1772:a3a83e812a5e) display.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

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

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
27class Value:
28 def __init__(self, value, precision, percent = False):
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

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

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
27class Value:
28 def __init__(self, value, precision, percent = False):
29 self.value = value
29 self.value = float(value)
30 self.precision = precision
31 self.percent = percent
32 def __str__(self):
33 if isinstance(self.value, str):
34 if self.value.lower() == 'nan':
35 value = 'NaN'
36 if self.value.lower() == 'inf':
37 value = 'Inf'

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

85 return True
86
87 def display(self):
88 if self.doprint():
89 print self
90
91class VectorDisplay:
92 def display(self):
30 self.precision = precision
31 self.percent = percent
32 def __str__(self):
33 if isinstance(self.value, str):
34 if self.value.lower() == 'nan':
35 value = 'NaN'
36 if self.value.lower() == 'inf':
37 value = 'Inf'

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

85 return True
86
87 def display(self):
88 if self.doprint():
89 print self
90
91class VectorDisplay:
92 def display(self):
93 if not self.value:
94 return
95
93 p = Print()
94 p.flags = self.flags
95 p.precision = self.precision
96
96 p = Print()
97 p.flags = self.flags
98 p.precision = self.precision
99
97 if isinstance(self.value, (list, tuple)):
98 if not len(self.value):
99 return
100 if not isinstance(self.value, (list, tuple)):
101 p.name = self.name
102 p.desc = self.desc
103 p.value = self.value
104 p.display()
105 return
100
106
101 mytotal = reduce(lambda x,y: float(x) + float(y), self.value)
102 mycdf = 0.0
107 mytotal = reduce(lambda x,y: float(x) + float(y), self.value)
108 mycdf = 0.0
103
109
104 value = self.value
110 value = self.value
105
111
106 if display_all:
107 subnames = [ '[%d]' % i for i in range(len(value)) ]
108 else:
109 subnames = [''] * len(value)
112 if display_all:
113 subnames = [ '[%d]' % i for i in range(len(value)) ]
114 else:
115 subnames = [''] * len(value)
110
116
111 if self.__dict__.has_key('subnames'):
112 for i,each in enumerate(self.subnames):
113 if len(each) > 0:
114 subnames[i] = '.%s' % each
117 if self.__dict__.has_key('subnames'):
118 for i,each in enumerate(self.subnames):
119 if len(each) > 0:
120 subnames[i] = '.%s' % each
115
121
116 subdescs = [self.desc]*len(value)
117 if self.__dict__.has_key('subdescs'):
118 for i in xrange(min(len(value), len(self.subdescs))):
119 subdescs[i] = self.subdescs[i]
122 subdescs = [self.desc]*len(value)
123 if self.__dict__.has_key('subdescs'):
124 for i in xrange(min(len(value), len(self.subdescs))):
125 subdescs[i] = self.subdescs[i]
120
126
121 for val,sname,sdesc in map(None, value, subnames, subdescs):
122 if mytotal > 0.0:
123 mypdf = float(val) / float(mytotal)
124 mycdf += mypdf
125 if (self.flags & flags_pdf):
126 p.pdf = mypdf
127 p.cdf = mycdf
127 for val,sname,sdesc in map(None, value, subnames, subdescs):
128 if mytotal > 0.0:
129 mypdf = float(val) / float(mytotal)
130 mycdf += mypdf
131 if (self.flags & flags_pdf):
132 p.pdf = mypdf
133 p.cdf = mycdf
128
134
129 if len(sname) == 0:
130 continue
135 if len(sname) == 0:
136 continue
131
137
132 p.name = self.name + sname
133 p.desc = sdesc
134 p.value = val
135 p.display()
138 p.name = self.name + sname
139 p.desc = sdesc
140 p.value = val
141 p.display()
136
142
137 if (self.flags & flags_total):
138 if (p.__dict__.has_key('pdf')): del p.__dict__['pdf']
139 if (p.__dict__.has_key('cdf')): del p.__dict__['cdf']
140 p.name = self.name + '.total'
141 p.desc = self.desc
142 p.value = mytotal
143 p.display()
144
145 else:
146 p.name = self.name
143 if (self.flags & flags_total):
144 if (p.__dict__.has_key('pdf')): del p.__dict__['pdf']
145 if (p.__dict__.has_key('cdf')): del p.__dict__['cdf']
146 p.name = self.name + '.total'
147 p.desc = self.desc
147 p.desc = self.desc
148 p.value = self.value
148 p.value = mytotal
149 p.display()
149 p.display()
150