Skip to content

Commit

Permalink
add state and arrow requests
Browse files Browse the repository at this point in the history
Signed-off-by: Arnaud Fiorini <[email protected]>
  • Loading branch information
arfio committed Jul 4, 2024
1 parent 29ba74a commit 9e04b58
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 21 deletions.
3 changes: 2 additions & 1 deletion tsp/model_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ModelType(Enum):
'''

TIME_GRAPH_TREE = "time_graph_tree"
TIME_GRAPH_STATE = "time_graph_state"
TIME_GRAPH_ARROW = "time_graph_arrow"
XY_TREE = "xy_tree"
STATES = "states"
XY = "xy"
DATA_TREE = "data_tree"
9 changes: 7 additions & 2 deletions tsp/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ def __init__(self, params, model_type):
if MODEL_KEY in params and params.get(MODEL_KEY) is not None:
if self.model_type == ModelType.TIME_GRAPH_TREE:
self.model = EntryModel(params.get(MODEL_KEY), self.model_type)
elif self.model_type == ModelType.TIME_GRAPH_STATE:
self.model = TimeGraphModel(params.get(MODEL_KEY))
elif self.model_type == ModelType.TIME_GRAPH_ARROW:
arrows = []
for arrow in params.get(MODEL_KEY):
arrows.append(TimeGraphArrow(arrow))
self.model = arrows
elif self.model_type == ModelType.XY_TREE:
self.model = EntryModel(params.get(MODEL_KEY))
elif self.model_type == ModelType.STATES: # pragma: no cover
print("not implemented")
elif self.model_type == ModelType.XY:
self.model = XYModel(params.get(MODEL_KEY))
elif self.model_type == ModelType.DATA_TREE:
Expand Down
31 changes: 18 additions & 13 deletions tsp/time_graph_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
from tsp.entry import Entry

TYPE_KEY = "type"
START_TIME_KEY = "startTime"
END_TIME_KEY = "endTime"
HAS_ROW_MODEL_KEY = "hasRowModel"
START_TIME_KEY = "start"
END_TIME_KEY = "end"
HAS_ROW_MODEL_KEY = "hasData"
ROWS_KEY = "rows"
ENTRY_ID_KEY = "entryID"
ENTRY_ID_KEY = "entryId"
STATES_KEY = "states"
DURATION_KEY = "duration"
LABEL_KEY = "label"
VALUE_KEY = "value"
VALUE_KEY = "values"
TAGS_KEY = "tags"
STYLE_KEY = "style"
SOURCE_ID_TAG = "sourceId"
DESTINATION_ID_TAG = "destinationId"
TARGET_ID_TAG = "targetId"

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

Expand Down Expand Up @@ -119,9 +119,9 @@ def __init__(self, params):
del params[START_TIME_KEY]

# Duration of the state
if DURATION_KEY in params:
self.duration = params.get(DURATION_KEY)
del params[DURATION_KEY]
if END_TIME_KEY in params:
self.end_time = params.get(END_TIME_KEY)
del params[END_TIME_KEY]

# Label to apply to the state
if LABEL_KEY in params:
Expand Down Expand Up @@ -158,15 +158,20 @@ def __init__(self, params):
del params[SOURCE_ID_TAG]

# Destination entry Id for the arrow
if DESTINATION_ID_TAG in params:
self.destination_id = params.get(DESTINATION_ID_TAG)
del params[DESTINATION_ID_TAG]
if TARGET_ID_TAG in params:
self.target_id = params.get(TARGET_ID_TAG)
del params[TARGET_ID_TAG]

# Start time of the arrow
if START_TIME_KEY in params:
self.start_time = params.get(START_TIME_KEY)
self.start = params.get(START_TIME_KEY)
del params[START_TIME_KEY]

# Duration of the state
if END_TIME_KEY in params:
self.end = params.get(END_TIME_KEY)
del params[END_TIME_KEY]

# Duration of the arrow
if DURATION_KEY in params:
self.duration = params.get(DURATION_KEY)
Expand Down
84 changes: 79 additions & 5 deletions tsp/tsp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
'Accept': APPLICATION_JSON}

GET_TREE_FAILED = "failed to get tree: {0}"
GET_STATES_FAILED = "failed to get states: {0}"
GET_ARROWS_FAILED = "failed to get arrows: {0}"


# pylint: disable=consider-using-f-string,missing-timeout

Expand Down Expand Up @@ -289,23 +292,87 @@ def fetch_timegraph_tree(self, exp_uuid, output_id, parameters=None):
:returns: :class: `TspClientResponse <GenericResponse>` object Timegraph entries response
:rtype: TspClientResponse
'''
api_url = '{0}experiments/{1}/outputs/timeGraph/{2}/tree'.format(
self.base_url, exp_uuid, output_id)
api_url = f'{self.base_url}experiments/{exp_uuid}/outputs/timeGraph/{output_id}/tree'

