Structure.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. def addContent(self,content):
  48. self._content.append(content)
  49. @property
  50. def hasContent(self):
  51. return(len(self._content) > 0 or any([x.hasContent for x in self.sections]))
  52. def accept(self, visitor):
  53. if self.hasContent:
  54. visitor.visitSection(self)
  55. for element in self.sections:
  56. element.accept(visitor)
  57. for element in self._content:
  58. element.accept(visitor)
  59. visitor.leaveSection(self)
  60. class Table:
  61. def __init__(self,params,cores):
  62. self._params=params
  63. self._cores=cores
  64. self._rows=[]
  65. def addRow(self,row):
  66. self._rows.append(row)
  67. @property
  68. def columns(self):
  69. return(self._params + self._cores)
  70. @property
  71. def params(self):
  72. return(self._params)
  73. @property
  74. def cores(self):
  75. return(self._cores)
  76. @property
  77. def rows(self):
  78. return(self._rows)
  79. def accept(self, visitor):
  80. visitor.visitTable(self)
  81. class Text:
  82. def __init__(self,text):
  83. self._text = text
  84. @property
  85. def text(self):
  86. return(self._text)
  87. def accept(self, visitor):
  88. visitor.visitText(self)
  89. class BarChart:
  90. def __init__(self,data):
  91. self._data = data
  92. @property
  93. def data(self):
  94. return(self._data)
  95. def accept(self, visitor):
  96. visitor.visitBarChart(self)
  97. class History:
  98. def __init__(self,data,runid):
  99. self._data = data
  100. minId = runid-9
  101. if minId < 0:
  102. minId = 0
  103. self._runids = list(range(minId,runid+1))
  104. @property
  105. def data(self):
  106. return(self._data)
  107. @property
  108. def runids(self):
  109. return(self._runids)
  110. def accept(self, visitor):
  111. visitor.visitHistory(self)