CMS 3D CMS Logo

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__ (self, title, sampleName)
 
def addPlotSet (self, section, plotSet)
 
def addTable (self, section, table)
 
def isEmpty (self)
 
def write (self, fileName)
 

Private Member Functions

def _appendColumnHeader (self, header)
 
def _appendLegend (self, section)
 
def _formatLegend (self)
 
def _formatPlotSets (self)
 
def _formatTables (self)
 
def _mapSectionName (self, section)
 
def _orderSets (self, keys)
 

Private Attributes

 _columnHeaders
 
 _columnHeadersIndex
 
 _content
 
 _legends
 
 _plotSets
 
 _sectionLegendIndex
 
 _tables
 

Detailed Description

Definition at line 298 of file html.py.

Constructor & Destructor Documentation

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

Definition at line 299 of file html.py.

299  def __init__(self, title, sampleName):
300  self._content = [
301  '<html>',
302  ' <head>',
303  ' <title>%s</title>' % title,
304  ' </head>',
305  ' <body>',
306  ' '+sampleName,
307  ' <br/>',
308  ' <br/>',
309  ]
310 
311  self._plotSets = {}
312  self._tables = {}
313 
_content
Definition: html.py:300
def __init__(self, title, sampleName)
Definition: html.py:299
_plotSets
Definition: html.py:311
_tables
Definition: html.py:312

Member Function Documentation

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

Definition at line 416 of file html.py.

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

Referenced by html.Page._formatTables().

416  def _appendColumnHeader(self, header):
417  leg = ""
418  if header in self._columnHeadersIndex:
419  leg = self._columnHeadersIndex[header]
420  else:
421  leg = str(chr(ord('A')+len(self._columnHeaders)))
422  self._columnHeaders.append("%s: %s" % (leg, header))
423  self._columnHeadersIndex[header] = leg
424  return leg
425 
def _appendColumnHeader(self, header)
Definition: html.py:416
_columnHeaders
Definition: html.py:336
_columnHeadersIndex
Definition: html.py:337
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 354 of file html.py.

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

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

354  def _appendLegend(self, section):
355  leg = ""
356  legends = _sectionNameLegend()
357  if section in legends:
358  if section in self._sectionLegendIndex:
359  leg = self._sectionLegendIndex[section]
360  else:
361  legnum = len(self._legends)+1
362  leg = "<sup>%d</sup>" % legnum
363  leg2 = "<sup>%d)</sup>" % legnum
364  self._legends.append("%s %s" % (leg2, legends[section]))
365  self._sectionLegendIndex[section] = leg
366  return leg
367 
_legends
Definition: html.py:334
def _appendLegend(self, section)
Definition: html.py:354
def _sectionNameLegend()
Definition: html.py:217
_sectionLegendIndex
Definition: html.py:335
def html.Page._formatLegend (   self)
private

Definition at line 480 of file html.py.

References html.Page._legends.

480  def _formatLegend(self):
481  if len(self._legends) > 0:
482  self._content.extend([
483  ' <br/>'
484  ' Details:</br>',
485  ])
486  for leg in self._legends:
487  self._content.append(' %s<br/>' % leg)
488 
489 
_legends
Definition: html.py:334
def _formatLegend(self)
Definition: html.py:480
def html.Page._formatPlotSets (   self)
private

Definition at line 368 of file html.py.

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

368  def _formatPlotSets(self):
369  self._content.extend([
370  ' <table>'
371  ' <tr>',
372  ])
373 
374  fileTable = []
375 
376  sections = self._orderSets(self._plotSets.keys())
377  for isec, section in enumerate(sections):
378  leg = self._appendLegend(section)
379 
380  self._content.extend([
381  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
382  ])
383  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
384  for row in fileTable:
385  found = False
386  for i, (bsf, f) in enumerate(files):
387  if bsf == row[0]:
388  row.append(f)
389  found = True
390  del files[i]
391  break
392  if not found:
393  row.append(None)
394  for bsf, f in files:
395  fileTable.append( [bsf] + [None]*isec + [f] )
396 
397  self._content.extend([
398  ' </tr>',
399  ])
400 
401  for row in fileTable:
402  self._content.append(' <tr>')
403  bs = row[0]
404  for elem in row[1:]:
405  if elem is not None:
406  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
407  else:
408  self._content.append(' <td></td>')
409  self._content.append(' </tr>')
410 
411 
412  self._content.extend([
413  ' </table>',
414  ])
415 
def _orderSets(self, keys)
Definition: html.py:493
def _mapSectionName(self, section)
Definition: html.py:490
def _appendLegend(self, section)
Definition: html.py:354
_plotSets
Definition: html.py:311
def _formatPlotSets(self)
Definition: html.py:368
def html.Page._formatTables (   self)
private

Definition at line 426 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, genParticles_cff.map, hpstanc_transforms.max, and harvestTrackValidationPlots.str.