params = parameters
if parameters is None:
params = {}
params = {
"parameters": { }
}

response = requests.post(api_url, json=params, headers=headers)

if response.status_code == 200:
response_size = len(bytes(response.text, 'utf-8'))
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
ModelType.TIME_GRAPH_TREE),
response.status_code, response.text)
else: # pragma: no cover
print(GET_TREE_FAILED.format(response.status_code))
return TspClientResponse(None, response.status_code, response.text)


def fetch_timegraph_states(self, exp_uuid, output_id, parameters=None):
'''
Fetch Time Graph States
:param exp_uuid: Experiment UUID
:param output_id: Output ID
:param parameters: Query object
:returns: :class: `TspClientResponse <GenericResponse>` object Timegraph Model response
:rtype: TspClientResponse
'''
api_url = f'{self.base_url}experiments/{exp_uuid}/outputs/timeGraph/{output_id}/states'

params = parameters
if parameters is None:
params = {
"parameters": { }
}

self.logger.info("time_graph_states_begin")
response = requests.post(api_url, json=params, headers=headers)
self.logger.info("time_graph_states_end")

if response.status_code == 200:
response_size = len(bytes(response.text, 'utf-8'))
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
ModelType.TIME_GRAPH_STATE),
response.status_code, response.reason, response_size)
else: # pragma: no cover
print(GET_STATES_FAILED.format(response.status_code))
return TspClientResponse(None, response.status_code, response.text)


def fetch_timegraph_arrows(self, exp_uuid, output_id, parameters=None):
'''
Fetch Time Graph Arrows
:param exp_uuid: Experiment UUID
:param output_id: Output ID
:param parameters: Query object
:returns: :class: `TspClientResponse <GenericResponse>` list of object Timegraph arrows response
:rtype: TspClientResponse
'''
api_url = f'{self.base_url}experiments/{exp_uuid}/outputs/timeGraph/{output_id}/arrows'

params = parameters
if parameters is None:
params = {
"parameters": { }
}

self.logger.info("time_graph_arrows_begin")
response = requests.post(api_url, json=params, headers=headers)
self.logger.info("time_graph_arrows_end")

if response.status_code == 200:
response_size = len(bytes(response.text, 'utf-8'))
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
ModelType.TIME_GRAPH_ARROW),
response.status_code, response.reason, response_size)
else: # pragma: no cover
print(GET_ARROWS_FAILED.format(response.status_code))
return TspClientResponse(None, response.status_code, response.text)

def fetch_xy_tree(self, exp_uuid, output_id, parameters=None):
'''
Fetch XY tree, Model extends Entry
Expand All @@ -320,7 +387,9 @@ def fetch_xy_tree(self, exp_uuid, output_id, parameters=None):

params = parameters
if parameters is None:
params = {}
params = {
"parameters": { }
}

response = requests.post(api_url, json=params, headers=headers)

Expand All @@ -344,7 +413,12 @@ def fetch_xy(self, exp_uuid, output_id, parameters):
api_url = '{0}experiments/{1}/outputs/XY/{2}/xy'.format(
self.base_url, exp_uuid, output_id)

response = requests.post(api_url, json=parameters, headers=headers)
params = parameters
if parameters is None:
params = {
"parameters": { }
}
response = requests.post(api_url, json=params, headers=headers)

if response.status_code == 200:
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
Expand Down

0 comments on commit 9e04b58

Please sign in to comment.