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 302 of file html.py.

Constructor & Destructor Documentation

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

Definition at line 303 of file html.py.

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

Member Function Documentation

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

Definition at line 420 of file html.py.

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

Referenced by html.Page._formatTables().

420  def _appendColumnHeader(self, header):
421  leg = ""
422  if header in self._columnHeadersIndex:
423  leg = self._columnHeadersIndex[header]
424  else:
425  leg = str(chr(ord('A')+len(self._columnHeaders)))
426  self._columnHeaders.append("%s: %s" % (leg, header))
427  self._columnHeadersIndex[header] = leg
428  return leg
429 
def _appendColumnHeader(self, header)
Definition: html.py:420
_columnHeaders
Definition: html.py:340
_columnHeadersIndex
Definition: html.py:341
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 358 of file html.py.

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

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

358  def _appendLegend(self, section):
359  leg = ""
360  legends = _sectionNameLegend()
361  if section in legends:
362  if section in self._sectionLegendIndex:
363  leg = self._sectionLegendIndex[section]
364  else:
365  legnum = len(self._legends)+1
366  leg = "<sup>%d</sup>" % legnum
367  leg2 = "<sup>%d)</sup>" % legnum
368  self._legends.append("%s %s" % (leg2, legends[section]))
369  self._sectionLegendIndex[section] = leg
370  return leg
371 
_legends
Definition: html.py:338
def _appendLegend(self, section)
Definition: html.py:358
def _sectionNameLegend()
Definition: html.py:220
_sectionLegendIndex
Definition: html.py:339
def html.Page._formatLegend (   self)
private

Definition at line 484 of file html.py.

References html.Page._legends.

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

Definition at line 372 of file html.py.

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

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

Definition at line 430 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, SiStripPI.max, and harvestTrackValidationPlots.str.

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

Definition at line 494 of file html.py.

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

494  def _mapSectionName(self, section):
495  return _sectionNameMapOrder.get(section, section)
496 
def _mapSectionName(self, section)
Definition: html.py:494
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 497 of file html.py.

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

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

Definition at line 318 of file html.py.

References html.Page._plotSets.

318  def addPlotSet(self, section, plotSet):
319  if section in self._plotSets:
320  self._plotSets[section].extend(plotSet)
321  else:
322  self._plotSets[section] = plotSet
323 
def addPlotSet(self, section, plotSet)
Definition: html.py:318
_plotSets
Definition: html.py:315
def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 324 of file html.py.

References html.Page._tables.

324  def addTable(self, section, table):
325  self._tables[section] = table
326 
_tables
Definition: html.py:316
def addTable(self, section, table)
Definition: html.py:324
def html.Page.isEmpty (   self)

Definition at line 327 of file html.py.

References html.Page._tables.

Referenced by plotting.Plot.clone().

327  def isEmpty(self):
328  for plotSet in self._plotSets.itervalues():
329  if len(plotSet) > 0:
330  return False
331 
332  if len(self._tables) > 0:
333  return False
334 
335  return True
336 
def isEmpty(self)
Definition: html.py:327
_tables
Definition: html.py:316
def html.Page.write (   self,
  fileName 
)

Definition at line 337 of file html.py.

337  def write(self, fileName):
338  self._legends = []
340  self._columnHeaders = []
342  self._formatPlotSets()
343  self._formatTables()
344  self._formatLegend()
345 
346  self._content.extend([
347  ' </body>',
348  '</html>',
349  ])
350 
351  #print "Writing HTML report page", fileName
352  f = open(fileName, "w")
353  for line in self._content:
354  f.write(line)
355  f.write("\n")
356  f.close()
357 
def write(self, fileName)
Definition: html.py:337
_legends
Definition: html.py:338
_content
Definition: html.py:304
def _formatLegend(self)
Definition: html.py:484
_columnHeaders
Definition: html.py:340
def _formatTables(self)
Definition: html.py:430
_columnHeadersIndex
Definition: html.py:341
def _formatPlotSets(self)
Definition: html.py:372
_sectionLegendIndex
Definition: html.py:339

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 340 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 341 of file html.py.

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

html.Page._content
private

Definition at line 304 of file html.py.

html.Page._legends
private

Definition at line 338 of file html.py.

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

html.Page._plotSets
private

Definition at line 315 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 339 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 316 of file html.py.

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