auto-trainer-api 0.10.1__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.1 → auto_trainer_api-0.10.2}/PKG-INFO +1 -1
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_detector_kind.py +1 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_kind.py +7 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_payloads.py +105 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/build_event.py +2 -0
- {auto_trainer_api-0.10.1 → 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.1/tests/test_util.py +0 -46
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/.gitignore +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/README.md +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/publish-testpypi.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/pyproject.toml +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_alarm_kind.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_application_mode.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_options.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_configuration.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_status.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_training_mode.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/__main__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_app.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_service.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request_response.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/api_command_request_result.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/command/command_request_delegate.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/rpc_service.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/telemetry/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/telemetry/open_telemetry_service.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/util.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/zeromq/__init__.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/zeromq/zeromq_api_service.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/tests/test_api_basics.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/tests/test_api_event.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/tests/test_bridge_service.py +0 -0
- {auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/tests/test_resolve_enum.py +0 -0
- {auto_trainer_api-0.10.1 → 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
|
{auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_kind.py
RENAMED
|
@@ -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.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/api_event_payloads.py
RENAMED
|
@@ -24,6 +24,8 @@ not ``UUID``.
|
|
|
24
24
|
"""
|
|
25
25
|
from enum import Enum
|
|
26
26
|
from typing import Any, List, Optional, Protocol, Sequence, TypedDict, Union
|
|
27
|
+
|
|
28
|
+
from typing_extensions import NotRequired
|
|
27
29
|
from uuid import UUID
|
|
28
30
|
|
|
29
31
|
from ..api_alarm_kind import ApiAlarmKind
|
|
@@ -44,6 +46,7 @@ __all__ = [
|
|
|
44
46
|
"IntertrialErrorContext", "DayStartedContext", "ReachEventMethodLike", "ReachEventOutcomeLike",
|
|
45
47
|
"ReachEventLike", "ReachEventDict",
|
|
46
48
|
"TrialReachEventsContext",
|
|
49
|
+
"IntertrialResponseDataLike", "IntertrialResponseDict", "IntertrialResponseContext",
|
|
47
50
|
"PelletShiftContext", "TrainingModeContext", "TrainingPlanContext",
|
|
48
51
|
]
|
|
49
52
|
|
|
@@ -414,8 +417,12 @@ class IntertrialErrorContext(TypedDict):
|
|
|
414
417
|
class DayStartedContext(TypedDict):
|
|
415
418
|
"""Fields:
|
|
416
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).
|
|
417
423
|
"""
|
|
418
424
|
date: float
|
|
425
|
+
day_path: NotRequired[str]
|
|
419
426
|
|
|
420
427
|
|
|
421
428
|
class ReachEventMethodLike(str, Enum):
|
|
@@ -459,18 +466,22 @@ class ReachEventLike(Protocol):
|
|
|
459
466
|
:func:`autotrainer.api.util.prepare_for_serialization` turns each dataclass instance into its wire
|
|
460
467
|
dict, so nothing else is required. Each property is documented on itself below.
|
|
461
468
|
"""
|
|
469
|
+
|
|
462
470
|
@property
|
|
463
471
|
def init(self) -> int:
|
|
464
472
|
"""Reach initiation frame index (may be negative)."""
|
|
465
473
|
...
|
|
474
|
+
|
|
466
475
|
@property
|
|
467
476
|
def end(self) -> Optional[int]:
|
|
468
477
|
"""Reach end frame index, or ``None`` if unknown."""
|
|
469
478
|
...
|
|
479
|
+
|
|
470
480
|
@property
|
|
471
481
|
def max(self) -> Optional[int]:
|
|
472
482
|
"""Frame index of maximum extension, or ``None`` if unknown."""
|
|
473
483
|
...
|
|
484
|
+
|
|
474
485
|
@property
|
|
475
486
|
def method(self) -> str:
|
|
476
487
|
"""Reach method. Typed ``str`` (not :class:`ReachEventMethodLike`) on purpose: this Protocol exists to
|
|
@@ -480,11 +491,13 @@ class ReachEventLike(Protocol):
|
|
|
480
491
|
``"left_hand"``, ``"tongue"``, ``"none"``, ``"other"``); a ``ReachEventMethodLike`` member also
|
|
481
492
|
satisfies this since it subclasses ``str``."""
|
|
482
493
|
...
|
|
494
|
+
|
|
483
495
|
@property
|
|
484
496
|
def outcome(self) -> str:
|
|
485
497
|
"""Reach outcome. Same rationale as ``method``; the values are the :class:`ReachEventOutcomeLike`
|
|
486
498
|
strings (``"eaten"``, ``"grabbed"``, ``"dropped"``, ``"missed"``, ``"stalled"``, ``"none"``)."""
|
|
487
499
|
...
|
|
500
|
+
|
|
488
501
|
@property
|
|
489
502
|
def delay_since_presented(self) -> float:
|
|
490
503
|
"""Seconds between pellet presentation and the reach."""
|
|
@@ -532,6 +545,98 @@ class TrialReachEventsContext(TypedDict):
|
|
|
532
545
|
trial_reach_events: Sequence[Union[ReachEventLike, ReachEventDict]]
|
|
533
546
|
|
|
534
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
|
+
|
|
535
640
|
class PelletShiftContext(TypedDict):
|
|
536
641
|
"""Fields:
|
|
537
642
|
session_id: The session the trial belongs to.
|
{auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/event/build_event.py
RENAMED
|
@@ -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
|
|
File without changes
|
{auto_trainer_api-0.10.1 → 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.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_configuration.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/api_system_status.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.1 → 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.1 → auto_trainer_api-0.10.2}/src/autotrainer/api/bridge/bridge_app.py
RENAMED
|
File without changes
|
{auto_trainer_api-0.10.1 → 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.1 → 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.1 → 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.1 → 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
|