auto-trainer-api 0.10.0__tar.gz → 0.10.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/PKG-INFO +8 -1
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/README.md +7 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_detector_kind.py +1 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_kind.py +16 -9
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_payloads.py +216 -30
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/build_event.py +5 -3
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/tests/test_build_event.py +22 -0
- auto_trainer_api-0.10.2/tests/test_util.py +97 -0
- auto_trainer_api-0.10.0/tests/test_util.py +0 -46
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/.gitignore +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/publish-testpypi.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/pyproject.toml +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_alarm_kind.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_application_mode.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_options.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_configuration.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_status.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_training_mode.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/__main__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_app.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_service.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request_response.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request_result.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/command_request_delegate.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/rpc_service.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/telemetry/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/telemetry/open_telemetry_service.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/util.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/zeromq/__init__.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/zeromq/zeromq_api_service.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/tests/test_api_basics.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/tests/test_api_event.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/tests/test_bridge_service.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/tests/test_resolve_enum.py +0 -0
- {auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: auto-trainer-api
|
|
3
|
-
Version: 0.10.
|
|
3
|
+
Version: 0.10.2
|
|
4
4
|
Summary: API for interfacing with the core acquisition process via platform and language agnostic message queues.
|
|
5
5
|
License: AGPL-3.0-only
|
|
6
6
|
Classifier: Operating System :: OS Independent
|
|
@@ -154,3 +154,10 @@ Optional dependency groups:
|
|
|
154
154
|
pip install auto-trainer-api[bridge] # Socket.IO bridge dependencies
|
|
155
155
|
pip install auto-trainer-api[telemetry] # OpenTelemetry support
|
|
156
156
|
```
|
|
157
|
+
|
|
158
|
+
To install a development build from TestPyPI (see _Publishing_ above), point pip at the TestPyPI index, keep
|
|
159
|
+
PyPI as an extra index so the runtime dependencies still resolve, and pass `--pre` so the `.devN`
|
|
160
|
+
pre-release versions are eligible:
|
|
161
|
+
```
|
|
162
|
+
pip install --pre --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ auto-trainer-api
|
|
163
|
+
```
|
|
@@ -129,3 +129,10 @@ Optional dependency groups:
|
|
|
129
129
|
pip install auto-trainer-api[bridge] # Socket.IO bridge dependencies
|
|
130
130
|
pip install auto-trainer-api[telemetry] # OpenTelemetry support
|
|
131
131
|
```
|
|
132
|
+
|
|
133
|
+
To install a development build from TestPyPI (see _Publishing_ above), point pip at the TestPyPI index, keep
|
|
134
|
+
PyPI as an extra index so the runtime dependencies still resolve, and pass `--pre` so the `.devN`
|
|
135
|
+
pre-release versions are eligible:
|
|
136
|
+
```
|
|
137
|
+
pip install --pre --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ auto-trainer-api
|
|
138
|
+
```
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_kind.py
RENAMED
|
@@ -263,22 +263,22 @@ class ApiEventKind(IntEnum):
|
|
|
263
263
|
## Pose identification during trials.
|
|
264
264
|
trialAnimalSeen = 1501
|
|
265
265
|
"""
|
|
266
|
-
Payload:
|
|
267
|
-
First time the animal is seen by inference after a trial starts.
|
|
268
|
-
|
|
266
|
+
Payload: TrialSeenContext
|
|
267
|
+
First time the animal is seen by inference after a trial starts. (batch_id on this event is DEPRECATED
|
|
268
|
+
and ignored — these fire during capture, before any batch exists; see TrialSeenContext.)
|
|
269
269
|
"""
|
|
270
270
|
trialRightHandSeen = 1502
|
|
271
271
|
"""
|
|
272
|
-
Payload:
|
|
273
|
-
First time the right_hand is seen by inference after a trial starts.
|
|
274
|
-
|
|
272
|
+
Payload: TrialSeenContext
|
|
273
|
+
First time the right_hand is seen by inference after a trial starts. (batch_id on this event is
|
|
274
|
+
DEPRECATED and ignored — see TrialSeenContext.)
|
|
275
275
|
"""
|
|
276
276
|
|
|
277
277
|
trialPelletSeen = 1503
|
|
278
278
|
"""
|
|
279
|
-
Payload:
|
|
280
|
-
First time the pellet is seen by inference after a trial starts.
|
|
281
|
-
|
|
279
|
+
Payload: TrialSeenContext
|
|
280
|
+
First time the pellet is seen by inference after a trial starts. (batch_id on this event is DEPRECATED
|
|
281
|
+
and ignored — see TrialSeenContext.)
|
|
282
282
|
"""
|
|
283
283
|
|
|
284
284
|
## Auto-clamp and baseline behavior.
|
|
@@ -394,6 +394,13 @@ class ApiEventKind(IntEnum):
|
|
|
394
394
|
sent separately.
|
|
395
395
|
"""
|
|
396
396
|
|
|
397
|
+
intertrialResponse = 1720
|
|
398
|
+
"""
|
|
399
|
+
Payload: IntertrialResponseContext
|
|
400
|
+
Carries a nullable batch_id (the producing batch's id in deferred/batch mode; None inline or when
|
|
401
|
+
analysis is disabled).
|
|
402
|
+
"""
|
|
403
|
+
|
|
397
404
|
## Pellet/reach counts.
|
|
398
405
|
pelletPresentedCountChanged = 1800
|
|
399
406
|
"""Payload: CountChangeContext"""
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_payloads.py
RENAMED
|
@@ -22,7 +22,10 @@ directly by ``build_event``.
|
|
|
22
22
|
Identifier fields documented as already stringified (``session_id``, ``batch_id``) are typed ``str``,
|
|
23
23
|
not ``UUID``.
|
|
24
24
|
"""
|
|
25
|
+
from enum import Enum
|
|
25
26
|
from typing import Any, List, Optional, Protocol, Sequence, TypedDict, Union
|
|
27
|
+
|
|
28
|
+
from typing_extensions import NotRequired
|
|
26
29
|
from uuid import UUID
|
|
27
30
|
|
|
28
31
|
from ..api_alarm_kind import ApiAlarmKind
|
|
@@ -31,16 +34,19 @@ from ..api_training_mode import ApiTrainingMode
|
|
|
31
34
|
from .api_event_kind import ApiPelletShiftSource
|
|
32
35
|
|
|
33
36
|
__all__ = [
|
|
34
|
-
"Vector3Context", "SessionTrialContext", "AnalysisTrialContext", "
|
|
35
|
-
"IsEnabledContext",
|
|
37
|
+
"Vector3Context", "SessionTrialContext", "AnalysisTrialContext", "TrialSeenContext", "ReasonContext",
|
|
38
|
+
"CommandContext", "IsEnabledContext",
|
|
36
39
|
"IsEngagedContext", "IntensityContext", "CountChangeContext", "TrainingPhaseContext",
|
|
37
40
|
"EmergencyStopContext", "VersionContext", "ApplicationModeContext", "PropertyChangedContext",
|
|
38
41
|
"ProjectChangedContext", "ProjectTrialChangedContext", "PelletHomeResetContext",
|
|
39
42
|
"PelletDriftResetContext", "SessionStartedContext", "SessionEndedContext", "TrialStartedContext",
|
|
40
|
-
"TrialEndedContext", "
|
|
43
|
+
"TrialEndedContext", "CaptureAnalysisResultLike", "BatchAnalysisStartedContext", "BatchAnalysisEndedContext",
|
|
44
|
+
"BaselineContext",
|
|
41
45
|
"FrequencyContext", "DelayContext", "ReleaseToneContext", "IntertrialSaveContext",
|
|
42
|
-
"IntertrialErrorContext", "DayStartedContext", "
|
|
46
|
+
"IntertrialErrorContext", "DayStartedContext", "ReachEventMethodLike", "ReachEventOutcomeLike",
|
|
47
|
+
"ReachEventLike", "ReachEventDict",
|
|
43
48
|
"TrialReachEventsContext",
|
|
49
|
+
"IntertrialResponseDataLike", "IntertrialResponseDict", "IntertrialResponseContext",
|
|
44
50
|
"PelletShiftContext", "TrainingModeContext", "TrainingPlanContext",
|
|
45
51
|
]
|
|
46
52
|
|
|
@@ -83,6 +89,28 @@ class AnalysisTrialContext(SessionTrialContext):
|
|
|
83
89
|
batch_id: Optional[str]
|
|
84
90
|
|
|
85
91
|
|
|
92
|
+
class TrialSeenContext(SessionTrialContext):
|
|
93
|
+
"""Identifies the trial for a first-sighting event — ``trialAnimalSeen`` / ``trialRightHandSeen`` /
|
|
94
|
+
``trialPelletSeen``. Extends :class:`SessionTrialContext` (``session_id`` + ``trial_id``).
|
|
95
|
+
|
|
96
|
+
**DEPRECATED FIELD — ``batch_id``.** ``batch_id`` on these events is deprecated, ignored, and must not
|
|
97
|
+
be read. First-sightings are emitted during capture, *before any batch exists*, so a ``batch_id`` here
|
|
98
|
+
is meaningless — treat the event as carrying none, whatever value is present. The key is retained (and,
|
|
99
|
+
like the rest of the payload, still required in the type) only so existing producers that populate it
|
|
100
|
+
keep working unchanged; it will be removed later. Producers may put any value (``None`` is fine); new
|
|
101
|
+
code should set ``None`` and consumers must ignore it. Structurally this is the same shape as
|
|
102
|
+
:class:`AnalysisTrialContext`, so a value of either type is interchangeable at the call site — the
|
|
103
|
+
difference is only this contract: here ``batch_id`` is meaningless. (The reliable, non-deprecated
|
|
104
|
+
``batch_id`` lives on the ``intertrial*`` and ``batchAnalysis*`` events, emitted inside the batch.)
|
|
105
|
+
|
|
106
|
+
Fields:
|
|
107
|
+
session_id: The session the trial belongs to.
|
|
108
|
+
trial_id: The trial identifier within the session.
|
|
109
|
+
batch_id: Deprecated and ignored — see above. Do not read it; set ``None``.
|
|
110
|
+
"""
|
|
111
|
+
batch_id: Optional[str] # DEPRECATED / ignored — retained only for backward compatibility; will be removed.
|
|
112
|
+
|
|
113
|
+
|
|
86
114
|
class ReasonContext(TypedDict):
|
|
87
115
|
"""A single free-text reason.
|
|
88
116
|
|
|
@@ -262,15 +290,32 @@ class TrialStartedContext(TypedDict):
|
|
|
262
290
|
reason: str
|
|
263
291
|
|
|
264
292
|
|
|
293
|
+
class CaptureAnalysisResultLike(str, Enum):
|
|
294
|
+
"""The capture/analysis result of a trial — a temporary local duplicate of
|
|
295
|
+
``autotrainer.core.interfaces.CaptureAnalysisResult``.
|
|
296
|
+
|
|
297
|
+
Mirrors that class's members and string values so ``result`` can be type-checked here instead of typed
|
|
298
|
+
as a bare ``str``. Same rationale and caveats as :class:`ReachEventMethodLike`: a ``str``-valued
|
|
299
|
+
:class:`~enum.Enum` (the wire form is JSON, so it serializes to its value and stays interchangeable
|
|
300
|
+
with the raw string), kept in sync with the core class by hand and expected to be removed once the
|
|
301
|
+
packages share a type.
|
|
302
|
+
"""
|
|
303
|
+
CAPTURE_ONLY = "capture_only"
|
|
304
|
+
ANALYSIS_SUCCEEDED = "analysis_succeeded"
|
|
305
|
+
ANALYSIS_FAILED = "analysis_failed"
|
|
306
|
+
ANALYSIS_DELAYED = "analysis_delayed"
|
|
307
|
+
|
|
308
|
+
|
|
265
309
|
class TrialEndedContext(TypedDict):
|
|
266
310
|
"""Fields:
|
|
267
311
|
session_id: The session the trial belongs to.
|
|
268
312
|
trial_id: The trial identifier.
|
|
269
|
-
result: The trial/analysis result.
|
|
313
|
+
result: The trial/analysis result (:class:`CaptureAnalysisResultLike`, e.g. ``CAPTURE_ONLY``,
|
|
314
|
+
``ANALYSIS_SUCCEEDED``, ``ANALYSIS_FAILED``, ``ANALYSIS_DELAYED``).
|
|
270
315
|
"""
|
|
271
316
|
session_id: str
|
|
272
317
|
trial_id: int
|
|
273
|
-
result:
|
|
318
|
+
result: CaptureAnalysisResultLike
|
|
274
319
|
|
|
275
320
|
|
|
276
321
|
class BatchAnalysisStartedContext(TypedDict):
|
|
@@ -372,42 +417,91 @@ class IntertrialErrorContext(TypedDict):
|
|
|
372
417
|
class DayStartedContext(TypedDict):
|
|
373
418
|
"""Fields:
|
|
374
419
|
date: Number of seconds since the epoch (e.g. ``datetime.now(timezone.utc).timestamp()``).
|
|
420
|
+
day_path: Absolute path to the new day's directory that just started — the expected ``day_path`` for
|
|
421
|
+
that day, analogous to :attr:`ApiProjectStatus.day_path`. Optional: omitted when not known (and
|
|
422
|
+
absent from older production events that predate this field).
|
|
375
423
|
"""
|
|
376
424
|
date: float
|
|
425
|
+
day_path: NotRequired[str]
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
class ReachEventMethodLike(str, Enum):
|
|
429
|
+
"""The reach method — a temporary local duplicate of ``autotrainer.core.reach_event.ReachEventMethod``.
|
|
430
|
+
|
|
431
|
+
Mirrors that class's string values so ``method`` fields can be type-checked here instead of typed as a
|
|
432
|
+
bare ``str``. It is intentionally a ``str``-valued :class:`~enum.Enum` (unlike the plain-class original,
|
|
433
|
+
which avoids being an enum so its members survive pickling into saved h5 files); on the wire these
|
|
434
|
+
events are JSON, so a ``str`` enum serializes to its value and stays interchangeable with the raw
|
|
435
|
+
string. This duplication is deliberate and expected to be removed once the two packages share a type;
|
|
436
|
+
until then it must be kept in sync with the core class by hand.
|
|
437
|
+
"""
|
|
438
|
+
NONE = "none"
|
|
439
|
+
OTHER = "other"
|
|
440
|
+
RIGHT_HAND = "right_hand"
|
|
441
|
+
LEFT_HAND = "left_hand"
|
|
442
|
+
TONGUE = "tongue"
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
class ReachEventOutcomeLike(str, Enum):
|
|
446
|
+
"""The reach outcome — a temporary local duplicate of ``autotrainer.core.reach_event.ReachEventOutcome``.
|
|
447
|
+
|
|
448
|
+
Same rationale and caveats as :class:`ReachEventMethodLike`: a ``str``-valued enum kept in sync by hand,
|
|
449
|
+
to be removed once the packages share a type.
|
|
450
|
+
"""
|
|
451
|
+
NONE = "none"
|
|
452
|
+
STALLED = "stalled"
|
|
453
|
+
MISSED = "missed"
|
|
454
|
+
DROPPED = "dropped"
|
|
455
|
+
GRABBED = "grabbed"
|
|
456
|
+
EATEN = "eaten"
|
|
377
457
|
|
|
378
458
|
|
|
379
459
|
class ReachEventLike(Protocol):
|
|
380
460
|
"""Structural type for a single reach event, matched by ``autotrainer.core.ReachEvent``.
|
|
381
461
|
|
|
382
|
-
Anything exposing these read-only
|
|
462
|
+
Anything exposing these read-only properties satisfies it, so callers may put
|
|
383
463
|
``autotrainer.core.ReachEvent`` instances straight into ``trial_reach_events`` with no conversion to
|
|
384
464
|
:class:`ReachEventDict` — and this needs no import of ``autotrainer.core`` (kept out to preserve the
|
|
385
465
|
library's Python 3.8 / dependency-free footprint). On send,
|
|
386
466
|
:func:`autotrainer.api.util.prepare_for_serialization` turns each dataclass instance into its wire
|
|
387
|
-
dict, so nothing else is required.
|
|
388
|
-
|
|
389
|
-
Attributes:
|
|
390
|
-
init: Reach initiation frame index (may be negative).
|
|
391
|
-
end: Reach end frame index, or ``None`` if unknown.
|
|
392
|
-
max: Frame index of maximum extension, or ``None`` if unknown.
|
|
393
|
-
method: Reach method (e.g. ``"right_hand"``, ``"left_hand"``, ``"tongue"``, ``"none"``,
|
|
394
|
-
``"other"``).
|
|
395
|
-
outcome: Reach outcome (e.g. ``"eaten"``, ``"grabbed"``, ``"dropped"``, ``"missed"``,
|
|
396
|
-
``"stalled"``, ``"none"``).
|
|
397
|
-
delay_since_presented: Seconds between pellet presentation and the reach.
|
|
467
|
+
dict, so nothing else is required. Each property is documented on itself below.
|
|
398
468
|
"""
|
|
469
|
+
|
|
399
470
|
@property
|
|
400
|
-
def init(self) -> int:
|
|
471
|
+
def init(self) -> int:
|
|
472
|
+
"""Reach initiation frame index (may be negative)."""
|
|
473
|
+
...
|
|
474
|
+
|
|
401
475
|
@property
|
|
402
|
-
def end(self) -> Optional[int]:
|
|
476
|
+
def end(self) -> Optional[int]:
|
|
477
|
+
"""Reach end frame index, or ``None`` if unknown."""
|
|
478
|
+
...
|
|
479
|
+
|
|
403
480
|
@property
|
|
404
|
-
def max(self) -> Optional[int]:
|
|
481
|
+
def max(self) -> Optional[int]:
|
|
482
|
+
"""Frame index of maximum extension, or ``None`` if unknown."""
|
|
483
|
+
...
|
|
484
|
+
|
|
405
485
|
@property
|
|
406
|
-
def method(self) -> str:
|
|
486
|
+
def method(self) -> str:
|
|
487
|
+
"""Reach method. Typed ``str`` (not :class:`ReachEventMethodLike`) on purpose: this Protocol exists to
|
|
488
|
+
be satisfied structurally by ``autotrainer.core.ReachEvent``, whose ``method`` is a plain ``str``.
|
|
489
|
+
Narrowing to the enum would make ``core.ReachEvent`` fail the match (``str`` is not assignable to
|
|
490
|
+
the narrower enum). Values are still the :class:`ReachEventMethodLike` strings (``"right_hand"``,
|
|
491
|
+
``"left_hand"``, ``"tongue"``, ``"none"``, ``"other"``); a ``ReachEventMethodLike`` member also
|
|
492
|
+
satisfies this since it subclasses ``str``."""
|
|
493
|
+
...
|
|
494
|
+
|
|
407
495
|
@property
|
|
408
|
-
def outcome(self) -> str:
|
|
496
|
+
def outcome(self) -> str:
|
|
497
|
+
"""Reach outcome. Same rationale as ``method``; the values are the :class:`ReachEventOutcomeLike`
|
|
498
|
+
strings (``"eaten"``, ``"grabbed"``, ``"dropped"``, ``"missed"``, ``"stalled"``, ``"none"``)."""
|
|
499
|
+
...
|
|
500
|
+
|
|
409
501
|
@property
|
|
410
|
-
def delay_since_presented(self) -> float:
|
|
502
|
+
def delay_since_presented(self) -> float:
|
|
503
|
+
"""Seconds between pellet presentation and the reach."""
|
|
504
|
+
...
|
|
411
505
|
|
|
412
506
|
|
|
413
507
|
class ReachEventDict(TypedDict):
|
|
@@ -419,17 +513,17 @@ class ReachEventDict(TypedDict):
|
|
|
419
513
|
init: Reach initiation frame index (may be negative).
|
|
420
514
|
end: Reach end frame index, or ``None`` if unknown.
|
|
421
515
|
max: Frame index of maximum extension, or ``None`` if unknown.
|
|
422
|
-
method: Reach method (e.g. ``
|
|
423
|
-
``
|
|
424
|
-
outcome: Reach outcome (e.g. ``
|
|
425
|
-
``
|
|
516
|
+
method: Reach method (:class:`ReachEventMethodLike`, e.g. ``RIGHT_HAND``, ``LEFT_HAND``, ``TONGUE``,
|
|
517
|
+
``NONE``, ``OTHER``).
|
|
518
|
+
outcome: Reach outcome (:class:`ReachEventOutcomeLike`, e.g. ``EATEN``, ``GRABBED``, ``DROPPED``,
|
|
519
|
+
``MISSED``, ``STALLED``, ``NONE``).
|
|
426
520
|
delay_since_presented: Seconds between pellet presentation and the reach.
|
|
427
521
|
"""
|
|
428
522
|
init: int
|
|
429
523
|
end: Optional[int]
|
|
430
524
|
max: Optional[int]
|
|
431
|
-
method:
|
|
432
|
-
outcome:
|
|
525
|
+
method: ReachEventMethodLike
|
|
526
|
+
outcome: ReachEventOutcomeLike
|
|
433
527
|
delay_since_presented: float
|
|
434
528
|
|
|
435
529
|
|
|
@@ -451,6 +545,98 @@ class TrialReachEventsContext(TypedDict):
|
|
|
451
545
|
trial_reach_events: Sequence[Union[ReachEventLike, ReachEventDict]]
|
|
452
546
|
|
|
453
547
|
|
|
548
|
+
class IntertrialResponseDataLike(Protocol):
|
|
549
|
+
"""Structural type for a single intertrial response, matched by
|
|
550
|
+
``autotrainer.inference.analysis.IntertrialResponse``.
|
|
551
|
+
|
|
552
|
+
Anything exposing these read-only properties satisfies it, so callers may put ``IntertrialResponse``
|
|
553
|
+
instances straight into ``response_data`` with no conversion to :class:`IntertrialResponseDict` — and
|
|
554
|
+
this needs no import of ``autotrainer.inference`` (kept out to preserve the library's Python 3.8 /
|
|
555
|
+
dependency-free footprint). On send, :func:`autotrainer.api.util.prepare_for_serialization` turns each
|
|
556
|
+
dataclass instance — and its nested reach events and offset tuples — into its wire form, so nothing else
|
|
557
|
+
is required. Each property is documented on itself below.
|
|
558
|
+
"""
|
|
559
|
+
|
|
560
|
+
@property
|
|
561
|
+
def rh_max_vp_list(self) -> Sequence[Optional[Sequence[float]]]:
|
|
562
|
+
"""Right-hand max-reach vantage points, each an ``(x, y, z)`` relative offset, or ``None`` when the
|
|
563
|
+
offset could not be determined. Typed ``Sequence[float]`` (not a concrete vector) so
|
|
564
|
+
``autotrainer.core.Offset3DTuple`` — a ``(x, y, z)`` namedtuple — satisfies it structurally."""
|
|
565
|
+
...
|
|
566
|
+
|
|
567
|
+
@property
|
|
568
|
+
def reach_events(self) -> Sequence[ReachEventLike]:
|
|
569
|
+
"""Hand reaches (right and left). Typed :class:`ReachEventLike` so a
|
|
570
|
+
``List[autotrainer.core.ReachEvent]`` satisfies it structurally; see that type for the ``method`` /
|
|
571
|
+
``outcome`` string values."""
|
|
572
|
+
...
|
|
573
|
+
|
|
574
|
+
@property
|
|
575
|
+
def other_events(self) -> Sequence[ReachEventLike]:
|
|
576
|
+
"""Non-hand-based events; same element type as :attr:`reach_events`."""
|
|
577
|
+
...
|
|
578
|
+
|
|
579
|
+
@property
|
|
580
|
+
def food_consumed(self) -> int:
|
|
581
|
+
"""Total pellets consumed during the trial/session."""
|
|
582
|
+
...
|
|
583
|
+
|
|
584
|
+
@property
|
|
585
|
+
def successful_reaches(self) -> int:
|
|
586
|
+
"""Number of successful (right-hand) reaches."""
|
|
587
|
+
...
|
|
588
|
+
|
|
589
|
+
@property
|
|
590
|
+
def total_reaches(self) -> int:
|
|
591
|
+
"""Total reaches across both hands."""
|
|
592
|
+
...
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
class IntertrialResponseDict(TypedDict):
|
|
596
|
+
"""Dict form of a single intertrial response, mirroring ``autotrainer.inference.analysis.IntertrialResponse``
|
|
597
|
+
for callers who build the payload by hand. A :class:`IntertrialResponseDataLike` object (e.g. an
|
|
598
|
+
``IntertrialResponse``) may be used instead; both are accepted in ``response_data`` and produce the same
|
|
599
|
+
wire shape.
|
|
600
|
+
|
|
601
|
+
Fields:
|
|
602
|
+
rh_max_vp_list: Right-hand max-reach vantage points, each an ``(x, y, z)`` relative offset or
|
|
603
|
+
``None``. (A core ``Offset3DTuple`` serializes to the same ``[x, y, z]`` array.)
|
|
604
|
+
reach_events: Hand reaches (right and left). Each element may be an ``autotrainer.core.ReachEvent``
|
|
605
|
+
(any :class:`ReachEventLike`) or a :class:`ReachEventDict`.
|
|
606
|
+
other_events: Non-hand-based events; same element type as ``reach_events``.
|
|
607
|
+
food_consumed: Total pellets consumed during the trial/session.
|
|
608
|
+
successful_reaches: Number of successful (right-hand) reaches.
|
|
609
|
+
total_reaches: Total reaches across both hands.
|
|
610
|
+
|
|
611
|
+
Note: the source ``IntertrialResponse`` also carries a deprecated ``pellets_presented`` (superseded by
|
|
612
|
+
the pellet-presented event). It is intentionally omitted here; a real ``IntertrialResponse`` still has
|
|
613
|
+
the field and it rides over the wire, but nothing consumes it.
|
|
614
|
+
"""
|
|
615
|
+
rh_max_vp_list: Sequence[Optional[Sequence[float]]]
|
|
616
|
+
reach_events: Sequence[Union[ReachEventLike, ReachEventDict]]
|
|
617
|
+
other_events: Sequence[Union[ReachEventLike, ReachEventDict]]
|
|
618
|
+
food_consumed: int
|
|
619
|
+
successful_reaches: int
|
|
620
|
+
total_reaches: int
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
class IntertrialResponseContext(TypedDict):
|
|
624
|
+
"""Fields:
|
|
625
|
+
session_id: The session the trial belongs to.
|
|
626
|
+
trial_id: The trial identifier.
|
|
627
|
+
batch_id: The stringified uuid v4 of the batch that produced this event, or ``None`` when there is
|
|
628
|
+
no batch (inline analysis, or analysis disabled).
|
|
629
|
+
response_data: The trial's intertrial responses. Each element may be an
|
|
630
|
+
``autotrainer.inference.analysis.IntertrialResponse`` (any :class:`IntertrialResponseDataLike`)
|
|
631
|
+
or a :class:`IntertrialResponseDict`; a ``List[IntertrialResponse]`` may be passed as-is.
|
|
632
|
+
``Sequence`` (rather than ``List``) keeps it covariant so that is accepted without a type error.
|
|
633
|
+
"""
|
|
634
|
+
session_id: str
|
|
635
|
+
trial_id: int
|
|
636
|
+
batch_id: Optional[str]
|
|
637
|
+
response_data: Sequence[Union[IntertrialResponseDataLike, IntertrialResponseDict]]
|
|
638
|
+
|
|
639
|
+
|
|
454
640
|
class PelletShiftContext(TypedDict):
|
|
455
641
|
"""Fields:
|
|
456
642
|
session_id: The session the trial belongs to.
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/build_event.py
RENAMED
|
@@ -157,11 +157,11 @@ def build_event(kind: Literal[ApiEventKind.headFixationForceDetectorChanged], co
|
|
|
157
157
|
|
|
158
158
|
# --- Pose identification ----------------------------------------------------------------------------
|
|
159
159
|
@overload
|
|
160
|
-
def build_event(kind: Literal[ApiEventKind.trialAnimalSeen], context: p.
|
|
160
|
+
def build_event(kind: Literal[ApiEventKind.trialAnimalSeen], context: p.TrialSeenContext) -> ApiEventDict: ...
|
|
161
161
|
@overload
|
|
162
|
-
def build_event(kind: Literal[ApiEventKind.trialRightHandSeen], context: p.
|
|
162
|
+
def build_event(kind: Literal[ApiEventKind.trialRightHandSeen], context: p.TrialSeenContext) -> ApiEventDict: ...
|
|
163
163
|
@overload
|
|
164
|
-
def build_event(kind: Literal[ApiEventKind.trialPelletSeen], context: p.
|
|
164
|
+
def build_event(kind: Literal[ApiEventKind.trialPelletSeen], context: p.TrialSeenContext) -> ApiEventDict: ...
|
|
165
165
|
|
|
166
166
|
# --- Auto-clamp / baseline --------------------------------------------------------------------------
|
|
167
167
|
@overload
|
|
@@ -232,6 +232,8 @@ def build_event(kind: Literal[ApiEventKind.trialPelletPresented], context: p.Ses
|
|
|
232
232
|
def build_event(kind: Literal[ApiEventKind.trialReachEvents], context: p.TrialReachEventsContext) -> ApiEventDict: ...
|
|
233
233
|
@overload
|
|
234
234
|
def build_event(kind: Literal[ApiEventKind.intertrialPelletShift], context: p.PelletShiftContext) -> ApiEventDict: ...
|
|
235
|
+
@overload
|
|
236
|
+
def build_event(kind: Literal[ApiEventKind.intertrialResponse], context: p.IntertrialResponseContext) -> ApiEventDict: ...
|
|
235
237
|
|
|
236
238
|
# --- Analysis ---------------------------------------------------------------------------------------
|
|
237
239
|
@overload
|
|
@@ -127,3 +127,25 @@ class TestBatchId:
|
|
|
127
127
|
# Same typed path with the nullable batch_id absent-of-batch case (inline / analysis disabled).
|
|
128
128
|
ctx = p.AnalysisTrialContext(session_id="s1", trial_id=2, batch_id=None)
|
|
129
129
|
assert build_event(ApiEventKind.intertrialSegmentationBegin, ctx)["context"] == ctx
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class TestIntertrialResponse:
|
|
133
|
+
"""The intertrialResponse overload / context, mirroring the reach-events Like+Dict pattern."""
|
|
134
|
+
|
|
135
|
+
def _reach(self):
|
|
136
|
+
return p.ReachEventDict(init=0, end=10, max=5, method=p.ReachEventMethodLike.RIGHT_HAND,
|
|
137
|
+
outcome=p.ReachEventOutcomeLike.EATEN, delay_since_presented=0.1)
|
|
138
|
+
|
|
139
|
+
def test_typed_constructor_stores_context(self):
|
|
140
|
+
# Hand-built IntertrialResponseDict with a string-enum ReachEventDict; batch_id present (deferred).
|
|
141
|
+
resp = p.IntertrialResponseDict(
|
|
142
|
+
rh_max_vp_list=[[1.0, 2.0, 3.0], None], reach_events=[self._reach()], other_events=[],
|
|
143
|
+
food_consumed=1, successful_reaches=1, total_reaches=2)
|
|
144
|
+
ctx = p.IntertrialResponseContext(session_id="s1", trial_id=2, batch_id="b1", response_data=[resp])
|
|
145
|
+
event = build_event(ApiEventKind.intertrialResponse, ctx)
|
|
146
|
+
assert event["kind"] is ApiEventKind.intertrialResponse
|
|
147
|
+
assert event["context"] == ctx
|
|
148
|
+
|
|
149
|
+
def test_generic_build_with_plain_dict_and_null_batch(self):
|
|
150
|
+
ctx = {"session_id": "s1", "trial_id": 2, "batch_id": None, "response_data": []}
|
|
151
|
+
assert _generic_build(ApiEventKind.intertrialResponse, ctx)["context"] == ctx
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
import json
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from autotrainer.api.util import prepare_for_serialization
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclasses.dataclass
|
|
9
|
+
class _Reach:
|
|
10
|
+
init: int
|
|
11
|
+
end: Optional[int] = None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestPrepareForSerializationTuples:
|
|
15
|
+
def test_tuple_becomes_list(self):
|
|
16
|
+
assert prepare_for_serialization((1, 2, 3)) == [1, 2, 3]
|
|
17
|
+
|
|
18
|
+
def test_tuple_elements_are_recursed(self):
|
|
19
|
+
# A tuple of dataclasses (e.g. ReachEvent instances) is the motivating case.
|
|
20
|
+
result = prepare_for_serialization((_Reach(10, 200), _Reach(-5, None)))
|
|
21
|
+
assert result == [{"init": 10, "end": 200}, {"init": -5, "end": None}]
|
|
22
|
+
|
|
23
|
+
def test_nested_tuple_in_dict_and_list(self):
|
|
24
|
+
result = prepare_for_serialization({"reaches": (_Reach(1), _Reach(2))})
|
|
25
|
+
assert result == {"reaches": [{"init": 1, "end": None}, {"init": 2, "end": None}]}
|
|
26
|
+
assert prepare_for_serialization([(1, 2), (3, 4)]) == [[1, 2], [3, 4]]
|
|
27
|
+
|
|
28
|
+
def test_result_is_json_serializable(self):
|
|
29
|
+
# The whole point: a tuple of dataclasses must reach the wire without a TypeError.
|
|
30
|
+
payload = prepare_for_serialization({"trial_reach_events": (_Reach(10, 200),)})
|
|
31
|
+
assert json.loads(json.dumps(payload)) == {"trial_reach_events": [{"init": 10, "end": 200}]}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TestIntertrialResponseLikeSerialization:
|
|
35
|
+
"""A duck-typed IntertrialResponse (nested reach dataclasses + Offset3DTuple-like namedtuples) reaches
|
|
36
|
+
the wire correctly: string-enum values serialize to their strings and offsets to ``[x, y, z]`` arrays.
|
|
37
|
+
This is the ``IntertrialResponseDataLike`` pathway — no conversion required by the caller.
|
|
38
|
+
|
|
39
|
+
It also pins the extra-field behavior: the real dataclass carries ``pellets_presented`` (which the
|
|
40
|
+
``IntertrialResponseDataLike`` type deliberately omits), and ``asdict`` still emits it — so it rides over
|
|
41
|
+
the wire even though nothing in the API types declares it."""
|
|
42
|
+
|
|
43
|
+
def test_like_object_serializes_to_wire_form(self):
|
|
44
|
+
import collections
|
|
45
|
+
|
|
46
|
+
from autotrainer.api.event import ReachEventMethodLike, ReachEventOutcomeLike
|
|
47
|
+
|
|
48
|
+
offset3d = collections.namedtuple("Offset3DTuple", "x y z") # stands in for autotrainer.core
|
|
49
|
+
|
|
50
|
+
@dataclasses.dataclass
|
|
51
|
+
class _ReachLike:
|
|
52
|
+
init: int
|
|
53
|
+
end: Optional[int]
|
|
54
|
+
method: ReachEventMethodLike
|
|
55
|
+
outcome: ReachEventOutcomeLike
|
|
56
|
+
|
|
57
|
+
@dataclasses.dataclass
|
|
58
|
+
class _ResponseLike:
|
|
59
|
+
rh_max_vp_list: list
|
|
60
|
+
reach_events: list
|
|
61
|
+
other_events: list
|
|
62
|
+
food_consumed: int
|
|
63
|
+
successful_reaches: int
|
|
64
|
+
pellets_presented: int
|
|
65
|
+
total_reaches: int
|
|
66
|
+
|
|
67
|
+
resp = _ResponseLike(
|
|
68
|
+
rh_max_vp_list=[offset3d(1.0, 2.0, 3.0), None],
|
|
69
|
+
reach_events=[_ReachLike(0, 10, ReachEventMethodLike.RIGHT_HAND, ReachEventOutcomeLike.EATEN)],
|
|
70
|
+
other_events=[], food_consumed=1, successful_reaches=1, pellets_presented=0, total_reaches=2)
|
|
71
|
+
|
|
72
|
+
wire = prepare_for_serialization({"response_data": [resp]})
|
|
73
|
+
assert wire == {"response_data": [{
|
|
74
|
+
"rh_max_vp_list": [[1.0, 2.0, 3.0], None], # namedtuple -> array, None passes through
|
|
75
|
+
"reach_events": [{"init": 0, "end": 10, "method": "right_hand", "outcome": "eaten"}], # enum -> value
|
|
76
|
+
"other_events": [],
|
|
77
|
+
"food_consumed": 1,
|
|
78
|
+
"successful_reaches": 1,
|
|
79
|
+
"pellets_presented": 0,
|
|
80
|
+
"total_reaches": 2,
|
|
81
|
+
}]}
|
|
82
|
+
assert json.loads(json.dumps(wire)) # the whole thing is JSON-serializable
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class TestBatchIdSerialization:
|
|
86
|
+
"""The nullable batch_id (str or None) needs no special handling — str and None pass through."""
|
|
87
|
+
|
|
88
|
+
def test_str_batch_id_passthrough(self):
|
|
89
|
+
ctx = {"session_id": "s1", "trial_id": 1, "batch_id": "b1"}
|
|
90
|
+
assert prepare_for_serialization(ctx) == ctx
|
|
91
|
+
|
|
92
|
+
def test_none_batch_id_stays_none(self):
|
|
93
|
+
ctx = {"session_id": "s1", "trial_id": 1, "batch_id": None}
|
|
94
|
+
result = prepare_for_serialization(ctx)
|
|
95
|
+
assert result == ctx
|
|
96
|
+
# JSON null round-trips.
|
|
97
|
+
assert json.loads(json.dumps(result)) == ctx
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import dataclasses
|
|
2
|
-
import json
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
|
-
from autotrainer.api.util import prepare_for_serialization
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclasses.dataclass
|
|
9
|
-
class _Reach:
|
|
10
|
-
init: int
|
|
11
|
-
end: Optional[int] = None
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TestPrepareForSerializationTuples:
|
|
15
|
-
def test_tuple_becomes_list(self):
|
|
16
|
-
assert prepare_for_serialization((1, 2, 3)) == [1, 2, 3]
|
|
17
|
-
|
|
18
|
-
def test_tuple_elements_are_recursed(self):
|
|
19
|
-
# A tuple of dataclasses (e.g. ReachEvent instances) is the motivating case.
|
|
20
|
-
result = prepare_for_serialization((_Reach(10, 200), _Reach(-5, None)))
|
|
21
|
-
assert result == [{"init": 10, "end": 200}, {"init": -5, "end": None}]
|
|
22
|
-
|
|
23
|
-
def test_nested_tuple_in_dict_and_list(self):
|
|
24
|
-
result = prepare_for_serialization({"reaches": (_Reach(1), _Reach(2))})
|
|
25
|
-
assert result == {"reaches": [{"init": 1, "end": None}, {"init": 2, "end": None}]}
|
|
26
|
-
assert prepare_for_serialization([(1, 2), (3, 4)]) == [[1, 2], [3, 4]]
|
|
27
|
-
|
|
28
|
-
def test_result_is_json_serializable(self):
|
|
29
|
-
# The whole point: a tuple of dataclasses must reach the wire without a TypeError.
|
|
30
|
-
payload = prepare_for_serialization({"trial_reach_events": (_Reach(10, 200),)})
|
|
31
|
-
assert json.loads(json.dumps(payload)) == {"trial_reach_events": [{"init": 10, "end": 200}]}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class TestBatchIdSerialization:
|
|
35
|
-
"""The nullable batch_id (str or None) needs no special handling — str and None pass through."""
|
|
36
|
-
|
|
37
|
-
def test_str_batch_id_passthrough(self):
|
|
38
|
-
ctx = {"session_id": "s1", "trial_id": 1, "batch_id": "b1"}
|
|
39
|
-
assert prepare_for_serialization(ctx) == ctx
|
|
40
|
-
|
|
41
|
-
def test_none_batch_id_stays_none(self):
|
|
42
|
-
ctx = {"session_id": "s1", "trial_id": 1, "batch_id": None}
|
|
43
|
-
result = prepare_for_serialization(ctx)
|
|
44
|
-
assert result == ctx
|
|
45
|
-
# JSON null round-trips.
|
|
46
|
-
assert json.loads(json.dumps(result)) == ctx
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_application_mode.py
RENAMED
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_configuration.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_status.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_training_mode.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_app.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_service.py
RENAMED
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/telemetry/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auto_trainer_api-0.10.0 → auto_trainer_api-0.10.2}/src/autotrainer/api/zeromq/zeromq_api_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|