Skip to content
Snippets Groups Projects
Verified Commit 8a9d2850 authored by David Hoese's avatar David Hoese
Browse files

Fix influxdbv2 bad order when wind direction is present

parent 476d1f54
Branches
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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())
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment