From b84e9a0b52899eb930b92b49430b5ab8f4ab0f70 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 26 Feb 2024 15:11:31 +0000 Subject: [PATCH] Fix time searching (#336) * Add online test for Time search parameter * Bit of tidying * Add another constraint to make sure we get the right dataset * Parametrize the test because that's how we do things * Revert "Use execTime for fido search (#326)" This reverts commit 62039c25ada619db57e2d23ca872e387d85d66a2. * Use startTime for fido search again, but right this time * Put the parameters the right way round so it actually works * Add changelog --- changelog/336.bugfix.rst | 1 + dkist/net/attr_walker.py | 4 ++-- dkist/net/tests/conftest.py | 2 +- dkist/net/tests/test_attr_walker.py | 12 ++++++------ dkist/net/tests/test_client.py | 13 +++++++++++++ 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 changelog/336.bugfix.rst diff --git a/changelog/336.bugfix.rst b/changelog/336.bugfix.rst new file mode 100644 index 00000000..f63ccabb --- /dev/null +++ b/changelog/336.bugfix.rst @@ -0,0 +1 @@ +Correct Fido time searching to use `endTimeMin` and `startTimeMax` (in the correct order) so that searching returns any dataset with a partially or completely overlapping time range. diff --git a/dkist/net/attr_walker.py b/dkist/net/attr_walker.py index 6ac55aa0..faa13681 100644 --- a/dkist/net/attr_walker.py +++ b/dkist/net/attr_walker.py @@ -53,8 +53,8 @@ def iterate_over_and(wlk, tree, params): # SunPy Attrs @walker.add_applier(Time) def _(wlk, attr, params): - return params.update({'execTimeMin': attr.start.isot, - 'execTimeMax': attr.end.isot}) + return params.update({'endTimeMin': attr.start.isot, + 'startTimeMax': attr.end.isot}) @walker.add_applier(Instrument) diff --git a/dkist/net/tests/conftest.py b/dkist/net/tests/conftest.py index ca599b16..38b01d9b 100644 --- a/dkist/net/tests/conftest.py +++ b/dkist/net/tests/conftest.py @@ -28,7 +28,7 @@ def api_param_names(): Excludes ones with input dependant query params """ return { - a.Time: ('execTimeMin', 'execTimeMax'), + a.Time: ('endTimeMin', 'startTimeMax'), a.Instrument: ('instrumentNames',), a.Wavelength: ('wavelengthRanges',), a.Physobs: ('hasAllStokes',), diff --git a/dkist/net/tests/test_attr_walker.py b/dkist/net/tests/test_attr_walker.py index 51dfcfcb..467f670d 100644 --- a/dkist/net/tests/test_attr_walker.py +++ b/dkist/net/tests/test_attr_walker.py @@ -166,8 +166,8 @@ def test_and_simple(query_and_simple): assert out == [ { "instrumentNames": "VBI", - "execTimeMin": "2020-06-01T00:00:00.000", - "execTimeMax": "2020-06-02T00:00:00.000", + "endTimeMin": "2020-06-01T00:00:00.000", + "startTimeMax": "2020-06-02T00:00:00.000", } ] @@ -181,12 +181,12 @@ def test_or_instrument(query_or_instrument): assert out == [ { "instrumentNames": "VBI", - "execTimeMin": "2020-06-01T00:00:00.000", - "execTimeMax": "2020-06-02T00:00:00.000", + "endTimeMin": "2020-06-01T00:00:00.000", + "startTimeMax": "2020-06-02T00:00:00.000", }, { "instrumentNames": "VISP", - "execTimeMin": "2020-06-01T00:00:00.000", - "execTimeMax": "2020-06-02T00:00:00.000", + "endTimeMin": "2020-06-01T00:00:00.000", + "startTimeMax": "2020-06-02T00:00:00.000", } ] diff --git a/dkist/net/tests/test_client.py b/dkist/net/tests/test_client.py index 614abce5..998700a8 100644 --- a/dkist/net/tests/test_client.py +++ b/dkist/net/tests/test_client.py @@ -28,6 +28,19 @@ def test_search(client): res = client.search(a.Time("2019/01/01", "2021/01/01")) +@pytest.mark.remote_data +@pytest.mark.parametrize("time", [ + a.Time("2022/12/27 19:55", "2022/12/27 20:01"), # Time range overlaps the end of the dataset + a.Time("2022/12/27 19:26", "2022/12/27 19:30"), # Time range overlaps the start of the dataset + a.Time("2022/12/27 19:30", "2022/12/27 19:35"), # Time range within the dataset + a.Time("2022/12/27 19:26", "2022/12/27 20:01"), # Time range contains dataset +]) +def test_search_by_time(client, time): + res = client.search(time, a.Instrument("VBI")) + assert len(res) == 1 + assert res[0]["Primary Proposal ID"] == "pid_1_50" + assert res[0]["Start Time"].value == '2022-12-27T19:27:42.338' and res[0]["End Time"].value == '2022-12-27T20:00:09.005' + @pytest.fixture def empty_query_response(): return DKISTQueryResponseTable()