From 515d9355076d38388a61cbc128313880a51d5c6c Mon Sep 17 00:00:00 2001 From: atmorling Date: Wed, 4 Dec 2024 15:03:41 +0200 Subject: [PATCH] Add patrol start time to get_patrol_events (#350) --- ecoscope/io/earthranger.py | 1 + tests/test_earthranger_io.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ecoscope/io/earthranger.py b/ecoscope/io/earthranger.py index a0966381..90364c71 100644 --- a/ecoscope/io/earthranger.py +++ b/ecoscope/io/earthranger.py @@ -743,6 +743,7 @@ def get_patrol_events( for event in segment.get("events", []): event["patrol_id"] = row.get("id") event["patrol_segment_id"] = segment.get("id") + event["patrol_start_time"] = (segment.get("time_range") or {}).get("start_time") events.append(event) events_df = pd.DataFrame(events) if events_df.empty: diff --git a/tests/test_earthranger_io.py b/tests/test_earthranger_io.py index 9875c191..f45c62de 100644 --- a/tests/test_earthranger_io.py +++ b/tests/test_earthranger_io.py @@ -148,6 +148,7 @@ def test_get_patrol_events(er_io): assert "geometry" in events assert "patrol_id" in events assert "patrol_segment_id" in events + assert "patrol_start_time" in events assert "time" in events @@ -339,3 +340,19 @@ def test_existing_token_expired(er_io): with pytest.raises(ERClientException, match="Authorization token is invalid or expired."): ecoscope.io.EarthRangerIO(service_root=er_io.service_root, token_url=er_io.token_url, token=token) + + +def test_get_patrol_observations_with_patrol_filter(er_io): + observations = er_io.get_patrol_observations_with_patrol_filter( + since=pd.Timestamp("2017-01-01").isoformat(), + until=pd.Timestamp("2017-04-01").isoformat(), + patrol_type_value="ecoscope_patrol", + status=["done"], + include_patrol_details=True, + ) + + assert not observations.empty + assert "patrol_id" in observations.columns + assert "patrol_title" in observations.columns + assert "patrol_start_time" in observations.columns + pd.testing.assert_series_equal(observations["patrol_id"], observations["groupby_col"], check_names=False)