Skip to content

Commit

Permalink
Get-XY with time range option (#62)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kavehshahedi committed May 28, 2024
1 parent 27422bf commit 5ded7d6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ usage: tsp_cli_client [-h] [--ip IP] [--port PORT]
[--list-output OUTPUT_ID] [--get-tree OUTPUT_ID]
[--get-timegraph-tree OUTPUT_ID]
[--get-xy-tree OUTPUT_ID] [--get-xy OUTPUT_ID]
[--items [ITEMS ...]] [--times [TIMES ...]]
[--items [ITEMS ...]] [--time-range START END NUM_TIMES]
[--uuid UUID] [--uuids [UUIDS ...]] [--do-delete-traces]
[--paths [PATHS ...]]
[--list-configuration-sources]
Expand Down Expand Up @@ -111,7 +111,8 @@ optional arguments:
Get the tree of an output of type TREE_TIME_XY
--get-xy OUTPUT_ID Get the XY data of an output
--items [ITEMS ...] The list of XY items requested
--times [TIMES ...] The list of XY times requested
--time-range START END NUM_TIMES
The time range requested
--uuid UUID The UUID of a trace
--uuids [UUIDS ...] The list of UUIDs
--do-delete-traces Also delete traces when deleting experiment
Expand Down Expand Up @@ -152,7 +153,7 @@ Examples:
./tsp_cli_client --get-tree OUTPUT_ID --uuid UUID
./tsp_cli_client --get-timegraph-tree OUTPUT_ID --uuid UUID
./tsp_cli_client --get-xy-tree OUTPUT_ID --uuid UUID
./tsp_cli_client --get-xy OUTPUT_ID --uuid UUID --items ITEMS --times TIMES
./tsp_cli_client --get-xy OUTPUT_ID --uuid UUID --items ITEMS --time-range START END NUM_TIMES
./tsp_cli_client --list-configuration-sources
./tsp_cli_client --list-configuration-source TYPE_ID
./tsp_cli_client --list-configurations TYPE_ID
Expand Down
5 changes: 5 additions & 0 deletions tsp/tsp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class TspClient:
PARAMETERS_KEY = 'parameters'
REQUESTED_TIME_KEY = 'requested_times'
REQUESTED_ITEM_KEY = 'requested_items'

REQUESTED_TIME_RANGE_KEY = 'requested_timerange'
REQUESTED_TIME_RANGE_START_KEY = 'start'
REQUESTED_TIME_RANGE_END_KEY = 'end'
REQUESTED_TIME_RANGE_NUM_TIMES_KEY = 'nbTimes'

def __init__(self, base_url):
'''
Expand Down
25 changes: 15 additions & 10 deletions tsp/xy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, params):
self.series.append(XYSeries(series))
del params[SERIES_KEY]

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

for series in self.series:
series.print()
series.print(array_print)


class XYSeries:
Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(self, params):
self.tags.append(tag)
del params[TAGS_KEY]

def print(self): # pragma: no cover
def print(self, array_print=False): # pragma: no cover
'''
XY series rendering below
'''
Expand All @@ -132,13 +132,18 @@ def print(self): # pragma: no cover
if hasattr(self, 'x_axis'):
print(f' Series X-axis:\n{self.x_axis.print()}')
print(f' Series Y-axis:\n{self.y_axis.print()}')
for value in self.x_values:
print(f' Series X-value: {value}')
for value in self.y_values:
print(f' Series Y-value: {value}')
for tag in self.tags:
print(f' Series tag: {tag}')


if not array_print:
for value in self.x_values:
print(f' Series X-value: {value}')
for value in self.y_values:
print(f' Series Y-value: {value}')
for tag in self.tags:
print(f' Series tag: {tag}')
else:
print(f' Series X-values: {self.x_values}')
print(f' Series Y-values: {self.y_values}')
print(f' Series tags: {self.tags}')

class XYAxis:
'''
Expand Down
29 changes: 22 additions & 7 deletions tsp_cli_client
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ if __name__ == "__main__":
help="Get the XY data of an output", metavar="OUTPUT_ID")
parser.add_argument("--items", dest="items",
help="The list of XY items requested", nargs="*")
parser.add_argument("--times", dest="times",
help="The list of XY times requested", nargs="*")
parser.add_argument("--time-range", dest="time_range",
help="The time range requested", nargs=3, metavar=("START", "END", "NUM_TIMES"))
parser.add_argument("--uuid", dest="uuid", help="The UUID of a trace")
parser.add_argument("--uuids", dest="uuids",
help="The list of UUIDs", nargs="*")
Expand Down Expand Up @@ -370,20 +370,35 @@ if __name__ == "__main__":
__get_tree(options.uuid, options.get_xy_tree, "TREE_TIME_XY")

if options.get_xy:
if not options.items or not options.times:
print("Provide requested --items and --times for the XY data")
if not options.items:
print("Provide requested --items for the XY data")
sys.exit(1)

if not options.time_range:
print("Provide requested --time-range for the XY data")
sys.exit(1)

if options.uuid is not None:
parameters = {TspClient.REQUESTED_TIME_KEY: list(map(int, options.times)),
TspClient.REQUESTED_ITEM_KEY: list(map(int, options.items))}
start_time = int(options.time_range[0])
end_time = int(options.time_range[1])
nb_times = int(options.time_range[2])

parameters = {
TspClient.REQUESTED_ITEM_KEY: list(map(int, options.items)),
TspClient.REQUESTED_TIME_RANGE_KEY: {
TspClient.REQUESTED_TIME_RANGE_START_KEY: start_time,
TspClient.REQUESTED_TIME_RANGE_END_KEY: end_time,
TspClient.REQUESTED_TIME_RANGE_NUM_TIMES_KEY: nb_times
}
}

params = {TspClient.PARAMETERS_KEY: parameters}

response = tsp_client.fetch_xy(
options.uuid, options.get_xy, params)
if response.status_code == 200:
xyModel = response.model.model
xyModel.print()
xyModel.print(array_print=True)
sys.exit(0)
else:
sys.exit(1)
Expand Down

0 comments on commit 5ded7d6

Please sign in to comment.