Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LOFAR Station Client
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
LOFAR2.0
LOFAR Station Client
Commits
2eac7c1b
Commit
2eac7c1b
authored
2 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-845
: Return arrays as [y][x] just like Tango uses
parent
b8f71ce1
No related branches found
No related tags found
1 merge request
!5
L2SS-845: Return arrays as [y][x] just like Tango uses
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lofar_station_client/requests/prometheus.py
+11
-10
11 additions, 10 deletions
lofar_station_client/requests/prometheus.py
tests/requests/test_prometheus.py
+2
-3
2 additions, 3 deletions
tests/requests/test_prometheus.py
with
13 additions
and
13 deletions
lofar_station_client/requests/prometheus.py
+
11
−
10
View file @
2eac7c1b
...
...
@@ -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
This diff is collapsed.
Click to expand it.
tests/requests/test_prometheus.py
+
2
−
3
View file @
2eac7c1b
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment