Skip to content

Commit 0f636f0

Browse files
kavehshahediMatthewKhouzam
authored andcommitted
Add get-virtual-tabel-lines to the tsp client
1 parent 6d94598 commit 0f636f0

File tree

5 files changed

+216
-0
lines changed

5 files changed

+216
-0
lines changed

tsp/model_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ class ModelType(Enum):
3535
STATES = "states"
3636
XY = "xy"
3737
DATA_TREE = "data_tree"
38+
VIRTUAL_TABLE = "virtual_table"

tsp/response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from tsp.output_descriptor import OutputDescriptor
2929
from tsp.entry_model import EntryModel
3030
from tsp.xy_model import XYModel
31+
from tsp.virtual_table_model import VirtualTableModel
3132

3233
MODEL_KEY = "model"
3334
OUTPUT_DESCRIPTOR_KEY = "output"
@@ -87,6 +88,8 @@ def __init__(self, params, model_type):
8788
self.model = XYModel(params.get(MODEL_KEY))
8889
elif self.model_type == ModelType.DATA_TREE:
8990
self.model = EntryModel(params.get(MODEL_KEY), self.model_type)
91+
elif self.model_type == ModelType.VIRTUAL_TABLE:
92+
self.model = VirtualTableModel(params.get(MODEL_KEY))
9093

9194
# Output descriptor
9295
if OUTPUT_DESCRIPTOR_KEY in params:

tsp/tsp_client.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class TspClient:
6464
REQUESTED_TIME_RANGE_END_KEY = 'end'
6565
REQUESTED_TIME_RANGE_NUM_TIMES_KEY = 'nbTimes'
6666

67+
REQUESTED_TABLE_LINE_INDEX_KEY = 'requested_table_index'
68+
REQUESTED_TABLE_LINE_COUNT_KEY = 'requested_table_count'
69+
REQUESTED_TABLE_LINE_COLUMN_IDS_KEY = 'requested_table_column_ids'
70+
REQUESTED_TABLE_LINE_SEACH_DIRECTION_KEY = 'table_search_direction'
71+
REQUESTED_TABLE_LINE_SEARCH_EXPRESSION_KEY = 'table_search_expressions'
72+
6773
def __init__(self, base_url):
6874
'''
6975
Constructor
@@ -280,6 +286,34 @@ def fetch_datatree(self, exp_uuid, output_id, parameters=None):
280286
else: # pragma: no cover
281287
print(GET_TREE_FAILED.format(response.status_code))
282288
return TspClientResponse(None, response.status_code, response.text)
289+
290+
def fetch_virtual_table_lines(self, exp_uuid, output_id, parameters=None):
291+
'''
292+
Fetch Virtual Table lines, Model extends VirtualTableModel
293+
:param exp_uuid: Experiment UUID
294+
:param output_id: Output ID
295+
:param parameters: Query object
296+
:returns: :class: `TspClientResponse <GenericResponse>` object Virtual Table lines response
297+
:rtype: TspClientResponse
298+
'''
299+
api_url = '{0}experiments/{1}/outputs/table/{2}/lines'.format(
300+
self.base_url, exp_uuid, output_id)
301+
302+
params = parameters
303+
if parameters is None:
304+
params = {
305+
TspClient.PARAMETERS_KEY: {}
306+
}
307+
308+
response = requests.post(api_url, json=params, headers=headers)
309+
310+
if response.status_code == 200:
311+
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
312+
ModelType.VIRTUAL_TABLE),
313+
response.status_code, response.text)
314+
else: # pragma: no cover
315+
print(GET_TREE_FAILED.format(response.status_code))
316+
return TspClientResponse(None, response.status_code, response.text)
283317

284318
def fetch_timegraph_tree(self, exp_uuid, output_id, parameters=None):
285319
'''

