Skip to content
Snippets Groups Projects
Commit 2eac7c1b authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-845: Return arrays as [y][x] just like Tango uses

parent b8f71ce1
No related branches found
No related tags found
1 merge request!5L2SS-845: Return arrays as [y][x] just like Tango uses
......@@ -211,9 +211,9 @@ class PrometheusRequests:
pass as `json["data"]["result"]` from raw json.
"""
def ord_index(metric: dict) -> str:
def ord_index(metric: dict) -> Tuple[str]:
"""Generate the ordered dict index from json metric"""
return f"{metric['x']}.{metric['y']}"
return (metric['x'], metric['y'])
result_dict = OrderedDict()
for json_result in json_results:
......@@ -233,15 +233,14 @@ class PrometheusRequests:
def _expand_convert_results_3d(
merged_results: OrderedDict,
) -> List[List[List[Tuple[datetime, any]]]]:
"""Expand the results into [x][y][tuple[datetime, value]] and convert values
"""Expand the results into [y][x][tuple[datetime, value]] and convert values
:param merged_results: Result from _merge_result_data
"""
def str_to_coords(coordinate: str) -> (int, int):
def str_to_coords(coordinate: Tuple[str]) -> (int, int):
"""Convert the string coordinate"""
split = coordinate.split(".", 1)
return int(split[0]), int(split[1])
return int(coordinate[0]), int(coordinate[1])
def convert_row(row: List[any], converter: Callable):
return datetime.fromtimestamp(row[0]), converter(row[1])
......@@ -250,13 +249,15 @@ class PrometheusRequests:
for key, values in merged_results.items():
x_index, y_index = str_to_coords(key)
# Store as [y][x], just like Tango
# Ensure outermost array sufficiently sized
while len(results) <= x_index:
while len(results) <= y_index:
results.append([[]])
# Ensure internal array sufficiently sized
while len(results[x_index]) <= y_index:
results[x_index].append([])
while len(results[y_index]) <= x_index:
results[y_index].append([])
# Per result determine the callable type converter
type_converter = PrometheusRequests._get_type_converter(
......@@ -264,6 +265,6 @@ class PrometheusRequests:
)
result = [convert_row(row, type_converter) for row in values["values"]]
results[x_index][y_index].extend(result)
results[y_index][x_index].extend(result)
return results
......@@ -301,7 +301,7 @@ class PrometheusTest(base.TestCase):
for result in reference_data["data"]["result"]:
metric = result["metric"]
index = f"{metric['x']}.{metric['y']}"
index = (metric['x'], metric['y'])
result_dict_timestamps = [
result[0] for result in result_dict[index]["values"]
......@@ -318,8 +318,7 @@ class PrometheusTest(base.TestCase):
def str_to_coords(coordinate: str) -> (int, int):
"""Convert the string coordinate"""
split = coordinate.split(".", 1)
return int(split[0]), int(split[1])
return int(coordinate[0]), int(coordinate[1])
for key, result in result_dict.items():
x, y = str_to_coords(key)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment