Skip to content
Snippets Groups Projects

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

Merged L2SS-845: Return arrays as [y][x] just like Tango uses
All threads resolved!
Merged Jan David Mol requested to merge L2SS-845-swap-x-y into main
All threads resolved!
Files
3
@@ -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
Loading