426  def _formatTables(self):
427  def _allNone(row):
428  for item in row:
429  if item is not None:
430  return False
431  return True
432 
433  sections = self._orderSets(self._tables.keys())
434  for isec, section in enumerate(sections):
435  leg = self._appendLegend(section)
436 
437  table = self._tables[section]
438  self._content.extend([
439  ' <br/>',
440  ' %s%s' % (self._mapSectionName(section), leg),
441  ' <table border="1">'
442  ])
443 
444  # table is stored in column-row, need to transpose
445  data = table.tableAsRowColumn()
446 
447  self._content.extend([
448  ' <tr>'
449  ' <td></td>'
450  ])
451  heads = table.columnHeaders()
452  if max(map(lambda h: len(h), heads)) > 20:
453  heads = [self._appendColumnHeader(h) for h in heads]
454  for head in heads:
455  self._content.append(' <td>%s</td>' % head)
456  self._content.append(' </tr>')
457 
458  for irow, row in enumerate(data):
459  # Skip row if all values are non-existent
460  if _allNone(row):
461  continue
462 
463  self._content.extend([
464  ' <tr>'
465  ' <td>%s</td>' % table.rowHeaders()[irow]
466  ])
467  # align the number columns to right
468  for icol, item in enumerate(row):
469  formatted = str(item) if item is not None else ""
470  self._content.append(' <td align="right">%s</td>' % formatted)
471  self._content.append(' </tr>')
472 
473  self._content.append(' </table>')
474 
475  for shortenedColumnHeader in self._columnHeaders:
476  self._content.append(' %s<br/>' % shortenedColumnHeader)
477  self._columnHeaders = []
478  self._columnHeadersIndex = {}
479 
def _appendColumnHeader(self, header)
Definition: html.py:416
def _orderSets(self, keys)
Definition: html.py:493
def _mapSectionName(self, section)
Definition: html.py:490
def _appendLegend(self, section)
Definition: html.py:354
_columnHeaders
Definition: html.py:336
def _formatTables(self)
Definition: html.py:426
_columnHeadersIndex
Definition: html.py:337
_tables
Definition: html.py:312
def html.Page._mapSectionName (   self,
  section 
)
private

Definition at line 490 of file html.py.

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

490  def _mapSectionName(self, section):
491  return _sectionNameMapOrder.get(section, section)
492 
def _mapSectionName(self, section)
Definition: html.py:490
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 493 of file html.py.

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

493  def _orderSets(self, keys):
494  keys_sorted = sorted(keys)
495  ret = []
496  for section in _sectionNameMapOrder.keys():
497  if section in keys_sorted:
498  ret.append(section)
499  keys_sorted.remove(section)
500  ret.extend(keys_sorted)
501  return ret
502 
def _orderSets(self, keys)
Definition: html.py:493
def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 314 of file html.py.

References html.Page._plotSets.

314  def addPlotSet(self, section, plotSet):
315  if section in self._plotSets:
316  self._plotSets[section].extend(plotSet)
317  else:
318  self._plotSets[section] = plotSet
319 
def addPlotSet(self, section, plotSet)
Definition: html.py:314
_plotSets
Definition: html.py:311
def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 320 of file html.py.

References html.Page._tables.

320  def addTable(self, section, table):
321  self._tables[section] = table
322 
_tables
Definition: html.py:312
def addTable(self, section, table)
Definition: html.py:320
def html.Page.isEmpty (   self)

Definition at line 323 of file html.py.

References html.Page._tables.

Referenced by plotting.Plot.clone().

323  def isEmpty(self):
324  for plotSet in self._plotSets.itervalues():
325  if len(plotSet) > 0:
326  return False
327 
328  if len(self._tables) > 0:
329  return False
330 
331  return True
332 
def isEmpty(self)
Definition: html.py:323
_tables
Definition: html.py:312
def html.Page.write (   self,
  fileName 
)

Definition at line 333 of file html.py.

333  def write(self, fileName):
334  self._legends = []
336  self._columnHeaders = []
338  self._formatPlotSets()
339  self._formatTables()
340  self._formatLegend()
341 
342  self._content.extend([
343  ' </body>',
344  '</html>',
345  ])
346 
347  #print "Writing HTML report page", fileName
348  f = open(fileName, "w")
349  for line in self._content:
350  f.write(line)
351  f.write("\n")
352  f.close()
353 
def write(self, fileName)
Definition: html.py:333
_legends
Definition: html.py:334
_content
Definition: html.py:300
def _formatLegend(self)
Definition: html.py:480
_columnHeaders
Definition: html.py:336
def _formatTables(self)
Definition: html.py:426
_columnHeadersIndex
Definition: html.py:337
def _formatPlotSets(self)
Definition: html.py:368
_sectionLegendIndex
Definition: html.py:335

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 336 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 337 of file html.py.

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

html.Page._content
private

Definition at line 300 of file html.py.

html.Page._legends
private

Definition at line 334 of file html.py.

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

html.Page._plotSets
private

Definition at line 311 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 335 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 312 of file html.py.

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