test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
html.Page Class Reference
Inheritance diagram for html.Page:
html.TrackingIterPage

Public Member Functions

def __init__
 
def addPlotSet
 
def addTable
 
def isEmpty
 
def write
 

Private Member Functions

def _appendColumnHeader
 
def _appendLegend
 
def _formatLegend
 
def _formatPlotSets
 
def _formatTables
 
def _mapSectionName
 
def _orderSets
 

Private Attributes

 _columnHeaders
 
 _columnHeadersIndex
 
 _content
 
 _legends
 
 _plotSets
 
 _sectionLegendIndex
 
 _tables
 

Detailed Description

Definition at line 228 of file html.py.

Constructor & Destructor Documentation

def html.Page.__init__ (   self,
  title,
  sampleName 
)

Definition at line 229 of file html.py.

230  def __init__(self, title, sampleName):
231  self._content = [
232  '<html>',
233  ' <head>',
234  ' <title>%s</title>' % title,
235  ' </head>',
236  ' <body>',
237  ' '+sampleName,
238  ' <br/>',
239  ' <br/>',
240  ]
242  self._plotSets = {}
243  self._tables = {}
_content
Definition: html.py:230
_plotSets
Definition: html.py:241
def __init__
Definition: html.py:229
_tables
Definition: html.py:242

Member Function Documentation

def html.Page._appendColumnHeader (   self,
  header 
)
private

Definition at line 343 of file html.py.

References html.Table._columnHeaders, html.Page._columnHeaders, and html.Page._columnHeadersIndex.

Referenced by html.Page._formatTables().

344  def _appendColumnHeader(self, header):
345  leg = ""
346  if header in self._columnHeadersIndex:
347  leg = self._columnHeadersIndex[header]
348  else:
349  leg = str(chr(ord('A')+len(self._columnHeaders)))
350  self._columnHeaders.append("%s: %s" % (leg, header))
351  self._columnHeadersIndex[header] = leg
352  return leg
_columnHeaders
Definition: html.py:263
_columnHeadersIndex
Definition: html.py:264
def _appendColumnHeader
Definition: html.py:343
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 281 of file html.py.

References html.Page._legends, html.Page._sectionLegendIndex, and html._sectionNameLegend().

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

282  def _appendLegend(self, section):
283  leg = ""
284  legends = _sectionNameLegend()
285  if section in legends:
286  if section in self._sectionLegendIndex:
287  leg = self._sectionLegendIndex[section]
288  else:
289  legnum = len(self._legends)+1
290  leg = "<sup>%d</sup>" % legnum
291  leg2 = "<sup>%d)</sup>" % legnum
292  self._legends.append("%s %s" % (leg2, legends[section]))
293  self._sectionLegendIndex[section] = leg
294  return leg
_legends
Definition: html.py:261
def _sectionNameLegend
Definition: html.py:153
def _appendLegend
Definition: html.py:281
_sectionLegendIndex
Definition: html.py:262
def html.Page._formatLegend (   self)
private

Definition at line 407 of file html.py.

References html.Page._legends.

408  def _formatLegend(self):
409  if len(self._legends) > 0:
410  self._content.extend([
411  ' <br/>'
412  ' Details:</br>',
413  ])
414  for leg in self._legends:
415  self._content.append(' %s<br/>' % leg)
416 
_legends
Definition: html.py:261
def _formatLegend
Definition: html.py:407
def html.Page._formatPlotSets (   self)
private

Definition at line 295 of file html.py.

References html.Page._appendLegend(), html.Page._mapSectionName(), html.Page._orderSets(), and html.Page._plotSets.

296  def _formatPlotSets(self):
297  self._content.extend([
298  ' <table>'
299  ' <tr>',
300  ])
301 
302  fileTable = []
303 
304  sections = self._orderSets(self._plotSets.keys())
305  for isec, section in enumerate(sections):
306  leg = self._appendLegend(section)
307 
308  self._content.extend([
309  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
310  ])
311  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
312  for row in fileTable:
313  found = False
314  for i, (bsf, f) in enumerate(files):
315  if bsf == row[0]:
316  row.append(f)
317  found = True
318  del files[i]
319  break
320  if not found:
321  row.append(None)
322  for bsf, f in files:
323  fileTable.append( [bsf] + [None]*isec + [f] )
324 
325  self._content.extend([
326  ' </tr>',
327  ])
328 
329  for row in fileTable:
330  self._content.append(' <tr>')
331  bs = row[0]
332  for elem in row[1:]:
333  if elem is not None:
334  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
335  else:
336  self._content.append(' <td></td>')
337  self._content.append(' </tr>')
338 
339 
340  self._content.extend([
341  ' </table>',
342  ])
def _formatPlotSets
Definition: html.py:295
def _orderSets
Definition: html.py:420
_plotSets
Definition: html.py:241
def _appendLegend
Definition: html.py:281
def _mapSectionName
Definition: html.py:417
def html.Page._formatTables (   self)
private

Definition at line 353 of file html.py.

References html.Page._appendColumnHeader(), html.Page._appendLegend(), html.Table._columnHeaders, html.Page._columnHeaders, html.Page._columnHeadersIndex, html.Page._mapSectionName(), html.Page._orderSets(), html.Page._tables, and bookConverter.max.

