Skip to content

Commit 5ded7d6

Browse files
authored
Get-XY with time range option (#62)
* Add time range implementation for the get-xy functionality * Add array print mode for the get-xy time range option * Remove --times argument from get-xy (it is deprecated in the tsp server) * Update readme for --time-range argument
1 parent 27422bf commit 5ded7d6

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ usage: tsp_cli_client [-h] [--ip IP] [--port PORT]
6868
[--list-output OUTPUT_ID] [--get-tree OUTPUT_ID]
6969
[--get-timegraph-tree OUTPUT_ID]
7070
[--get-xy-tree OUTPUT_ID] [--get-xy OUTPUT_ID]
71-
[--items [ITEMS ...]] [--times [TIMES ...]]
71+
[--items [ITEMS ...]] [--time-range START END NUM_TIMES]
7272
[--uuid UUID] [--uuids [UUIDS ...]] [--do-delete-traces]
7373
[--paths [PATHS ...]]
7474
[--list-configuration-sources]
@@ -111,7 +111,8 @@ optional arguments:
111111
Get the tree of an output of type TREE_TIME_XY
112112
--get-xy OUTPUT_ID Get the XY data of an output
113113
--items [ITEMS ...] The list of XY items requested
114-
--times [TIMES ...] The list of XY times requested
114+
--time-range START END NUM_TIMES
115+
The time range requested
115116
--uuid UUID The UUID of a trace
116117
--uuids [UUIDS ...] The list of UUIDs
117118
--do-delete-traces Also delete traces when deleting experiment
@@ -152,7 +153,7 @@ Examples:
152153
./tsp_cli_client --get-tree OUTPUT_ID --uuid UUID
153154
./tsp_cli_client --get-timegraph-tree OUTPUT_ID --uuid UUID
154155
./tsp_cli_client --get-xy-tree OUTPUT_ID --uuid UUID
155-
./tsp_cli_client --get-xy OUTPUT_ID --uuid UUID --items ITEMS --times TIMES
156+
./tsp_cli_client --get-xy OUTPUT_ID --uuid UUID --items ITEMS --time-range START END NUM_TIMES
156157
./tsp_cli_client --list-configuration-sources
157158
./tsp_cli_client --list-configuration-source TYPE_ID
158159
./tsp_cli_client --list-configurations TYPE_ID

tsp/tsp_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class TspClient:
5757
PARAMETERS_KEY = 'parameters'
5858
REQUESTED_TIME_KEY = 'requested_times'
5959
REQUESTED_ITEM_KEY = 'requested_items'
60+
61+
REQUESTED_TIME_RANGE_KEY = 'requested_timerange'
62+
REQUESTED_TIME_RANGE_START_KEY = 'start'
63+
REQUESTED_TIME_RANGE_END_KEY = 'end'
64+
REQUESTED_TIME_RANGE_NUM_TIMES_KEY = 'nbTimes'
6065

6166
def __init__(self, base_url):
6267
'''

tsp/xy_model.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, params):
5858
self.series.append(XYSeries(series))
5959
del params[SERIES_KEY]
6060

61-
def print(self): # pragma: no cover
61+
def print(self, array_print=False): # pragma: no cover
6262
'''
6363
XY model rendering below
6464
'''
@@ -70,7 +70,7 @@ def print(self): # pragma: no cover
7070
print(f'XY has common X axis: {common_x_axis}')
7171

7272
for series in self.series:
73-
series.print()
73+
series.print(array_print)
7474

7575

7676
class XYSeries:
@@ -122,7 +122,7 @@ def __init__(self, params):
122122
self.tags.append(tag)
123123
del params[TAGS_KEY]
124124

125-
def print(self): # pragma: no cover
125+
def print(self, array_print=False): # pragma: no cover
126126
'''
127127
XY series rendering below
128128
'''
@@ -132,13 +132,18 @@ def print(self): # pragma: no cover
132132
if hasattr(self, 'x_axis'):
133133
print(f' Series X-axis:\n{self.x_axis.print()}')
134134
print(f' Series Y-axis:\n{self.y_axis.print()}')
135-
for value in self.x_values:
136-
print(f' Series X-value: {value}')
137-
for value in self.y_values:
138-
print(f' Series Y-value: {value}')
139-
for tag in self.tags:
140-
print(f' Series tag: {tag}')
141-
135+
136+
if not array_print:
137+
for value in self.x_values:
138+
print(f' Series X-value: {value}')
139+
for value in self.y_values:
140+
print(f' Series Y-value: {value}')
141+
for tag in self.tags:
142+
print(f' Series tag: {tag}')
143+
else:
144+
print(f' Series X-values: {self.x_values}')
145+
print(f' Series Y-values: {self.y_values}')
146+
print(f' Series tags: {self.tags}')
142147

143148
class XYAxis:
144149
'''

tsp_cli_client

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ if __name__ == "__main__":
196196
help="Get the XY data of an output", metavar="OUTPUT_ID")
197197
parser.add_argument("--items", dest="items",
198198
help="The list of XY items requested", nargs="*")
199-
parser.add_argument("--times", dest="times",
200-
help="The list of XY times requested", nargs="*")
199+
parser.add_argument("--time-range", dest="time_range",
200+
help="The time range requested", nargs=3, metavar=("START", "END", "NUM_TIMES"))
201201
parser.add_argument("--uuid", dest="uuid", help="The UUID of a trace")
202202
parser.add_argument("--uuids", dest="uuids",
203203
help="The list of UUIDs", nargs="*")
@@ -370,20 +370,35 @@ if __name__ == "__main__":
370370
__get_tree(options.uuid, options.get_xy_tree, "TREE_TIME_XY")
371371

372372
if options.get_xy:
373-
if not options.items or not options.times:
374-
print("Provide requested --items and --times for the XY data")
373+
if not options.items:
374+
print("Provide requested --items for the XY data")
375+
sys.exit(1)
376+
377+
if not options.time_range:
378+
print("Provide requested --time-range for the XY data")
375379
sys.exit(1)
376380

377381
if options.uuid is not None:
378-
parameters = {TspClient.REQUESTED_TIME_KEY: list(map(int, options.times)),
379-
TspClient.REQUESTED_ITEM_KEY: list(map(int, options.items))}
382+
start_time = int(options.time_range[0])
383+
end_time = int(options.time_range[1])
384+
nb_times = int(options.time_range[2])
385+
386+
parameters = {
387+
TspClient.REQUESTED_ITEM_KEY: list(map(int, options.items)),
388+
TspClient.REQUESTED_TIME_RANGE_KEY: {
389+
TspClient.REQUESTED_TIME_RANGE_START_KEY: start_time,
390+
TspClient.REQUESTED_TIME_RANGE_END_KEY: end_time,
391+
TspClient.REQUESTED_TIME_RANGE_NUM_TIMES_KEY: nb_times
392+
}
393+
}
394+
380395
params = {TspClient.PARAMETERS_KEY: parameters}
381396

382397
response = tsp_client.fetch_xy(
383398
options.uuid, options.get_xy, params)
384399
if response.status_code == 200:
385400
xyModel = response.model.model
386-
xyModel.print()
401+
xyModel.print(array_print=True)
387402
sys.exit(0)
388403
else:
389404
sys.exit(1)

0 commit comments

Comments
 (0)