tsp/virtual_table_model.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (C) 2024 - Ericsson
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""VirtualTableModel class file."""
24+
25+
SIZE_KEY = "size"
26+
LOW_INDEX_KEY = "lowIndex"
27+
COLUMN_IDS_KEY = "columnIds"
28+
LINES_KEY = "lines"
29+
30+
TABLE_LINE_INDEX_KEY = "index"
31+
TABLE_LINE_CELLS_KEY = "cells"
32+
TABLE_LINE_CELL_CONTENT_KEY = "content"
33+
34+
35+
# pylint: disable=too-few-public-methods
36+
class VirtualTableModel:
37+
'''
38+
Virtual table model that will be returned by the server
39+
'''
40+
41+
def __init__(self, params):
42+
# Size of the virtual table
43+
self.size = 0
44+
if SIZE_KEY in params:
45+
if params.get(SIZE_KEY) is not None and type(params.get(SIZE_KEY)) is int:
46+
self.size = int(params.get(SIZE_KEY))
47+
del params[SIZE_KEY]
48+
49+
# Index of the first line in the virtual table
50+
self.low_index = 0
51+
if LOW_INDEX_KEY in params:
52+
if params.get(LOW_INDEX_KEY) is not None and type(params.get(LOW_INDEX_KEY)) is int:
53+
self.low_index = int(params.get(LOW_INDEX_KEY))
54+
del params[LOW_INDEX_KEY]
55+
56+
# Array of column IDs in the virtual table
57+
self.column_ids = []
58+
if COLUMN_IDS_KEY in params:
59+
if params.get(COLUMN_IDS_KEY) is not None:
60+
for column_id in params.get(COLUMN_IDS_KEY):
61+
self.column_ids.append(column_id)
62+
del params[COLUMN_IDS_KEY]
63+
64+
# Array of lines in the virtual table
65+
self.lines = []
66+
if LINES_KEY in params:
67+
for line in params.get(LINES_KEY):
68+
self.lines.append(VirtualTableLine(line))
69+
del params[LINES_KEY]
70+
71+
def print(self):
72+
print("VirtualTableModel:")
73+
print(f" size: {self.size}")
74+
print(f" low_index: {self.low_index}")
75+
print(f" column_ids: {self.column_ids}")
76+
77+
print(" lines:")
78+
for i, line in enumerate(self.lines):
79+
line.print()
80+
81+
class VirtualTableLine:
82+
'''
83+
Virtual table line that will be returned by the server
84+
'''
85+
86+
def __init__(self, params):
87+
# Index of the line in the virtual table
88+
self.index = -1
89+
if TABLE_LINE_INDEX_KEY in params:
90+
if params.get(TABLE_LINE_INDEX_KEY) is not None and type(params.get(TABLE_LINE_INDEX_KEY)) is int:
91+
self.index = int(params.get(TABLE_LINE_INDEX_KEY))
92+
del params[TABLE_LINE_INDEX_KEY]
93+
94+
# Array of cells in the line
95+
self.cells = []
96+
if TABLE_LINE_CELLS_KEY in params:
97+
if params.get(TABLE_LINE_CELLS_KEY) is not None:
98+
for cell in params.get(TABLE_LINE_CELLS_KEY):
99+
self.cells.append(VirtualTableLineCell(cell))
100+
del params[TABLE_LINE_CELLS_KEY]
101+
102+
def print(self):
103+
104+
print(f" index: {self.index}")
105+
print(" cells:")
106+
for i, cell in enumerate(self.cells):
107+
cell.print()
108+
print(f" {'-' * 10}")
109+
110+
class VirtualTableLineCell:
111+
'''
112+
Virtual table line cell that will be returned by the server
113+
'''
114+
115+
def __init__(self, params):
116+
# Content of the cell
117+
self.content = None
118+
if TABLE_LINE_CELL_CONTENT_KEY in params:
119+
if params.get(TABLE_LINE_CELL_CONTENT_KEY) is not None:
120+
self.content = params.get(TABLE_LINE_CELL_CONTENT_KEY)
121+
del params[TABLE_LINE_CELL_CONTENT_KEY]
122+
123+
def print(self):
124+
print(f" \"{TABLE_LINE_CELL_CONTENT_KEY}\": \"{self.content}\"")

tsp_cli_client

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ if __name__ == "__main__":
188188
help="Get details on the given output of a trace", metavar="OUTPUT_ID")
189189
parser.add_argument("--get-tree", dest="get_tree",
190190
help="Get the tree of an output of type DATA_TREE", metavar="OUTPUT_ID")
191+
parser.add_argument("--get-virtual-table-lines", dest="get_virtual_table_lines",
192+
help="Get the tree lines of an output of type DATA_TREE", metavar="OUTPUT_ID")
193+
parser.add_argument("--table-line-index", dest="table_line_index",
194+
help="The index of the table line to start fetching", metavar="TABLE_LINE_INDEX")
195+
parser.add_argument("--table-line-count", dest="table_line_count",
196+
help="The number of table lines to fetch", metavar="TABLE_LINE_COUNT")
197+
parser.add_argument("--table-times", dest="table_times",
198+
help="The list of times to fetch from table", nargs="*")
199+
parser.add_argument("--table-column-ids", dest="table_column_ids",
200+
help="The list of column ids to fetch", nargs="*")
201+
parser.add_argument("--table-search-direction", dest="table_search_direction",
202+
help="The direction to search for the table lines", metavar="TABLE_LINE_SEARCH_DIRECTION")
203+
parser.add_argument("--table-search-expression", action="append", nargs=2, metavar=("COLUMN_ID", "EXPRESSION"), dest="table_search_expression",
204+
help="The column's expression to search for the table lines")
191205
parser.add_argument("--get-timegraph-tree", dest="get_timegraph_tree",
192206
help="Get the tree of an output of type TIME_GRAPH", metavar="OUTPUT_ID")
193207
parser.add_argument("--get-xy-tree", dest="get_xy_tree",
@@ -407,6 +421,46 @@ if __name__ == "__main__":
407421
print(TRACE_MISSING)
408422
sys.exit(1)
409423

424+
if options.get_virtual_table_lines:
425+
if options.uuid is not None:
426+
if options.table_line_index is None and options.table_times is None:
427+
print("Provide at least one of requested --table-line-index or --table-times for the virtual table data")
428+
sys.exit(1)
429+
430+
if options.table_line_count is None:
431+
print("Provide requested --table-line-count for the virtual table data")
432+
sys.exit(1)
433+
434+
parameters = {
435+
TspClient.PARAMETERS_KEY: {
436+
TspClient.REQUESTED_TABLE_LINE_COUNT_KEY: int(options.table_line_count),
437+
TspClient.REQUESTED_TABLE_LINE_COLUMN_IDS_KEY: list(map(int, options.table_column_ids)) if options.table_column_ids is not None else [],
438+
TspClient.REQUESTED_TABLE_LINE_SEACH_DIRECTION_KEY: options.table_search_direction if options.table_search_direction is not None else "NEXT"
439+
}
440+
}
441+
442+
if options.table_times is not None:
443+
parameters[TspClient.PARAMETERS_KEY][TspClient.REQUESTED_TIME_KEY] = list(map(int, options.table_times))
444+
else:
445+
parameters[TspClient.PARAMETERS_KEY][TspClient.REQUESTED_TABLE_LINE_INDEX_KEY] = int(options.table_line_index)
446+
447+
if options.table_search_expression is not None:
448+
parameters[TspClient.PARAMETERS_KEY][TspClient.REQUESTED_TABLE_LINE_SEARCH_EXPRESSION_KEY] = {}
449+
for column_id, expression in options.table_search_expression:
450+
for column_id, expression in options.table_search_expression:
451+
parameters[TspClient.PARAMETERS_KEY][TspClient.REQUESTED_TABLE_LINE_SEARCH_EXPRESSION_KEY][str(column_id)] = str(expression)
452+
453+
response = tsp_client.fetch_virtual_table_lines(options.uuid, options.get_virtual_table_lines, parameters)
454+
if response.status_code == 200:
455+
model = response.model.model
456+
model.print()
457+
sys.exit(0)
458+
else:
459+
sys.exit(1)
460+
else:
461+
print(TRACE_MISSING)
462+
sys.exit(1)
463+
410464
if options.list_configuration_sources:
411465
response = tsp_client.fetch_configuration_sources()
412466
if response.status_code == 200:

0 commit comments

Comments
 (0)