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

Constructor & Destructor Documentation

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

Definition at line 304 of file html.py.

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

Member Function Documentation

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

Definition at line 427 of file html.py.

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

Referenced by html.Page._formatTables().

427  def _appendColumnHeader(self, header):
428  leg = ""
429  if header in self._columnHeadersIndex:
430  leg = self._columnHeadersIndex[header]
431  else:
432  leg = str(chr(ord('A')+len(self._columnHeaders)))
433  self._columnHeaders.append("%s: %s" % (leg, header))
434  self._columnHeadersIndex[header] = leg
435  return leg
436 
def _appendColumnHeader(self, header)
Definition: html.py:427
_columnHeaders
Definition: html.py:341
_columnHeadersIndex
Definition: html.py:342
#define str(s)
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 359 of file html.py.

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

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

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

Definition at line 491 of file html.py.

References html.Page._legends.

491  def _formatLegend(self):
492  if len(self._legends) > 0:
493  self._content.extend([
494  ' <br/>'
495  ' Details:</br>',
496  ])
497  for leg in self._legends:
498  self._content.append(' %s<br/>' % leg)
499 
500 
_legends
Definition: html.py:339
def _formatLegend(self)
Definition: html.py:491
def html.Page._formatPlotSets (   self)
private

Definition at line 373 of file html.py.

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

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

Definition at line 437 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 str.

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

Definition at line 501 of file html.py.

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

501  def _mapSectionName(self, section):
502  return _sectionNameMapOrder.get(section, section)
503 
def _mapSectionName(self, section)
Definition: html.py:501
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 504 of file html.py.

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

504  def _orderSets(self, keys):
505  keys_sorted = sorted(keys)
506  ret = []
507  for section in _sectionNameMapOrder.keys():
508  if section in keys_sorted:
509  ret.append(section)
510  keys_sorted.remove(section)
511  ret.extend(keys_sorted)
512  return ret
513 
def _orderSets(self, keys)
Definition: html.py:504
def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 319 of file html.py.

References html.Page._plotSets.

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

Definition at line 325 of file html.py.

References html.Page._tables.

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

Definition at line 328 of file html.py.

References html.Page._plotSets, and html.Page._tables.

Referenced by plotting.Plot.clone().

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

Definition at line 338 of file html.py.

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

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 341 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 342 of file html.py.

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

html.Page._content
private

Definition at line 305 of file html.py.

html.Page._legends
private

Definition at line 339 of file html.py.

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

html.Page._plotSets
private

Definition at line 316 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 340 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 317 of file html.py.

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