-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add waterlog result and water restriction models * remove temp file * improve behavior session docs * formatting * further doc improvements
- Loading branch information
Showing
4 changed files
with
242 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
"""Contains a model for a waterlog result stored in SLIMS.""" | ||
|
||
from datetime import datetime | ||
from typing import Annotated, ClassVar, Optional | ||
|
||
from pydantic import Field | ||
|
||
from aind_slims_api import __version__ | ||
from aind_slims_api.models.base import SlimsBaseModel | ||
from aind_slims_api.models.utils import UnitSpec | ||
|
||
|
||
class SlimsWaterlogResult(SlimsBaseModel): | ||
"""Model for a SLIMS Waterlog Result, the daily water/weight records | ||
Examples | ||
-------- | ||
>>> from aind_slims_api.core import SlimsClient | ||
>>> from aind_slims_api import models | ||
>>> client = SlimsClient() | ||
>>> mouse = client.fetch_model(models.SlimsMouseContent, barcode="00000000") | ||
>>> test_pk = client.fetch_pk("Test", test_name="test_waterlog") | ||
Write waterlog result. | ||
>>> waterlog_result = client.add_model( | ||
... models.SlimsWaterlogResult( | ||
... mouse_pk=mouse.pk, | ||
... date=datetime(2021,1,1), | ||
... weight_g=20.0, | ||
... water_earned_ml=5.0, | ||
... water_supplement_delivered_ml=5.0, | ||
... water_supplement_recommended_ml=5.0, | ||
... total_water_ml=10.0, | ||
... comments="comments", | ||
... workstation="aibs-computer-id", | ||
... test_pk=test_pk, | ||
... ) | ||
... ) | ||
Read a waterlog result. | ||
>>> waterlog_results = client.fetch_models( | ||
... models.SlimsWaterlogResult, | ||
... mouse_pk=mouse.pk, | ||
... sort=["date"], | ||
... ) | ||
>>> waterlog_results[-1].weight_g | ||
20.0 | ||
""" | ||
|
||
date: datetime = Field( | ||
datetime.now(), | ||
serialization_alias="rslt_cf_datePerformed", | ||
validation_alias="rslt_cf_datePerformed", | ||
) | ||
operator: Optional[str] = Field( | ||
None, | ||
serialization_alias="rslt_cf_waterlogOperator", | ||
validation_alias="rslt_cf_waterlogOperator", | ||
) | ||
weight_g: Annotated[float | None, UnitSpec("g")] = Field( | ||
None, | ||
serialization_alias="rslt_cf_weight", | ||
validation_alias="rslt_cf_weight", | ||
) | ||
water_earned_ml: Annotated[float | None, UnitSpec("ml")] = Field( | ||
..., | ||
serialization_alias="rslt_cf_waterEarned", | ||
validation_alias="rslt_cf_waterEarned", | ||
) | ||
water_supplement_delivered_ml: Annotated[float | None, UnitSpec("ml")] = Field( | ||
..., | ||
serialization_alias="rslt_cf_waterSupplementDelivered", | ||
validation_alias="rslt_cf_waterSupplementDelivered", | ||
) | ||
water_supplement_recommended_ml: Annotated[float | None, UnitSpec("ml")] = Field( | ||
..., | ||
serialization_alias="rslt_cf_waterSupplementRecommended", | ||
validation_alias="rslt_cf_waterSupplementRecommended", | ||
) | ||
total_water_ml: Annotated[float | None, UnitSpec("ml")] = Field( | ||
..., | ||
serialization_alias="rslt_cf_totalWater", | ||
validation_alias="rslt_cf_totalWater", | ||
) | ||
comments: Optional[str] = Field( | ||
None, | ||
serialization_alias="rslt_comments", | ||
validation_alias="rslt_comments", | ||
) | ||
workstation: Optional[str] = Field( | ||
None, | ||
serialization_alias="rslt_cf_fk_workStation", | ||
validation_alias="rslt_cf_fk_workStation", | ||
) | ||
sw_source: str = Field( | ||
"aind-slims-api", | ||
serialization_alias="rslt_cf_swSource", | ||
validation_alias="rslt_cf_swSource", | ||
) | ||
sw_version: str = Field( | ||
__version__, | ||
serialization_alias="rslt_cf_swVersion", | ||
validation_alias="rslt_cf_swVersion", | ||
) | ||
pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="rslt_pk", | ||
validation_alias="rslt_pk", | ||
) | ||
mouse_pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="rslt_fk_content", | ||
validation_alias="rslt_fk_content", | ||
) | ||
test_pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="rslt_fk_test", | ||
validation_alias="rslt_fk_test", | ||
) | ||
|
||
_slims_table = "Result" | ||
|
||
_base_fetch_filters: ClassVar[dict[str, str]] = { | ||
"test_name": "test_waterlog", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""Contains a model for a waterlog water restriction event stored in SLIMS.""" | ||
|
||
from datetime import datetime | ||
from typing import ClassVar, Optional | ||
|
||
from pydantic import Field | ||
|
||
from aind_slims_api.models.base import SlimsBaseModel | ||
|
||
DEFAULT_WEIGHT_FRACTION = 0.85 | ||
MIN_WEIGHT_FRACTION = 0.75 | ||
MAX_WEIGHT_FRACTION = 1.0 | ||
|
||
|
||
class SlimsWaterRestrictionEvent(SlimsBaseModel): | ||
"""Model for a Water Restriction Event | ||
Examples | ||
-------- | ||
>>> from aind_slims_api.core import SlimsClient | ||
>>> from aind_slims_api import models | ||
>>> client = SlimsClient() | ||
>>> mouse = client.fetch_model(models.SlimsMouseContent, barcode="00000000") | ||
### Write | ||
>>> water_restriction_event = client.add_model( | ||
... models.SlimsWaterRestrictionEvent( | ||
... mouse_pk=mouse.pk, | ||
... start_date=datetime(2021,1,1), | ||
... end_date=datetime(2021,1,2), | ||
... assigned_by="mochic", | ||
... target_weight_fraction=0.90, | ||
... ) | ||
... ) | ||
### Read | ||
>>> water_restriction_events = client.fetch_models( | ||
... models.SlimsWaterRestrictionEvent, | ||
... mouse_pk=mouse.pk, | ||
... sort=["start_date"], | ||
... ) | ||
>>> water_restriction_events[-1].target_weight_fraction | ||
0.9 | ||
""" | ||
|
||
start_date: datetime = Field( | ||
datetime.now(), | ||
serialization_alias="cnvn_cf_startDate", | ||
validation_alias="cnvn_cf_startDate", | ||
) | ||
end_date: Optional[datetime] = Field( | ||
None, | ||
serialization_alias="cnvn_cf_endDate", | ||
validation_alias="cnvn_cf_endDate", | ||
) | ||
assigned_by: str = Field( | ||
..., | ||
serialization_alias="cnvn_cf_assignedBy", | ||
validation_alias="cnvn_cf_assignedBy", | ||
) | ||
target_weight_fraction: float = Field( | ||
default=DEFAULT_WEIGHT_FRACTION, | ||
serialization_alias="cnvn_cf_targetWeightFraction", | ||
validation_alias="cnvn_cf_targetWeightFraction", | ||
gt=MIN_WEIGHT_FRACTION, | ||
lt=MAX_WEIGHT_FRACTION, | ||
) | ||
pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="cnvn_pk", | ||
validation_alias="cnvn_pk", | ||
) | ||
mouse_pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="cnvn_fk_content", | ||
validation_alias="cnvn_fk_content", | ||
) | ||
cnvn_fk_contentEventType: int = 9 # pk of Water Restriction ContentEvent type | ||
|
||
_slims_table = "ContentEvent" | ||
_base_fetch_filters: ClassVar[dict[str, str]] = { | ||
"cnvt_name": "Water Restriction", | ||
} |