354  def _formatTables(self):
355  def _allNone(row):
356  for item in row:
357  if item is not None:
358  return False
359  return True
360 
361  sections = self._orderSets(self._tables.keys())
362  for isec, section in enumerate(sections):
363  leg = self._appendLegend(section)
364 
365  table = self._tables[section]
366  self._content.extend([
367  ' <br/>',
368  ' %s%s' % (self._mapSectionName(section), leg),
369  ' <table border="1">'
370  ])
371 
372  # table is stored in column-row, need to transpose
373  data = table.tableAsRowColumn()
374 
375  self._content.extend([
376  ' <tr>'
377  ' <td></td>'
378  ])
379  heads = table.columnHeaders()
380  if max(map(lambda h: len(h), heads)) > 20:
381  heads = [self._appendColumnHeader(h) for h in heads]
382  for head in heads:
383  self._content.append(' <td>%s</td>' % head)
384  self._content.append(' </tr>')
385 
386  for irow, row in enumerate(data):
387  # Skip row if all values are non-existent
388  if _allNone(row):
389  continue
390 
391  self._content.extend([
392  ' <tr>'
393  ' <td>%s</td>' % table.rowHeaders()[irow]
394  ])
395  # align the number columns to right
396  for icol, item in enumerate(row):
397  formatted = str(item) if item is not None else ""
398  self._content.append(' <td align="right">%s</td>' % formatted)
399  self._content.append(' </tr>')
400 
401  self._content.append(' </table>')
402 
403  for shortenedColumnHeader in self._columnHeaders:
404  self._content.append(' %s<br/>' % shortenedColumnHeader)
405  self._columnHeaders = []
406  self._columnHeadersIndex = {}
def _formatTables
Definition: html.py:353
_columnHeaders
Definition: html.py:263
def _orderSets
Definition: html.py:420
def _appendLegend
Definition: html.py:281
_columnHeadersIndex
Definition: html.py:264
def _mapSectionName
Definition: html.py:417
_tables
Definition: html.py:242
def _appendColumnHeader
Definition: html.py:343
def html.Page._mapSectionName (   self,
  section 
)
private

Definition at line 417 of file html.py.

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

418  def _mapSectionName(self, section):
419  return _sectionNameMapOrder.get(section, section)
def _mapSectionName
Definition: html.py:417
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 420 of file html.py.

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

421  def _orderSets(self, keys):
422  ret = []
423  for section in _sectionNameMapOrder.keys():
424  if section in keys:
425  ret.append(section)
426  keys.remove(section)
427  ret.extend(keys)
428  return ret
def _orderSets
Definition: html.py:420
def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 244 of file html.py.

References html.Page._plotSets.

245  def addPlotSet(self, section, plotSet):
246  self._plotSets[section] = plotSet
def addPlotSet
Definition: html.py:244
_plotSets
Definition: html.py:241
def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 247 of file html.py.

References html.Page._tables.

248  def addTable(self, section, table):
249  self._tables[section] = table
_tables
Definition: html.py:242
def addTable
Definition: html.py:247
def html.Page.isEmpty (   self)

Definition at line 250 of file html.py.

References html.Page._tables.

251  def isEmpty(self):
252  for plotSet in self._plotSets.itervalues():
253  if len(plotSet) > 0:
254  return False
255 
256  if len(self._tables) > 0:
257  return False
258 
259  return True
_tables
Definition: html.py:242
def isEmpty
Definition: html.py:250
def html.Page.write (   self,
  fileName 
)

Definition at line 260 of file html.py.

261  def write(self, fileName):
262  self._legends = []
264  self._columnHeaders = []
265  self._columnHeadersIndex = {}
266  self._formatPlotSets()
267  self._formatTables()
268  self._formatLegend()
269 
270  self._content.extend([
271  ' </body>',
272  '</html>',
273  ])
274 
275  #print "Writing HTML report page", fileName
276  f = open(fileName, "w")
277  for line in self._content:
278  f.write(line)
279  f.write("\n")
280  f.close()
def _formatPlotSets
Definition: html.py:295
_legends
Definition: html.py:261
_content
Definition: html.py:230
def _formatTables
Definition: html.py:353
def _formatLegend
Definition: html.py:407
_columnHeaders
Definition: html.py:263
def write
Definition: html.py:260
_columnHeadersIndex
Definition: html.py:264
_sectionLegendIndex
Definition: html.py:262

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 263 of file html.py.

Referenced by html.Page._appendColumnHeader(), and html.Page._formatTables().

html.Page._columnHeadersIndex
private

Definition at line 264 of file html.py.

Referenced by html.Page._appendColumnHeader(), and html.Page._formatTables().

html.Page._content
private

Definition at line 230 of file html.py.

html.Page._legends
private

Definition at line 261 of file html.py.

Referenced by html.Page._appendLegend(), and html.Page._formatLegend().

html.Page._plotSets
private

Definition at line 241 of file html.py.

Referenced by html.Page._formatPlotSets(), and html.Page.addPlotSet().

html.Page._sectionLegendIndex
private

Definition at line 262 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 242 of file html.py.

Referenced by html.Page._formatTables(), html.Page.addTable(), and html.Page.isEmpty().