Skip to content

Commit 04b3632

Browse files
awendelin-workMatthewKhouzam
authored andcommitted
Deserialize EntryHeader parameters
The EntryHeader would set the map of all its parameters as its name member, which semantically does not make sense and requires a user to parse the name member itself to find the actual name of the header. Deserialize the EntryHeader according to the TSP to set members "name", "tooltip" and "data_type".
1 parent accbde6 commit 04b3632

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

tree_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def print(self):
5454
if self._headers is not None:
5555
headers = []
5656
for header in self._headers:
57-
headers.append(header.name["name"])
57+
headers.append(header.name)
5858
for child in self._root.get_children():
5959
data = child.print(data, 0)
6060
frame = {}

tsp/entry.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,32 @@
2222

2323
"""Entry classes file."""
2424

25+
from enum import Enum
26+
2527
from tsp.output_element_style import OutputElementStyle
2628

2729
ID_KEY = "id"
2830
PARENT_ID_KEY = "parentId"
2931
LABELS_KEY = "labels"
3032
STYLE_KEY = "style"
3133
HEADER_NAME_KEY = "name"
34+
HEADER_DATA_TYPE_KEY = "dataType"
35+
HEADER_TOOLTIP_KEY = "tooltip"
3236
UNKNOWN_ID = -1
33-
NAME_KEY = "name"
34-
TOOLTIP_KEY = "tooltip"
3537

3638
# pylint: disable=too-few-public-methods
3739

40+
class EntryHeaderDataType(Enum):
41+
'''
42+
The data types of a column entry.
43+
'''
44+
NUMBER = "NUMBER"
45+
BINARY_NUMBER = "BINARY_NUMBER"
46+
TIMESTAMP = "TIMESTAMP"
47+
DURATION = "DURATION"
48+
STRING = "STRING"
49+
TIME_RANGE = "TIME_RANGE"
50+
3851

3952
class EntryHeader:
4053
'''
@@ -43,9 +56,29 @@ class EntryHeader:
4356

4457
def __init__(self, params):
4558
'''
46-
Displayed name
59+
Constructor
4760
'''
48-
self.name = params
61+
62+
# Name for this header.
63+
if HEADER_NAME_KEY in params:
64+
self.name = params.get(HEADER_NAME_KEY)
65+
del params[HEADER_NAME_KEY]
66+
else:
67+
self.name = None
68+
69+
# Tooltip for this header.
70+
if HEADER_TOOLTIP_KEY in params:
71+
self.tooltip = params.get(HEADER_TOOLTIP_KEY)
72+
del params[HEADER_TOOLTIP_KEY]
73+
else:
74+
self.tooltip = None
75+
76+
# Data type for this header.
77+
if HEADER_DATA_TYPE_KEY in params:
78+
self.data_type = EntryHeaderDataType(params.get(HEADER_DATA_TYPE_KEY))
79+
del params[HEADER_DATA_TYPE_KEY]
80+
else:
81+
self.data_type = None
4982

5083

5184
class Entry:

0 commit comments

Comments
 (0)