Structure.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. class Hierarchy:
  2. def __init__(self,name,subsections=None):
  3. self._parent = None
  4. self._name=name
  5. self._sections = []
  6. if subsections is not None:
  7. for s in subsections:
  8. self.addSection(s)
  9. @property
  10. def parent(self):
  11. return(self._parent)
  12. @property
  13. def sections(self):
  14. return(self._sections)
  15. def addSection(self,section):
  16. self._sections.append(section)
  17. @property
  18. def hasChildren(self):
  19. return(len(self._sections)>0)
  20. @property
  21. def name(self):
  22. return(self._name)
  23. class Document:
  24. def __init__(self,runidHeader):
  25. self._runidHeader = runidHeader
  26. self._sections = []
  27. @property
  28. def runidHeader(self):
  29. return(self._runidHeader)
  30. @property
  31. def date(self):
  32. return(self._date)
  33. @property
  34. def sections(self):
  35. return(self._sections)
  36. def addSection(self,section):
  37. self._sections.append(section)
  38. def accept(self, visitor):
  39. visitor.visitDocument(self)
  40. for element in self._sections:
  41. element.accept(visitor)
  42. visitor.leaveDocument(self)
  43. class Section(Hierarchy):
  44. def __init__(self,name):
  45. super(Section, self).__init__(name)
  46. self._content = []
  47. self._testname=False
  48. def addContent(self,content):
  49. self._content.append(content)
  50. @property
  51. def isTest(self):
  52. return(self._testname)
  53. def setTest(self):
  54. self._testname = True
  55. @property
  56. def hasContent(self):
  57. return(len(self._content) > 0 or any([x.hasContent for x in self.sections]))
  58. def accept(self, visitor):
  59. if self.hasContent:
  60. visitor.visitSection(self)
  61. for element in self.sections:
  62. element.accept(visitor)
  63. for element in self._content:
  64. element.accept(visitor)
  65. visitor.leaveSection(self)
  66. class Table:
  67. def __init__(self,params,cores):
  68. self._params=params
  69. self._cores=cores
  70. self._rows=[]
  71. def addRow(self,row):
  72. self._rows.append(row)
  73. @property
  74. def columns(self):
  75. return(self._params + self._cores)
  76. @property
  77. def params(self):
  78. return(self._params)
  79. @property
  80. def cores(self):
  81. return(self._cores)
  82. @property
  83. def rows(self):
  84. return(self._rows)
  85. def accept(self, visitor):
  86. visitor.visitTable(self)
  87. class Text:
  88. def __init__(self,text):
  89. self._text = text
  90. @property
  91. def text(self):
  92. return(self._text)
  93. def accept(self, visitor):
  94. visitor.visitText(self)
  95. class BarChart:
  96. def __init__(self,data):
  97. self._data = data
  98. @property
  99. def data(self):
  100. return(self._data)
  101. def accept(self, visitor):
  102. visitor.visitBarChart(self)
  103. class History:
  104. def __init__(self,data,runid):
  105. self._data = data
  106. minId = runid-9
  107. if minId < 0:
  108. minId = 0
  109. self._runids = list(range(minId,runid+1))
  110. @property
  111. def data(self):
  112. return(self._data)
  113. @property
  114. def runids(self):
  115. return(self._runids)
  116. def accept(self, visitor):
  117. visitor.visitHistory(self)