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

Constructor & Destructor Documentation

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

Definition at line 263 of file html.py.

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

Member Function Documentation

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

Definition at line 380 of file html.py.

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

Referenced by html.Page._formatTables().

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

Definition at line 318 of file html.py.

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

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

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

Definition at line 444 of file html.py.

References html.Page._legends.

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

Definition at line 332 of file html.py.

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

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

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

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

Definition at line 454 of file html.py.

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

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

Definition at line 457 of file html.py.

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

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

Definition at line 278 of file html.py.

References html.Page._plotSets.

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

Definition at line 284 of file html.py.

References html.Page._tables.

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

Definition at line 287 of file html.py.

References html.Page._tables.

Referenced by plotting.Plot.clone().

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

Definition at line 297 of file html.py.

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

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 300 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 301 of file html.py.

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

html.Page._content
private

Definition at line 264 of file html.py.

html.Page._legends
private

Definition at line 298 of file html.py.

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

html.Page._plotSets
private

Definition at line 275 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 299 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 276 of file html.py.

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