Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/picterra/tracer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def analyze_plots(
plot_ids: List[str],
date_from: datetime.date,
date_to: datetime.date,
tag_name: Optional[str] = None,
) -> str:
"""
Runs the analysis for a given date over the plot ids of the specified plot group,
Expand All @@ -285,6 +286,7 @@ def analyze_plots(
that **the date that make sense are methodology dependent**, so please check the
methodology of the plots group beforehand
date_to: end point in time at which the analysis should be evaluated.
tag_name: name of the methodology version to run

Returns:
str: the analysis id.
Expand All @@ -296,6 +298,8 @@ def analyze_plots(
"date_from": date_from.isoformat(),
"date_to": date_to.isoformat(),
}
if tag_name is not None:
data.update({"tag_name": tag_name})
resp = self.sess.post(
self._full_url(f"plots_groups/{plots_group_id}/analysis/"), json=data
)
Expand Down
34 changes: 13 additions & 21 deletions tests/test_tracer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import tempfile

import pytest
import responses

from picterra import TracerClient
Expand Down Expand Up @@ -143,8 +144,9 @@ def test_update_plots_group_plots(monkeypatch):
client.update_plots_group_plots("group-id", [tmp.name])


@pytest.mark.parametrize("tag_name", [None, "v0"])
@responses.activate
def test_analyse_plots(monkeypatch):
def test_analyse_plots(monkeypatch, tag_name):
_add_api_response(
plots_analysis_api_url("upload/file/"),
responses.POST,
Expand All @@ -163,35 +165,34 @@ def test_analyse_plots(monkeypatch):
)
],
)
expected_params = {
"analysis_name": "foobar",
"upload_id": "an-upload-id",
"date_from": "2023-01-01",
"date_to": "2025-01-01",
}
if tag_name is not None:
expected_params.update({ "tag_name": tag_name })
_add_api_response(
plots_analysis_api_url("plots_groups/a-group-id/analysis/"),
responses.POST,
OP_RESP,
match=responses.matchers.json_params_matcher(
{
"analysis_name": "foobar",
"upload_id": "an-upload-id",
"date_from": "2023-01-01",
"date_to": "2025-01-01",
}
),
match=responses.matchers.json_params_matcher(expected_params),
)
_add_api_response(
plots_analysis_api_url(f"operations/{OPERATION_ID}/"),
responses.GET,
{"status": "success", "results": {"analysis_id": "an-analysis-id"}},
)
client: TracerClient = _client(monkeypatch, platform="plots_analysis")
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, "w") as f:
json.dump({"type": "FeatureCollection", "features": []}, f)
assert (
client.analyze_plots(
"a-group-id",
"foobar",
["uno", "dos"],
datetime.date.fromisoformat("2023-01-01"),
datetime.date.fromisoformat("2025-01-01"),
tag_name=tag_name,
)
== "an-analysis-id"
)
Expand Down Expand Up @@ -246,9 +247,6 @@ def test_analyse_precheck(monkeypatch):
}
responses.get("https://precheck_data_url.example.com/", json=precheck)
client: TracerClient = _client(monkeypatch, platform="plots_analysis")
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, "w") as f:
json.dump({"type": "FeatureCollection", "features": []}, f)
assert (
client.analyze_plots_precheck(
"a-group-id",
Expand Down Expand Up @@ -438,9 +436,6 @@ def test_create_plots_analysis_report_precheck(monkeypatch):
},
)
client: TracerClient = _client(monkeypatch, platform="plots_analysis")
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, "w") as f:
json.dump({"type": "FeatureCollection", "features": []}, f)
assert client.create_plots_analysis_report_precheck(
"an-analysis-id",
"foobar",
Expand Down Expand Up @@ -489,9 +484,6 @@ def test_create_plots_analysis_report(monkeypatch):
{"status": "success", "results": {"plots_analysis_report_id": "a-report-id"}},
)
client: TracerClient = _client(monkeypatch, platform="plots_analysis")
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, "w") as f:
json.dump({"type": "FeatureCollection", "features": []}, f)
assert (
client.create_plots_analysis_report(
"an-analysis-id",
Expand Down
Loading