def asFile( self, dataframe, row_headers, col_headers, title ): '''save the table as HTML file. Multiple files of the same Renderer/Tracker combination are distinguished by the title. ''' self.debug("%s: saving %i x %i table as file'"% (id(self), len(row_headers), len(col_headers))) lines = [] lines.append("`%i x %i table <#$html %s$#>`__" %\ (len(row_headers), len(col_headers), title) ) r = ResultBlock( "\n".join(lines) + "\n", title = title) out = StringIO.StringIO() dataframe.to_csv( out ) lines = out.getvalue().split("\n") # create an html table data = ["<table>"] data.append( "<tr><th></th><th>%s</th></tr>" % "</th><th>".join( map(str,lines[0].split(","))) ) data.extend( ["<tr><td>%s</td></tr>" % \ ("</td><td>".join(x.split(","))) for x in lines[1:]] ) data.append( "</table>\n" ) # substitute links data = [ re.sub("`(.*?(?:\".+\"|\'.+\')?.*?)\s<(.*?(?:\".+\"|\'.+\')?.*?)>`_", r'<a href="\2">\1</a>', x) \ for x in data ] r.html = "\n".join( data ) return r
def asFile( self, matrix, row_headers, col_headers, title ): '''save the table as HTML file. Multiple files of the same Renderer/Tracker combination are distinguished by the title. ''' self.debug("%s: saving %i x %i table as file'"% (id(self), len(row_headers), len(col_headers))) lines = [] lines.append("`%i x %i table <#$html %s$#>`__" %\ (len(row_headers), len(col_headers), title) ) r = ResultBlock( "\n".join(lines), title = title) # create an html table data = ["<table>"] data.append( "<tr><th></th><th>%s</th></tr>" % "</th><th>".join( map(str,col_headers)) ) for h, row in zip( row_headers, matrix): data.append( "<tr><th>%s</th><td>%s</td></tr>" % (h, "</td><td>".join(map(str,row)) )) data.append( "</table>\n" ) r.html = "\n".join( data ) return ResultBlocks( r )