Skip to content

Commit

Permalink
Add patrol start time to get_patrol_events (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling authored Dec 4, 2024
1 parent fa2c6d2 commit 515d935
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_earthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

0 comments on commit 515d935

Please sign in to comment.