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

Constructor & Destructor Documentation

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

Definition at line 264 of file html.py.

264  def __init__(self, title, sampleName):
265  self._content = [
266  '<html>',
267  ' <head>',
268  ' <title>%s</title>' % title,
269  ' </head>',
270  ' <body>',
271  ' '+sampleName,
272  ' <br/>',
273  ' <br/>',
274  ]
275 
276  self._plotSets = {}
277  self._tables = {}
278 
_content
Definition: html.py:265
def __init__(self, title, sampleName)
Definition: html.py:264
_plotSets
Definition: html.py:276
_tables
Definition: html.py:277

Member Function Documentation

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

Definition at line 381 of file html.py.

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

Referenced by html.Page._formatTables().

381  def _appendColumnHeader(self, header):
382  leg = ""
383  if header in self._columnHeadersIndex:
384  leg = self._columnHeadersIndex[header]
385  else:
386  leg = str(chr(ord('A')+len(self._columnHeaders)))
387  self._columnHeaders.append("%s: %s" % (leg, header))
388  self._columnHeadersIndex[header] = leg
389  return leg
390 
def _appendColumnHeader(self, header)
Definition: html.py:381
_columnHeaders
Definition: html.py:301
_columnHeadersIndex
Definition: html.py:302
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 319 of file html.py.

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

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

319  def _appendLegend(self, section):
320  leg = ""
321  legends = _sectionNameLegend()
322  if section in legends:
323  if section in self._sectionLegendIndex:
324  leg = self._sectionLegendIndex[section]
325  else:
326  legnum = len(self._legends)+1
327  leg = "<sup>%d</sup>" % legnum
328  leg2 = "<sup>%d)</sup>" % legnum
329  self._legends.append("%s %s" % (leg2, legends[section]))
330  self._sectionLegendIndex[section] = leg
331  return leg
332 
_legends
Definition: html.py:299
def _appendLegend(self, section)
Definition: html.py:319
def _sectionNameLegend()
Definition: html.py:185
_sectionLegendIndex
Definition: html.py:300
def html.Page._formatLegend (   self)
private

Definition at line 445 of file html.py.

References html.Page._legends.

445  def _formatLegend(self):
446  if len(self._legends) > 0:
447  self._content.extend([
448  ' <br/>'
449  ' Details:</br>',
450  ])
451  for leg in self._legends:
452  self._content.append(' %s<br/>' % leg)
453 
454 
_legends
Definition: html.py:299
def _formatLegend(self)
Definition: html.py:445
def html.Page._formatPlotSets (   self)
private

Definition at line 333 of file html.py.

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

333  def _formatPlotSets(self):
334  self._content.extend([
335  ' <table>'
336  ' <tr>',
337  ])
338 
339  fileTable = []
340 
341  sections = self._orderSets(self._plotSets.keys())
342  for isec, section in enumerate(sections):
343  leg = self._appendLegend(section)
344 
345  self._content.extend([
346  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
347  ])
348  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
349  for row in fileTable:
350  found = False
351  for i, (bsf, f) in enumerate(files):
352  if bsf == row[0]:
353  row.append(f)
354  found = True
355  del files[i]
356  break
357  if not found:
358  row.append(None)
359  for bsf, f in files:
360  fileTable.append( [bsf] + [None]*isec + [f] )
361 
362  self._content.extend([
363  ' </tr>',
364  ])
365 
366  for row in fileTable:
367  self._content.append(' <tr>')
368  bs = row[0]
369  for elem in row[1:]:
370  if elem is not None:
371  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
372  else:
373  self._content.append(' <td></td>')
374  self._content.append(' </tr>')
375 
376 
377  self._content.extend([
378  ' </table>',
379  ])
380 
def _orderSets(self, keys)
Definition: html.py:458
def _mapSectionName(self, section)
Definition: html.py:455
def _appendLegend(self, section)
Definition: html.py:319
_plotSets
Definition: html.py:276
def _formatPlotSets(self)
Definition: html.py:333
def html.Page._formatTables (   self)
private

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

