genhtml: Almost finished axis changing
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 8 Dec 2010 22:43:47 +0000 (23:43 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 8 Dec 2010 22:43:47 +0000 (23:43 +0100)
gw-tests/genhtml/genhtml-test.py
gw-tests/genhtml/genhtml.py
gw-tests/lib.sh

index 7d77fba..2e7aaa3 100644 (file)
@@ -12,7 +12,7 @@ def Dimension_and_DimValue():
         l.append(v.value)
     lsorted = ['2.6.30', '2.6.31']
     WVPASSEQ(l, lsorted)
-    WVPASSEQ(v.htmlLabel(), '2.6.31')
+    WVPASSEQ(v.htmlTableHeading(), '2.6.31')
     WVPASSEQ(d['2.6.31'].value, '2.6.31')
     
 @wvtest                
@@ -60,7 +60,7 @@ def Three_Dimensions_in_Tests():
     WVPASSEQ([d.__class__.__name__ for d in t.iterRemainingDimensions([dt])], ['DimensionKern', 'Dimension']) 
     WVPASSEQ([d.__class__.__name__ for d in t.iterRemainingDimensions([dt, dd])], ['DimensionKern'])
 
-    WVPASSEQ(str([v for v in iterDimValues([dt, dk])]), str([[1,'a']]))
+    WVPASSEQ(str([v for v in iterDimValues([dt, dk])]), "[[DimValue(DimensionTest, 1), DimValue(DimensionKern, 'a')]]")
     dt.addValue(2)
     dk.addValue('b')
-    WVPASSEQ(str([v for v in iterDimValues([dt, dk])]), str([[1, 'a'], [2, 'a'], [1, 'b'], [2, 'b']]))
+    WVPASSEQ(str([v for v in iterDimValues([dt, dk])]), "[[DimValue(DimensionTest, 1), DimValue(DimensionKern, 'a')], [DimValue(DimensionTest, 2), DimValue(DimensionKern, 'a')], [DimValue(DimensionTest, 1), DimValue(DimensionKern, 'b')], [DimValue(DimensionTest, 2), DimValue(DimensionKern, 'b')]]")
index 3bc059c..5dacc9e 100755 (executable)
@@ -10,17 +10,26 @@ class DimValue:
        self.dim = dim
        self.value = value
     def __str__(self):
-        return str(self.value)
+        return self.dim.val2str(self.value)
     def __repr__(self):
-       return repr(self.value)
-    def htmlLabel(self):
-       return self.dim.htmlLabel(self.value)
+       return "DimValue("+str(self.dim.__class__.__name__) + ", "+repr(self.value)+")"
+    def htmlTableHeading(self):
+       return self.dim.htmlTableHeading(self.value)
 
 class DimValues(list):
     def replace(self, val):
         for i in xrange(len(self)):
             if self[i].dim == val.dim:
                 self[i] = val
+    def __add__(self, val):
+        return DimValues(self).append(val)
+    def __sub__(self, dim):
+        result = DimValues(self)
+        print repr(result)
+        for v in self:
+            if v.dim == dim:
+                result.remove(v)
+        return result
 
 class Dimension(dict):
     def __init__(self, atype, name=None):
@@ -29,19 +38,25 @@ class Dimension(dict):
            self.name = name
        else:
            self.name = atype
+        self.sortedKeys = []
 
     def __iter__(self):
-       keys = self.keys()
-       keys.sort()
-       for k in keys:
-           yield self[k]
+       for i in xrange(len(self)):
+           yield self.getValue(i)
+    def getValue(self, index):
+        print self.sortedKeys
+        return self[self.sortedKeys[index]]
 
     def addValue(self, *values):
        for value in values:
            if value not in self:
                self[value] = DimValue(self, value)
-    def htmlLabel(self, v):
-       return v
+       self.sortedKeys = self.keys()
+       self.sortedKeys.sort()
+    def val2str(self, v):
+        return str(v)
+    def htmlTableHeading(self, v):
+       return self.val2str(v)
     def __str__(self):
         return self.name
     def __repr__(self):
@@ -50,7 +65,7 @@ class Dimension(dict):
 class DimensionKern(Dimension):
     def __init__(self):
        Dimension.__init__(self, 'gwkern', 'GW kernel')
-    def htmlLabel(self, v):
+    def htmlTableHeading(self, v):
        i=v.find(":")
        if i>0: kver=v[:i]
        else: kver=v
@@ -65,10 +80,12 @@ class DimensionKern(Dimension):
 class DimensionHostKern(Dimension):
     def __init__(self):
        Dimension.__init__(self, 'hostkern', 'Host kernel')
-    def htmlLabel(self, v):
+    def val2str(self, v):
         if v.find("host-") == 0:
             v = v[5:]
-        # TODO: remove host- prefix
+        return v
+    def htmlTableHeading(self, v):
+        v = self.val2str(v)
        i = v.find(":")
        if i>0: kver = v[:i]
         else: kver = v
@@ -83,15 +100,21 @@ class DimensionHostKern(Dimension):
 class DimensionTest(Dimension):
     def __init__(self):
        Dimension.__init__(self, 'test', 'Test')
-    def htmlLabel(self, v):
+    def htmlTableHeading(self, v):
        return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
 
 class DimensionTraffic(Dimension):
     def __init__(self):
        Dimension.__init__(self, 'traf', 'Traffic')
-    def htmlLabel(self, v):
-       return v
-
+    def val2str(self, v):
+        if v == "50":
+            return "50%"
+        elif v == "oneatatime":
+            return "one message at a time"
+        else:
+            return v
+    def htmlTableHeading(self, v):
+        return self.val2str(v)
 class Test:
     @classmethod
     def isOnPath(cls, path):
@@ -99,9 +122,14 @@ class Test:
        return os.path.isfile(f)
     def __init__(self, path):
        self.path = path
+        self.name = os.path.basename(path)
     def printThumbLink(self, file):
         thumb = self.path+'/thumb'
-        for img in dircache.listdir(thumb):
+        try:
+            imgs = [img for img in dircache.listdir(thumb)]
+        except OSError:
+            imgs = [ self.name + ".png" ]
+        for img in imgs:
             print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
                   (urllib.quote(self.path), img, urllib.quote(self.path), img)
 
@@ -201,8 +229,14 @@ th, td { border: 1px solid lightgray; padding: 4px;}
 </head>
 <body>
 <h1>%s</h1>"""  % (title, title)
+        params = ["%s %s" % (v.dim, v) for v in self.valsOther]
+        print >>html, "Results for:", ", ".join(params), "<hr />"
        for d in self.dimOther:
             print >>html, "%s: " % d
+            print >>html, "<a href='%s'>X axis</a>, " % \
+                self.getName(dimx=d,
+                             valsOther=self.valsOther - d + self.dimx.getValue(0))
+            print >>html, "<a href='%s'>Y axis</a>;&nbsp;&nbsp;" % self.getName(dimy=d)
             links = []
             for v in d.values():
                 if v in self.valsOther:
@@ -218,12 +252,12 @@ th, td { border: 1px solid lightgray; padding: 4px;}
             except Exception:
                 pass
 
-       print >>html, "<table><thead><tr><td> </td>"
+       print >>html, "<table><thead><tr><td>%s &rarr; <br />%s &darr;</td>" % (self.dimx.name, self.dimy.name)
        for x in self.dimx:
-           print >>html, "<th>%s</th>" % x.htmlLabel()
+           print >>html, "<th>%s</th>" % x.htmlTableHeading()
        print >>html, "</tr></thead>"
        for y in self.dimy:
-           print >>html, "<tr><th>%s</th>" % y.htmlLabel()
+           print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
 
            for x in self.dimx:
                print >>html, "<td>"
@@ -231,10 +265,7 @@ th, td { border: 1px solid lightgray; padding: 4px;}
                idx.extend(self.valsOther)
                 try:
                     test = tests.getTest(idx)
-                    try:
-                        test.printThumbLink(html)
-                    except OSError:
-                        print >>html, "No thumbnail :-("
+                    test.printThumbLink(html)
                 except KeyError:
                     print >>html, "N/A"
                 print >>html, "</td>"
index b571996..4c4274d 100644 (file)
@@ -128,7 +128,7 @@ _run() {
        if [[ ! "$OPT_PLOT_DISABLE" ]]; then
            _plot
        fi
-       cd -
+       cd - > /dev/null
     done
 }