2 # -*- coding: utf-8 -*-
9 def __init__(self, dim, value):
13 return self.dim.val2str(self.value)
15 return "DimValue("+str(self.dim.__class__.__name__) + ", "+repr(self.value)+")"
16 def htmlTableHeading(self):
17 return self.dim.htmlTableHeading(self.value)
19 class DimValues(list):
20 def replace(self, val):
21 for i in xrange(len(self)):
22 if self[i].dim == val.dim:
24 def __add__(self, val):
25 return DimValues(self).append(val)
26 def __sub__(self, dim):
27 result = DimValues(self)
34 class Dimension(dict):
35 def __init__(self, atype, name=None):
44 for i in xrange(len(self)):
45 yield self.getValue(i)
46 def getValue(self, index):
48 return self[self.sortedKeys[index]]
50 def addValue(self, *values):
53 self[value] = DimValue(self, value)
54 self.sortedKeys = self.keys()
55 self.sortedKeys.sort()
58 def htmlTableHeading(self, v):
59 return self.val2str(v)
65 class DimensionKern(Dimension):
67 Dimension.__init__(self, 'gwkern', 'GW kernel')
68 def htmlTableHeading(self, v):
72 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
80 class DimensionHostKern(Dimension):
82 Dimension.__init__(self, 'hostkern', 'Host kernel')
84 if v.find("host-") == 0:
87 def htmlTableHeading(self, v):
92 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
100 class DimensionTest(Dimension):
102 Dimension.__init__(self, 'test', 'Test')
103 def htmlTableHeading(self, v):
104 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
106 class DimensionTraffic(Dimension):
108 Dimension.__init__(self, 'traf', 'Traffic')
109 def val2str(self, v):
112 elif v == "oneatatime":
113 return "one message at a time"
116 def htmlTableHeading(self, v):
117 return self.val2str(v)
120 def isOnPath(cls, path):
121 f = os.path.join(path, '.results')
122 return os.path.isfile(f)
123 def __init__(self, path):
125 self.name = os.path.basename(path)
126 def printThumbLink(self, file):
127 thumb = self.path+'/thumb'
129 imgs = [img for img in dircache.listdir(thumb)]
131 imgs = [ self.name + ".png" ]
133 print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
134 (urllib.quote(self.path), img, urllib.quote(self.path), img)
136 def iterDimValues(dimensions):
137 idx = [0 for i in xrange(len(dimensions))]
141 for i in xrange(len(dimensions)):
142 values.append(dimensions[i].values()[idx[i]])
145 for i in xrange(len(dimensions)):
147 if idx[i] < len(dimensions[i]):
153 """Represents all tests organized along several dimensions"""
154 def __init__(self, rootpath, *dimensions):
156 self.dimensions = dimensions
158 self.populate(rootpath)
159 def getTest(self, key):
161 for d in self.dimensions:
164 realkey.append(i.value)
165 if len(realkey) != len(self.dimensions):
166 raise KeyError("The coordinates in key do not match dimensions")
167 return self[tuple(realkey)]
169 def addTest(self, test, coordinates):
170 if len(coordinates) != len(self.dimensions):
171 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
172 self[tuple(coordinates)] = test
173 for i in xrange(len(coordinates)):
174 self.dimensions[i].addValue(coordinates[i])
176 def populate(self, rootpath):
177 for root, dirs, files in os.walk(rootpath):
178 if (root.find(rootpath) == 0):
179 coordinates = root[len(rootpath):]
181 coordinates = rootpath
182 if Test.isOnPath(root):
183 self.addTest(Test(root), coordinates.split("/"))
184 def iterDimensionPairs(self):
185 for i in xrange(len(self.dimensions)):
186 for j in xrange(i+1, len(self.dimensions)):
187 yield (self.dimensions[i], self.dimensions[j])
188 yield (self.dimensions[j], self.dimensions[i])
189 def iterRemainingDimensions(self, dimensionPair):
190 for d in self.dimensions:
191 if d not in dimensionPair:
193 def generateHtml(self):
194 for pair in self.iterDimensionPairs():
195 remDims = [d for d in self.iterRemainingDimensions(pair)]
196 for vals in iterDimValues(remDims):
197 page = Page(pair, remDims, vals, self)
200 os.remove("index.html")
202 os.symlink(page.getName(), "index.html")
204 #os.system("source-highlight -d --output-dir=. ../*.sh")
207 def __init__(self, dimPair, dimOther, valsOther, tests):
208 self.dimy, self.dimx = dimPair
209 self.dimOther = dimOther
210 self.valsOther = valsOther
212 def getName(self, dimy=None, dimx=None, valsOther=None):
213 return "%s-vs-%s-for-%s.html"%(dimx or self.dimy.type,
214 dimy or self.dimx.type,
215 "-".join([v.value for v in valsOther or self.valsOther]))
217 html = open(self.getName(), "w")
218 title = "CAN gateway timing analysis"
219 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
220 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
222 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
226 table { border-collapse: collapse; }
227 th, td { border: 1px solid lightgray; padding: 4px;}
231 <h1>%s</h1>""" % (title, title)
232 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
233 print >>html, "Results for:", ", ".join(params), "<hr />"
234 for d in self.dimOther:
235 print >>html, "%s: " % d
236 print >>html, "<a href='%s'>X axis</a>, " % \
238 valsOther=self.valsOther - d + self.dimx.getValue(0))
239 print >>html, "<a href='%s'>Y axis</a>; " % self.getName(dimy=d)
242 if v in self.valsOther:
245 vv = DimValues(self.valsOther)
247 links.append("<a href='%s'>%s</a>"%(urllib.quote(self.getName(valsOther=vv)), str(v)))
248 print >>html, " | ".join(links)
251 print >>html, d.htmlPreamble()
255 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
257 print >>html, "<th>%s</th>" % x.htmlTableHeading()
258 print >>html, "</tr></thead>"
260 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
265 idx.extend(self.valsOther)
267 test = tests.getTest(idx)
268 test.printThumbLink(html)
271 print >>html, "</td>"
272 print >>html, "</tr>"
275 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
280 if __name__ == "__main__":
281 os.chdir(sys.argv[1])
282 os.system("rm *.html")
283 tests = Tests("./", DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest())