Skip to content

Commit 119ad0b

Browse files
kavehshahediMatthewKhouzam
authored andcommitted
Get virtual table header (i.e., columns)
1 parent 0f636f0 commit 119ad0b

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed

tsp/model_type.py

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

tsp/response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from tsp.model_type import ModelType
2828
from tsp.output_descriptor import OutputDescriptor
2929
from tsp.entry_model import EntryModel
30+
from tsp.virtual_tabel_header_model import VirtualTableHeaderModel
3031
from tsp.xy_model import XYModel
3132
from tsp.virtual_table_model import VirtualTableModel
3233

@@ -88,6 +89,8 @@ def __init__(self, params, model_type):
8889
self.model = XYModel(params.get(MODEL_KEY))
8990
elif self.model_type == ModelType.DATA_TREE:
9091
self.model = EntryModel(params.get(MODEL_KEY), self.model_type)
92+
elif self.model_type == ModelType.VIRTUAL_TABLE_HEADER:
93+
self.model = VirtualTableHeaderModel(params.get(MODEL_KEY))
9194
elif self.model_type == ModelType.VIRTUAL_TABLE:
9295
self.model = VirtualTableModel(params.get(MODEL_KEY))
9396

tsp/tsp_client.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TspClient:
5858
PARAMETERS_KEY = 'parameters'
5959
REQUESTED_TIME_KEY = 'requested_times'
6060
REQUESTED_ITEM_KEY = 'requested_items'
61-
61+
6262
REQUESTED_TIME_RANGE_KEY = 'requested_timerange'
6363
REQUESTED_TIME_RANGE_START_KEY = 'start'
6464
REQUESTED_TIME_RANGE_END_KEY = 'end'
@@ -286,7 +286,28 @@ def fetch_datatree(self, exp_uuid, output_id, parameters=None):
286286
else: # pragma: no cover
287287
print(GET_TREE_FAILED.format(response.status_code))
288288
return TspClientResponse(None, response.status_code, response.text)
289-
289+
290+
def fetch_virtual_table_columns(self, exp_uuid, output_id):
291+
'''
292+
Fetch Virtual Table columns, Model extends VirtualTableModel
293+
:param exp_uuid: Experiment UUID
294+
:param output_id: Output ID
295+
:returns: :class: `TspClientResponse <GenericResponse>` object Virtual Table columns response
296+
:rtype: TspClientResponse
297+
'''
298+
api_url = '{0}experiments/{1}/outputs/table/{2}/columns'.format(
299+
self.base_url, exp_uuid, output_id)
300+
301+
response = requests.post(api_url, json={}, headers=headers)
302+
303+
if response.status_code == 200:
304+
return TspClientResponse(GenericResponse(json.loads(response.content.decode('utf-8')),
305+
ModelType.VIRTUAL_TABLE_HEADER),
306+
response.status_code, response.text)
307+
else:
308+
print(GET_TREE_FAILED.format(response.status_code))
309+
return TspClientResponse(None, response.status_code, response.text)
310+
290311
def fetch_virtual_table_lines(self, exp_uuid, output_id, parameters=None):
291312
'''
292313
Fetch Virtual Table lines, Model extends VirtualTableModel
@@ -451,7 +472,6 @@ def fetch_configuration(self, type_id, config_id):
451472
print("failed to get configuration: {0}".format(response.status_code))
452473
return TspClientResponse(None, response.status_code, response.text)
453474

454-
455475
def post_configuration(self, type_id, params):
456476
'''
457477
Load an extension
@@ -480,7 +500,7 @@ def put_configuration(self, type_id, config_id, params):
480500
response = requests.put(api_url, json=parameters, headers=headers)
481501

482502
if response.status_code == 200:
483-
return TspClientResponse(Configuration(json.loads(response.content.decode('utf-8'))),
503+
return TspClientResponse(Configuration(json.loads(response.content.decode('utf-8'))),
484504
response.status_code, response.text)
485505
else: # pragma: no cover
486506
print("put extension failed: {0}".format(response.status_code))

tsp/virtual_tabel_header_model.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
"""Virtual table header model file."""
24+
25+
COLUMN_ID_KEY = "id"
26+
COLUMN_NAME_KEY = "name"
27+
COLUMN_DESCRIPTION_KEY = "description"
28+
COLUMN_TYPE_KEY = "type"
29+
30+
31+
class VirtualTableHeaderModel:
32+
'''
33+
Virtual table header model that will be returned by the server
34+
'''
35+
36+
def __init__(self, params):
37+
# Array of columns in the virtual table
38+
self.columns = []
39+
if params is not None:
40+
for column in params:
41+
# Column ID
42+
column_id = None
43+
if COLUMN_ID_KEY in column:
44+
column_id = column.get(COLUMN_ID_KEY)
45+
del column[COLUMN_ID_KEY]
46+
47+
# Column name
48+
column_name = None
49+
if COLUMN_NAME_KEY in column:
50+
column_name = column.get(COLUMN_NAME_KEY)
51+
del column[COLUMN_NAME_KEY]
52+
53+
# Column description
54+
column_description = None
55+
if COLUMN_DESCRIPTION_KEY in column:
56+
column_description = column.get(COLUMN_DESCRIPTION_KEY)
57+
del column[COLUMN_DESCRIPTION_KEY]
58+
59+
# Column type
60+
column_type = None
61+
if COLUMN_TYPE_KEY in column:
62+
column_type = column.get(COLUMN_TYPE_KEY)
63+
del column[COLUMN_TYPE_KEY]
64+
65+
# Add column to the list
66+
self.columns.append({
67+
COLUMN_ID_KEY: column_id,
68+
COLUMN_NAME_KEY: column_name,
69+
COLUMN_DESCRIPTION_KEY: column_description,
70+
COLUMN_TYPE_KEY: column_type
71+
})
72+
73+
def print(self):
74+
'''
75+
Print the virtual table header model
76+
'''
77+
print("Virtual Table Columns:")
78+
for column in self.columns:
79+
print(" id: " + str(column.get(COLUMN_ID_KEY)))
80+
print(" name: " + str(column.get(COLUMN_NAME_KEY)))
81+
print(" description: " + str(column.get(COLUMN_DESCRIPTION_KEY)))
82+
print(" type: " + str(column.get(COLUMN_TYPE_KEY)))
83+
print("-" * 50)

tsp_cli_client

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ 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-columns", dest="get_virtual_table_columns",
192+
help="Get the columns of an output of type DATA_TREE", metavar="OUTPUT_ID")
191193
parser.add_argument("--get-virtual-table-lines", dest="get_virtual_table_lines",
192194
help="Get the tree lines of an output of type DATA_TREE", metavar="OUTPUT_ID")
193195
parser.add_argument("--table-line-index", dest="table_line_index",
@@ -421,6 +423,21 @@ if __name__ == "__main__":
421423
print(TRACE_MISSING)
422424
sys.exit(1)
423425

426+
if options.get_virtual_table_columns:
427+
if options.uuid is not None:
428+
response = tsp_client.fetch_virtual_table_columns(
429+
options.uuid, options.get_virtual_table_columns)
430+
431+
if response.status_code == 200:
432+
model = response.model.model
433+
model.print()
434+
sys.exit(0)
435+
else:
436+
sys.exit(1)
437+
else:
438+
print(TRACE_MISSING)
439+
sys.exit(1)
440+
424441
if options.get_virtual_table_lines:
425442
if options.uuid is not None:
426443
if options.table_line_index is None and options.table_times is None:

0 commit comments

Comments
 (0)