Skip to content

Commit

Permalink
Deserialize EntryHeader parameters
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
awendelin-work authored and MatthewKhouzam committed Jul 19, 2024
1 parent accbde6 commit 04b3632
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def print(self):
if self._headers is not None:
headers = []
for header in self._headers:
headers.append(header.name["name"])
headers.append(header.name)
for child in self._root.get_children():
data = child.print(data, 0)
frame = {}
Expand Down
41 changes: 37 additions & 4 deletions tsp/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,32 @@

"""Entry classes file."""

from enum import Enum

from tsp.output_element_style import OutputElementStyle

ID_KEY = "id"
PARENT_ID_KEY = "parentId"
LABELS_KEY = "labels"
STYLE_KEY = "style"
HEADER_NAME_KEY = "name"
HEADER_DATA_TYPE_KEY = "dataType"
HEADER_TOOLTIP_KEY = "tooltip"
UNKNOWN_ID = -1
NAME_KEY = "name"
TOOLTIP_KEY = "tooltip"

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

class EntryHeaderDataType(Enum):
'''
The data types of a column entry.
'''
NUMBER = "NUMBER"
BINARY_NUMBER = "BINARY_NUMBER"
TIMESTAMP = "TIMESTAMP"
DURATION = "DURATION"
STRING = "STRING"
TIME_RANGE = "TIME_RANGE"


class EntryHeader:
'''
Expand All @@ -43,9 +56,29 @@ class EntryHeader:

def __init__(self, params):
'''
Displayed name
Constructor
'''
self.name = params

# Name for this header.
if HEADER_NAME_KEY in params:
self.name = params.get(HEADER_NAME_KEY)
del params[HEADER_NAME_KEY]
else:
self.name = None

# Tooltip for this header.
if HEADER_TOOLTIP_KEY in params:
self.tooltip = params.get(HEADER_TOOLTIP_KEY)
del params[HEADER_TOOLTIP_KEY]
else:
self.tooltip = None

# Data type for this header.
if HEADER_DATA_TYPE_KEY in params:
self.data_type = EntryHeaderDataType(params.get(HEADER_DATA_TYPE_KEY))
del params[HEADER_DATA_TYPE_KEY]
else:
self.data_type = None


class Entry:
Expand Down

0 comments on commit 04b3632

Please sign in to comment.