Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
MetObsAPI
Commits
8a9d2850
Verified
Commit
8a9d2850
authored
2 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Fix influxdbv2 bad order when wind direction is present
parent
476d1f54
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
metobsapi/data_api.py
+6
-2
6 additions, 2 deletions
metobsapi/data_api.py
metobsapi/tests/test_data_api.py
+8
-0
8 additions, 0 deletions
metobsapi/tests/test_data_api.py
metobsapi/util/query_influx.py
+1
-1
1 addition, 1 deletion
metobsapi/util/query_influx.py
with
15 additions
and
3 deletions
metobsapi/data_api.py
+
6
−
2
View file @
8a9d2850
...
...
@@ -103,16 +103,20 @@ def _get_column_name_in_influxdb(site: str, inst: str, api_symbol: str) -> str:
def
handle_influxdb_result
(
data_frame
,
influx_to_requested_symbols
):
valid_requested_symbols
=
[
symbol
for
symbol
in
influx_to_requested_symbols
.
values
()
if
symbol
is
not
None
]
if
data_frame
is
None
:
# invalid query
valid_requested_symbols
=
[
symbol
for
symbol
in
influx_to_requested_symbols
.
values
()
if
symbol
is
not
None
]
return
_create_empty_dataframe_for_columns
(
valid_requested_symbols
)
data_frame
=
_convert_wind_vectors_to_direction_if_needed
(
data_frame
)
data_frame
=
data_frame
.
round
({
s
:
ROUNDING
.
get
(
s
,
1
)
for
s
in
data_frame
.
columns
})
# reorder columns to match the order the user requested
new_column_order
=
[
influx_name
for
influx_name
in
influx_to_requested_symbols
if
influx_name
in
data_frame
.
columns
]
data_frame
=
data_frame
[
new_column_order
]
# rename columns to API names requested by the user
# User could request "<site>.<inst>.name" or just "name"
data_frame
.
columns
=
valid_requested_symbols
renamed_columns
=
[
influx_to_requested_symbols
[
symbol
]
for
symbol
in
data_frame
.
columns
]
data_frame
.
columns
=
renamed_columns
return
data_frame
...
...
This diff is collapsed.
Click to expand it.
metobsapi/tests/test_data_api.py
+
8
−
0
View file @
8a9d2850
...
...
@@ -345,6 +345,14 @@ def test_shorthand_two_symbols_json_column_order_check(client):
assert
res1
[
"
results
"
][
"
data
"
][
"
rel_hum
"
]
==
res2
[
"
results
"
][
"
data
"
][
"
rel_hum
"
]
@pytest.mark.usefixtures
(
"
influxdb_wind_fields_9_values
"
)
def
test_shorthand_wind_symbols_json_column_order_check
(
client
):
res1
=
_query_with_symbols
(
client
,
"
wind_speed:wind_direction
"
)
res2
=
_query_with_symbols
(
client
,
"
wind_direction:wind_speed
"
)
assert
res1
[
"
results
"
][
"
data
"
][
"
wind_speed
"
]
==
res2
[
"
results
"
][
"
data
"
][
"
wind_speed
"
]
assert
res1
[
"
results
"
][
"
data
"
][
"
wind_direction
"
]
==
res2
[
"
results
"
][
"
data
"
][
"
wind_direction
"
]
def
_query_with_symbols
(
client
,
symbols
:
str
)
->
dict
:
res
=
client
.
get
(
f
"
/api/data.json?site=aoss&inst=tower&symbols=
{
symbols
}
&begin=-00:10:00&order=column
"
)
res
=
json
.
loads
(
res
.
data
.
decode
())
...
...
This diff is collapsed.
Click to expand it.
metobsapi/util/query_influx.py
+
1
−
1
View file @
8a9d2850
...
...
@@ -91,7 +91,7 @@ class QueryHandler:
data_frame
=
data_frame
.
drop
(
columns
=
[
"
site
"
,
"
inst
"
])
# get dataframe into the same order that was requested
data_frame
=
data_frame
[
symbol_names
]
# "_time" should already be set as the index so we don't need to rename it
# "_time" should already be set as the index
,
so we don't need to rename it
new_column_names
=
[
f
"
{
site
}
.
{
inst
}
.
{
col_name
}
"
for
col_name
in
data_frame
.
columns
]
data_frame
.
columns
=
new_column_names
frames_to_concat
.
append
(
data_frame
)
...
...
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