391  def _formatTables(self):
392  def _allNone(row):
393  for item in row:
394  if item is not None:
395  return False
396  return True
397 
398  sections = self._orderSets(self._tables.keys())
399  for isec, section in enumerate(sections):
400  leg = self._appendLegend(section)
401 
402  table = self._tables[section]
403  self._content.extend([
404  ' <br/>',
405  ' %s%s' % (self._mapSectionName(section), leg),
406  ' <table border="1">'
407  ])
408 
409  # table is stored in column-row, need to transpose
410  data = table.tableAsRowColumn()
411 
412  self._content.extend([
413  ' <tr>'
414  ' <td></td>'
415  ])
416  heads = table.columnHeaders()
417  if max(map(lambda h: len(h), heads)) > 20:
418  heads = [self._appendColumnHeader(h) for h in heads]
419  for head in heads:
420  self._content.append(' <td>%s</td>' % head)
421  self._content.append(' </tr>')
422 
423  for irow, row in enumerate(data):
424  # Skip row if all values are non-existent
425  if _allNone(row):
426  continue
427 
428  self._content.extend([
429  ' <tr>'
430  ' <td>%s</td>' % table.rowHeaders()[irow]
431  ])
432  # align the number columns to right
433  for icol, item in enumerate(row):
434  formatted = str(item) if item is not None else ""
435  self._content.append(' <td align="right">%s</td>' % formatted)
436  self._content.append(' </tr>')
437 
438  self._content.append(' </table>')
439 
440  for shortenedColumnHeader in self._columnHeaders:
441  self._content.append(' %s<br/>' % shortenedColumnHeader)
442  self._columnHeaders = []
443  self._columnHeadersIndex = {}
444 
def _appendColumnHeader(self, header)
Definition: html.py:381
def _orderSets(self, keys)
Definition: html.py:458
def _mapSectionName(self, section)
Definition: html.py:455
def _appendLegend(self, section)
Definition: html.py:319
_columnHeaders
Definition: html.py:301
def _formatTables(self)
Definition: html.py:391
_columnHeadersIndex
Definition: html.py:302
_tables
Definition: html.py:277
def html.Page._mapSectionName (   self,
  section 
)
private

Definition at line 455 of file html.py.

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

455  def _mapSectionName(self, section):
456  return _sectionNameMapOrder.get(section, section)
457 
def _mapSectionName(self, section)
Definition: html.py:455
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 458 of file html.py.

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

458  def _orderSets(self, keys):
459  keys_sorted = sorted(keys)
460  ret = []
461  for section in _sectionNameMapOrder.keys():
462  if section in keys_sorted:
463  ret.append(section)
464  keys.remove(section)
465  ret.extend(keys_sorted)
466  return ret
467 
def _orderSets(self, keys)
Definition: html.py:458
def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 279 of file html.py.

References html.Page._plotSets.

279  def addPlotSet(self, section, plotSet):
280  if section in self._plotSets:
281  self._plotSets[section].extend(plotSet)
282  else:
283  self._plotSets[section] = plotSet
284 
def addPlotSet(self, section, plotSet)
Definition: html.py:279
_plotSets
Definition: html.py:276
def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 285 of file html.py.

References html.Page._tables.

285  def addTable(self, section, table):
286  self._tables[section] = table
287 
_tables
Definition: html.py:277
def addTable(self, section, table)
Definition: html.py:285
def html.Page.isEmpty (   self)

Definition at line 288 of file html.py.

References html.Page._tables.

Referenced by plotting.Plot.clone().

288  def isEmpty(self):
289  for plotSet in self._plotSets.itervalues():
290  if len(plotSet) > 0:
291  return False
292 
293  if len(self._tables) > 0:
294  return False
295 
296  return True
297 
def isEmpty(self)
Definition: html.py:288
_tables
Definition: html.py:277
def html.Page.write (   self,
  fileName 
)

Definition at line 298 of file html.py.

298  def write(self, fileName):
299  self._legends = []
301  self._columnHeaders = []
303  self._formatPlotSets()
304  self._formatTables()
305  self._formatLegend()
306 
307  self._content.extend([
308  ' </body>',
309  '</html>',
310  ])
311 
312  #print "Writing HTML report page", fileName
313  f = open(fileName, "w")
314  for line in self._content:
315  f.write(line)
316  f.write("\n")
317  f.close()
318 
def write(self, fileName)
Definition: html.py:298
_legends
Definition: html.py:299
_content
Definition: html.py:265
def _formatLegend(self)
Definition: html.py:445
_columnHeaders
Definition: html.py:301
def _formatTables(self)
Definition: html.py:391
_columnHeadersIndex
Definition: html.py:302
def _formatPlotSets(self)
Definition: html.py:333
_sectionLegendIndex
Definition: html.py:300

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 301 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 302 of file html.py.

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

html.Page._content
private

Definition at line 265 of file html.py.

html.Page._legends
private

Definition at line 299 of file html.py.

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

html.Page._plotSets
private

Definition at line 276 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 300 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 277 of file html.py.

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