Skip to content

Commit 50d72ce

Browse files
committed
Add a 'run_dataset_recommendation' method
1 parent faf681b commit 50d72ce

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/picterra/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,21 @@ def train_detector(self, detector_id):
833833
raise APIError(resp.text)
834834
return self._wait_until_operation_completes(resp.json())
835835

836+
def run_dataset_recommendation(self, detector_id):
837+
"""
838+
This is an **experimental** feature
839+
840+
Runs dataset recommendation on a detector. Note that you currently have to use
841+
the UI to be able to view the recommendation markers/report.
842+
843+
Args:
844+
detector_id (str): The id of the detector
845+
"""
846+
resp = self.sess.post(self._api_url("detectors/%s/dataset_recommendation/" % detector_id))
847+
if not resp.ok:
848+
raise APIError(resp.text)
849+
return self._wait_until_operation_completes(resp.json())
850+
836851
def run_advanced_tool(self, tool_id: UUID, inputs: dict, outputs: dict):
837852
"""
838853
This is an experimental feature

tests/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ def add_mock_detector_edit_response(d_id, **kwargs):
202202
def add_mock_detector_train_responses(detector_id):
203203
_add_api_response("detectors/%s/train/" % detector_id, responses.POST, OP_RESP)
204204

205+
def add_mock_run_dataset_recommendation_responses(detector_id):
206+
_add_api_response("detectors/%s/dataset_recommendation/" % detector_id, responses.POST, OP_RESP)
207+
205208

206209
def add_mock_operations_responses(status, **kwargs):
207210
data = {"type": "mock_operation_type", "status": status}
@@ -876,6 +879,18 @@ def test_train_detector():
876879
assert len(responses.calls) == 4
877880

878881

882+
@responses.activate
883+
def test_run_dataset_recommendation():
884+
add_mock_run_dataset_recommendation_responses(1)
885+
add_mock_operations_responses("running")
886+
add_mock_operations_responses("running")
887+
add_mock_operations_responses("success")
888+
client = _client()
889+
op = client.run_dataset_recommendation(1)
890+
assert op["status"] == "success"
891+
assert len(responses.calls) == 4
892+
893+
879894
@pytest.mark.parametrize(("name", "color"), ((None, None), ("foobar", "#aabbcc")))
880895
@responses.activate
881896
def test_upload_vector_layer(name, color):

0 commit comments

Comments
 (0)