Skip to content

Commit

Permalink
fix precom and test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgitonga committed Sep 15, 2023
1 parent cf057cf commit fa1d0b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
66 changes: 31 additions & 35 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,7 @@ def get_patrol_segments(self):
self.get_objects_multithreaded(object=object, threads=self.tcp_limit, page_size=self.sub_page_size)
)

def get_patrol_observations(
self,
patrols_df,
patrol_type=None,
include_patrol_details=False,
**kwargs):
def get_patrol_observations(self, patrols_df, patrol_type=None, include_patrol_details=False, **kwargs):
"""
Download observations for provided `patrols_df`.
Parameters
Expand All @@ -673,7 +668,7 @@ def get_patrol_observations(
patrol_type : UUID
Comma-separated list of type of patrol UUID
include_patrol_details : bool, optional
Whether to merge patrol details into dataframe
Whether to merge patrol details into dataframe
kwargs
Additional parameters to pass to `get_subject_observations`.
Returns
Expand All @@ -685,7 +680,7 @@ def get_patrol_observations(
kwargs,
patrol_type=patrol_type,
include_patrol_details=include_patrol_details,
)
)

observations = []
for _, patrol in patrols_df.iterrows():
Expand All @@ -697,41 +692,42 @@ def get_patrol_observations(
if None in {subject_id, patrol_start_time}:
continue
try:
observation = self.get_subject_observations(
subject_ids=[subject_id],
since=patrol_start_time,
until=patrol_end_time,
**kwargs
observation = self.get_subject_observations(
subject_ids=[subject_id], since=patrol_start_time, until=patrol_end_time, **params
)
if include_patrol_details:
observation["patrol_id"] = patrol["id"]
observation["patrol_serial_number"] = patrol["serial_number"]
observation["patrol_start_time"] = patrol_start_time
observation["patrol_end_time"] = patrol_end_time
observation["patrol_type"] = patrol_type
observation = (
observation.reset_index()
.merge(
pd.DataFrame(self.get_patrol_types()).add_prefix("patrol_type__"),
left_on="patrol_type",
right_on="id",
)
.drop(
columns=[
"patrol_type__ordernum",
"patrol_type__icon_id",
"patrol_type__default_priority",
"patrol_type__is_active",
]
)
)
if include_patrol_details:
observation["patrol_id"] = patrol["id"]
observation["patrol_serial_number"] = patrol["serial_number"]
observation["patrol_start_time"] = patrol_start_time
observation["patrol_end_time"] = patrol_end_time
observation["patrol_type"] = patrol_type
observation = observation.reset_index().merge(
pd.DataFrame(self.get_patrol_types()).add_prefix("patrol_type__"),
left_on="patrol_type",
right_on="id"
).drop(
columns=[
"patrol_type__ordernum",
"patrol_type__icon_id",
"patrol_type__default_priority",
"patrol_type__is_active"
]
)
observations.append(observation)
observations.append(observation)
except Exception as e:
print(
f"Getting observations for subject_id={subject_id} start_time={patrol_start_time} end_time={patrol_end_time}"
f"failed for: {e}"
f"Getting observations for subject_id={subject_id} start_time={patrol_start_time}"
f"end_time={patrol_end_time} failed for: {e}"
)
df = ecoscope.base.Relocations(pd.concat(observations))
if include_patrol_details:
return df.set_index("id")
return df

def get_patrol_segment_events(
self,
patrol_segment_id=None,
Expand Down
9 changes: 2 additions & 7 deletions tests/test_earthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,9 @@ def test_patch_event(er_io):
pd.testing.assert_frame_equal(result, updated_event)


def test_get_observation_for_patrol(er_io):
def test_get_patrol_observations(er_io):
patrols = er_io.get_patrols()
observations = er_io.get_observations_for_patrols(
patrols,
include_source_details=False,
include_subject_details=False,
include_subjectsource_details=False,
)
observations = er_io.get_patrol_observations(patrols, include_patrol_details=False)
assert not observations.empty


Expand Down

0 comments on commit fa1d0b0

Please sign in to comment.