Skip to content

Commit

Permalink
update(subject): update logic to keep up with the latest changes in P…
Browse files Browse the repository at this point in the history
…yrat API

In the latest pyrat API - by default, only subjects with `state='live'` is returned
  • Loading branch information
ttngu207 committed Nov 6, 2024
1 parent 61ec7ae commit f564c3b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions aeon/dj_pipeline/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def make(self, key):
"o": 0,
"l": 10,
"eartag": eartag_or_id,
"state": ["live", "sacrificed", "exported"],
}
animal_resp = get_pyrat_data(endpoint="animals", params=params)
if len(animal_resp) == 0:
Expand Down Expand Up @@ -105,6 +106,7 @@ def make(self, key):
"strain_id": animal_resp["strain_id"],
"cage_number": animal_resp["cagenumber"],
"lab_id": animal_resp["labid"],
"available": animal_resp.get("state", "") == "live",
}
if animal_resp["gen_bg_id"] is not None:
GeneticBackground.insert1(
Expand Down Expand Up @@ -250,7 +252,10 @@ def make(self, key):
new_eartags = []
for responsible_id in lab.User.fetch("responsible_id"):
# 1 - retrieve all animals from this user
animal_resp = get_pyrat_data(endpoint="animals", params={"responsible_id": responsible_id})
animal_resp = get_pyrat_data(
endpoint="animals",
params={"responsible_id": responsible_id, "state": ["live", "sacrificed", "exported"]}
)
for animal_entry in animal_resp:
# 2 - find animal with comment - Project Aeon
eartag_or_id = animal_entry["eartag_or_id"]
Expand Down Expand Up @@ -318,7 +323,7 @@ def make(self, key):
if e.args[0].endswith("response code: 404"):
SubjectDetail.update1(
{
**key,
"subject": key["subject"],
"available": False,
}
)
Expand Down Expand Up @@ -347,6 +352,21 @@ def make(self, key):
# compute/update reference weight
SubjectReferenceWeight.get_reference_weight(eartag_or_id)
finally:
# recheck for "state" to see if the animal is still available
animal_resp = get_pyrat_data(
endpoint="animals",
params={"k": ["labid", "state"],
"eartag": eartag_or_id,
"state": ["live", "sacrificed", "exported"]})
animal_resp = animal_resp[0]
SubjectDetail.update1(
{
"subject": key["subject"],
"available": animal_resp.get("state", "") == "live",
"lab_id": animal_resp["labid"],
}
)

completion_time = datetime.utcnow()
self.insert1(
{
Expand Down

0 comments on commit f564c3b

Please sign in to comment.