diff --git a/metobsapi/data_api.py b/metobsapi/data_api.py index f2c7e2bf0aaf8f83bc4da81bdb5b74af56625df7..ef23a6befc147d4bcaff7947be2346b3fc9efc5c 100644 --- a/metobsapi/data_api.py +++ b/metobsapi/data_api.py @@ -75,10 +75,11 @@ def handle_symbols(symbols: list[str]): # detecting 'wind_direction', otherwise we don't know we need to readd it influx_to_requested_symbols[f"{site}.{inst}.{influx_name}"] = symbol + influx_symbols.setdefault((site, inst), []) if s == "wind_direction": add_winds.add((site, inst)) continue - influx_symbols.setdefault((site, inst), []).append(influx_name) + influx_symbols[(site, inst)].append(influx_name) # Add the symbols needed to compute the wind_speed and wind_direction for site, inst in add_winds: diff --git a/metobsapi/tests/test_data_api.py b/metobsapi/tests/test_data_api.py index 78ec1a4a2ddc4ed5b5ded37c0ecfcf9b7eff9e9a..815934240db0e84a7c24e36a8c653eb77e088545 100644 --- a/metobsapi/tests/test_data_api.py +++ b/metobsapi/tests/test_data_api.py @@ -402,6 +402,22 @@ def test_wind_speed_direction_json(symbols, client): assert len(list(res["results"]["data"].keys())) == len(symbols) +@pytest.mark.usefixtures("influxdb_wind_fields_9_values") +def test_wind_direction_only_json(client): + symbols = ["wind_direction"] + symbol_param = ":".join(symbols) + site_inst_params = "&site=aoss&inst=tower" + + res = client.get(f"/api/data.json?symbols={symbol_param}{site_inst_params}&begin=-00:10:00&order=column") + res = json.loads(res.data.decode()) + assert res["code"] == 200 + assert res["num_results"] == 9 + for symbol_name in symbols: + assert symbol_name in res["results"]["data"] + assert not np.isnan(res["results"]["data"][symbol_name]).all() + assert len(list(res["results"]["data"].keys())) == len(symbols) + + def test_one_symbol_two_insts_json_row(client, mock_influxdb_query): fake_result = _fake_data( "1m",