utils.aind_smartsheet¶
SmartsheetRow ¶
Bases: BaseModel
A parsed row of the scheduling smartsheet.
Fields are populated from the sheet's column names (or by field name). Blank or null
string values become None, and every column not modeled here is kept in model_extra.
SmartsheetScheduleClient ¶
SmartsheetScheduleClient(
base_url: str = DEFAULT_SMARTSHEET_ENDPOINT,
timeout: float | tuple[float, float] | None = (1, 4),
validator: Callable[
[str], str | None
] = validate_username,
)
Client for the AIND behavior scheduling smartsheet, looked up by animal.
Rows are parsed into rows and are cached per subject, so a session only costs one request. get_row degrades to a logged warning
and None when the service is unreachable, but add_scientific_contact and
get_project_name require their values and raise ValueError without them.
Example
ss = SmartsheetScheduleClient()
session = ss.add_scientific_contact(session)
watchdog_settings.project_name = ss.get_project_name(session)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Root URL of the smartsheet service. |
DEFAULT_SMARTSHEET_ENDPOINT
|
timeout
|
float | tuple[float, float] | None
|
Timeout in seconds for each HTTP request, or a (connect, read) pair. |
(1, 4)
|
validator
|
Callable[[str], str | None]
|
Validates the scientific contact's username, returning the canonical name or None to reject it. Defaults to the Active Directory lookup. |
validate_username
|
Source code in src/clabe/utils/aind_smartsheet.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
get_row ¶
get_row(subject: str) -> SmartsheetRow | None
Fetches the parsed sheet row for an animal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
str
|
The animal (mouse) id. |
required |
Returns:
| Type | Description |
|---|---|
SmartsheetRow | None
|
The row, or None if the animal is not found or the service is unreachable. |
SmartsheetRow | None
|
Only found rows and definitive not-found results are cached; failures are retried on the next call. |
Source code in src/clabe/utils/aind_smartsheet.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
add_scientific_contact ¶
add_scientific_contact(session: Session) -> Session
Returns a copy of the session with the animal's validated scientific contact added
to the end of experimenter, with duplicate names removed (first occurrence kept).
The given session is never modified.
The scientific contact is required: this raises instead of degrading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to build on. |
required |
Returns:
| Type | Description |
|---|---|
Session
|
The updated copy of the session, so callers must use the return value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the animal's row cannot be retrieved, the row has no scientific contact, or the username fails validation. |
Source code in src/clabe/utils/aind_smartsheet.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
get_project_name ¶
get_project_name(session: Session) -> str
Returns the project name recorded for the session's animal.
The project name is required: this raises instead of degrading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session whose animal to look up. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The project name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the animal's row cannot be retrieved or has no project name. |
Source code in src/clabe/utils/aind_smartsheet.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |