Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize EntryHeader parameters #68

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@awendelin-work awendelin-work Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be an argument to put this as EntryHeaderDataType.STRING since it is the specified fallback in the absence of the "dataType" field. I put it to None to be transparent about what the server returns.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok, I think. Calling methods can default to String



class Entry:
Expand Down