plexus-python-pulse-demeter 1.2.149__py3-none-any.whl → 1.2.151__py3-none-any.whl
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.
- plexus/pulse/demeter/app.py +2 -0
- plexus/pulse/demeter/cli.py +13 -25
- plexus/pulse/demeter/domains/robotic/api/catalog_endpoints.py +197 -16
- plexus/pulse/demeter/domains/robotic/api/catalog_internal_endpoints.py +110 -0
- plexus/pulse/demeter/domains/robotic/api/pipeline_endpoints.py +292 -7
- plexus/pulse/demeter/domains/robotic/cli/manage.py +37 -0
- plexus/pulse/demeter/domains/robotic/client.py +142 -66
- plexus/pulse/demeter/domains/robotic/models/catalog.py +159 -58
- plexus/pulse/demeter/domains/robotic/models/serial.py +159 -0
- plexus/pulse/demeter/domains/robotic/tables/catalog.py +47 -14
- plexus/pulse/demeter/domains/robotic/tables/pipeline.py +7 -6
- plexus/pulse/demeter/domains/robotic/tui/__init__.py +0 -0
- plexus/pulse/demeter/domains/robotic/tui/manage.py +999 -0
- plexus/pulse/demeter/platform/agent.py +201 -0
- plexus/pulse/demeter/platform/api/registry_endpoints.py +46 -0
- plexus/pulse/demeter/platform/cli.py +130 -0
- plexus/pulse/demeter/platform/client.py +58 -0
- plexus/pulse/demeter/platform/database.py +367 -2
- plexus/pulse/demeter/platform/tables/iam.py +11 -10
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.151.dist-info}/METADATA +6 -1
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.151.dist-info}/RECORD +24 -17
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.151.dist-info}/WHEEL +0 -0
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.151.dist-info}/entry_points.txt +0 -0
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.151.dist-info}/top_level.txt +0 -0
plexus/pulse/demeter/app.py
CHANGED
|
@@ -6,6 +6,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
|
6
6
|
|
|
7
7
|
def make_api() -> FastAPI:
|
|
8
8
|
from plexus.pulse.demeter.platform.api.iam_internal_endpoints import router as iam_internal_router
|
|
9
|
+
from plexus.pulse.demeter.platform.api.registry_endpoints import router as registry_router
|
|
9
10
|
from plexus.pulse.demeter.domains.autodrive.api.inventory_endpoints import router as autodrive_inventory_router
|
|
10
11
|
from plexus.pulse.demeter.domains.autodrive.api.catalog_endpoints import router as autodrive_catalog_router
|
|
11
12
|
from plexus.pulse.demeter.domains.autodrive.api.tagging_endpoints import router as autodrive_tagging_router
|
|
@@ -29,6 +30,7 @@ def make_api() -> FastAPI:
|
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
api.include_router(iam_internal_router)
|
|
33
|
+
api.include_router(registry_router)
|
|
32
34
|
api.include_router(autodrive_inventory_router)
|
|
33
35
|
api.include_router(autodrive_catalog_router)
|
|
34
36
|
api.include_router(autodrive_workflow_router)
|
plexus/pulse/demeter/cli.py
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
|
-
from types import SimpleNamespace
|
|
2
|
-
|
|
3
|
-
import click
|
|
4
|
-
|
|
5
1
|
from plexus.pulse.demeter.domains.autodrive.cli.dataset import DatasetValidateCommandTool
|
|
6
2
|
from plexus.pulse.demeter.domains.autodrive.cli.tag_cache import (
|
|
7
3
|
TagCacheUploadCommandTool,
|
|
8
4
|
TagCacheValidateCommandTool,
|
|
9
5
|
)
|
|
10
6
|
from plexus.pulse.demeter.domains.robotic.cli.flow_ops import FlowOpsCommandTool
|
|
7
|
+
from plexus.pulse.demeter.domains.robotic.cli.manage import ManageCommandTool
|
|
11
8
|
from plexus.pulse.demeter.domains.robotic.cli.pipeline import PipelineUploadCommandTool
|
|
12
|
-
from plexus.pulse.demeter.platform.cli import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@classmethod
|
|
21
|
-
def params(cls) -> list[click.Parameter]:
|
|
22
|
-
return []
|
|
23
|
-
|
|
24
|
-
@classmethod
|
|
25
|
-
def desc(cls) -> str:
|
|
26
|
-
return "Show the installed Demeter package version."
|
|
27
|
-
|
|
28
|
-
def run(self, args: SimpleNamespace) -> int:
|
|
29
|
-
from plexus.pulse.demeter import __version__
|
|
30
|
-
|
|
31
|
-
click.echo(__version__)
|
|
32
|
-
return 0
|
|
9
|
+
from plexus.pulse.demeter.platform.cli import (
|
|
10
|
+
CommandTool,
|
|
11
|
+
RegistryDescribeCommandTool,
|
|
12
|
+
RegistryExplainCommandTool,
|
|
13
|
+
RegistryOpenApiCommandTool,
|
|
14
|
+
VersionCommandTool,
|
|
15
|
+
)
|
|
16
|
+
from plexus.pulse.demeter.platform.cli import run_cli
|
|
33
17
|
|
|
34
18
|
|
|
35
19
|
def main() -> None:
|
|
36
20
|
tools: list[type[CommandTool]] = [
|
|
37
21
|
VersionCommandTool,
|
|
22
|
+
RegistryDescribeCommandTool,
|
|
23
|
+
RegistryOpenApiCommandTool,
|
|
24
|
+
RegistryExplainCommandTool,
|
|
38
25
|
TagCacheUploadCommandTool,
|
|
39
26
|
TagCacheValidateCommandTool,
|
|
40
27
|
DatasetValidateCommandTool,
|
|
41
28
|
FlowOpsCommandTool,
|
|
29
|
+
ManageCommandTool,
|
|
42
30
|
PipelineUploadCommandTool,
|
|
43
31
|
]
|
|
44
32
|
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import datetime
|
|
2
2
|
import json
|
|
3
|
+
import re
|
|
3
4
|
import uuid as py_uuid
|
|
4
5
|
from collections.abc import Callable, Iterable
|
|
5
|
-
from typing import Literal, Self
|
|
6
|
+
from typing import Annotated, Literal, Self
|
|
6
7
|
|
|
7
8
|
import pydantic as pdt
|
|
8
9
|
import sqlalchemy as sa
|
|
9
10
|
import sqlalchemy.dialects.postgresql as sa_pg
|
|
10
11
|
import sqlalchemy.exc as sa_exc
|
|
11
12
|
import sqlalchemy.orm as sa_orm
|
|
12
|
-
|
|
13
|
+
import zxingcpp
|
|
14
|
+
from fastapi import APIRouter, Depends, HTTPException, Query, Response
|
|
13
15
|
from fastapi.responses import StreamingResponse
|
|
14
16
|
from jsonschema import Draft202012Validator
|
|
15
17
|
from jsonschema.exceptions import SchemaError, ValidationError
|
|
16
18
|
from plexus.pulse.common.utils.apiutils import database_transaction, get_clock, get_uuid_generator
|
|
17
19
|
from plexus.pulse.common.utils.ormutils import make_changing_model_mixin, make_revision_model_mixin
|
|
20
|
+
from plexus.pulse.common.utils.strutils import sn_code_pattern
|
|
18
21
|
from sqlmodel import SQLModel
|
|
19
22
|
|
|
20
23
|
from plexus.pulse.demeter.domains.robotic.models.catalog import (
|
|
@@ -26,9 +29,12 @@ from plexus.pulse.demeter.domains.robotic.models.catalog import (
|
|
|
26
29
|
EpisodeFormatSpec,
|
|
27
30
|
Robot,
|
|
28
31
|
RobotSetupSpec,
|
|
32
|
+
SerialSequencer,
|
|
29
33
|
Tag,
|
|
30
34
|
)
|
|
31
35
|
from plexus.pulse.demeter.domains.robotic.models.catalog import DELETED_FLAG
|
|
36
|
+
from plexus.pulse.demeter.domains.robotic.models.serial import SerialGeneratorSpec, SerialLiteralParam
|
|
37
|
+
from plexus.pulse.demeter.domains.robotic.models.serial import render_generated_serial, render_serial_template
|
|
32
38
|
from plexus.pulse.demeter.domains.robotic.tables.catalog import (
|
|
33
39
|
ArtifactFormatSpecTable,
|
|
34
40
|
ArtifactTable,
|
|
@@ -38,8 +44,10 @@ from plexus.pulse.demeter.domains.robotic.tables.catalog import (
|
|
|
38
44
|
DatasetTable,
|
|
39
45
|
EpisodeFormatSpecTable,
|
|
40
46
|
EpisodeTable,
|
|
47
|
+
IssuedSerialTable,
|
|
41
48
|
RobotSetupSpecTable,
|
|
42
49
|
RobotTable,
|
|
50
|
+
SerialSequencerTable,
|
|
43
51
|
TagTable,
|
|
44
52
|
TagsetSpecTable,
|
|
45
53
|
TagsetTable,
|
|
@@ -47,6 +55,7 @@ from plexus.pulse.demeter.domains.robotic.tables.catalog import (
|
|
|
47
55
|
from plexus.pulse.demeter.domains.robotic.tables.pipeline import PipelineTable
|
|
48
56
|
from plexus.pulse.demeter.platform.api import Pagination
|
|
49
57
|
from plexus.pulse.demeter.platform.database import make_session
|
|
58
|
+
from plexus.pulse.demeter.platform.models import BaseModel
|
|
50
59
|
|
|
51
60
|
router = APIRouter(prefix="/pulse_demeter/robotic/catalog", tags=["robotic", "catalog"])
|
|
52
61
|
|
|
@@ -272,6 +281,178 @@ def _validate_components(schema: dict, components: dict):
|
|
|
272
281
|
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
|
273
282
|
|
|
274
283
|
|
|
284
|
+
@router.post("/serial_sequencers/", response_model=SerialSequencerTable, status_code=201)
|
|
285
|
+
def register_serial_sequencer(
|
|
286
|
+
sequencer: SerialSequencer,
|
|
287
|
+
db: sa_orm.Session = Depends(make_session),
|
|
288
|
+
clock: Callable[[sa_orm.Session], datetime.datetime] = Depends(get_clock),
|
|
289
|
+
) -> SerialSequencerTable:
|
|
290
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
291
|
+
current_dt = clock(db)
|
|
292
|
+
db_sequencer = SerialSequencerTable(**sequencer.model_dump(), created_at=current_dt, updated_at=current_dt)
|
|
293
|
+
db.add(db_sequencer)
|
|
294
|
+
db.flush()
|
|
295
|
+
return db_sequencer
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class SerialNumberApplication(BaseModel):
|
|
299
|
+
sequencer: Annotated[str, pdt.StringConstraints(min_length=1, max_length=64)]
|
|
300
|
+
request_key: Annotated[str, pdt.StringConstraints(min_length=1, max_length=128)]
|
|
301
|
+
params: dict[str, str] = pdt.Field(default_factory=dict)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _apply_serial_number(
|
|
305
|
+
application: SerialNumberApplication,
|
|
306
|
+
response: Response,
|
|
307
|
+
db: sa_orm.Session,
|
|
308
|
+
clock: Callable[[sa_orm.Session], datetime.datetime],
|
|
309
|
+
) -> IssuedSerialTable:
|
|
310
|
+
db_sequencer = db.scalar(sa
|
|
311
|
+
.select(SerialSequencerTable)
|
|
312
|
+
.where(SerialSequencerTable.name == application.sequencer)
|
|
313
|
+
.with_for_update(key_share=True))
|
|
314
|
+
if db_sequencer is None:
|
|
315
|
+
raise HTTPException(status_code=404, detail="Serial sequencer not found")
|
|
316
|
+
|
|
317
|
+
params = application.params
|
|
318
|
+
|
|
319
|
+
db_serial = db.scalar(sa
|
|
320
|
+
.select(IssuedSerialTable)
|
|
321
|
+
.where(IssuedSerialTable.sequencer == db_sequencer.name,
|
|
322
|
+
IssuedSerialTable.request_key == application.request_key))
|
|
323
|
+
if db_serial is not None:
|
|
324
|
+
if db_serial.params != params:
|
|
325
|
+
raise HTTPException(status_code=409, detail="Request key already has a different serial application")
|
|
326
|
+
response.status_code = 200
|
|
327
|
+
return db_serial
|
|
328
|
+
|
|
329
|
+
try:
|
|
330
|
+
spec = SerialGeneratorSpec.model_validate(db_sequencer.generator_spec)
|
|
331
|
+
literal_params = {param.key: param for param in spec.params if isinstance(param, SerialLiteralParam)}
|
|
332
|
+
if params.keys() != literal_params.keys() or any(
|
|
333
|
+
param.regex is not None and re.fullmatch(param.regex, params[key]) is None
|
|
334
|
+
for key, param in literal_params.items()
|
|
335
|
+
):
|
|
336
|
+
raise HTTPException(status_code=422, detail="Invalid literal serial parameters")
|
|
337
|
+
|
|
338
|
+
scope_key = render_serial_template(db_sequencer.scope_key_template, params)
|
|
339
|
+
|
|
340
|
+
except (ValueError, re.error) as exc:
|
|
341
|
+
raise HTTPException(status_code=500, detail="Invalid serial generator specification") from exc
|
|
342
|
+
|
|
343
|
+
if len(scope_key) > 64:
|
|
344
|
+
raise HTTPException(status_code=422, detail="Rendered serial scope exceeds 64 characters")
|
|
345
|
+
|
|
346
|
+
last_sequence = db.scalar(sa
|
|
347
|
+
.select(sa.func.max(IssuedSerialTable.sequence_value))
|
|
348
|
+
.where(IssuedSerialTable.sequencer == db_sequencer.name,
|
|
349
|
+
IssuedSerialTable.scope_key == scope_key))
|
|
350
|
+
sequence = (last_sequence or 0) + 1
|
|
351
|
+
if sequence > 2 ** 63 - 1:
|
|
352
|
+
raise HTTPException(status_code=409, detail="Serial sequence range exhausted")
|
|
353
|
+
|
|
354
|
+
try:
|
|
355
|
+
serial_number = render_generated_serial(db_sequencer.template, spec, params, sequence)
|
|
356
|
+
except (ArithmeticError, SyntaxError, ValueError) as exc:
|
|
357
|
+
raise HTTPException(status_code=500, detail="Invalid serial generator specification") from exc
|
|
358
|
+
|
|
359
|
+
if not 1 <= len(serial_number) <= 64:
|
|
360
|
+
raise HTTPException(status_code=422, detail="Generated serial number must contain 1 to 64 characters")
|
|
361
|
+
|
|
362
|
+
current_dt = clock(db)
|
|
363
|
+
|
|
364
|
+
db_serial = IssuedSerialTable(
|
|
365
|
+
sequencer=db_sequencer.name,
|
|
366
|
+
scope_key=scope_key,
|
|
367
|
+
sequence_value=sequence,
|
|
368
|
+
serial_number=serial_number,
|
|
369
|
+
request_key=application.request_key,
|
|
370
|
+
params=params,
|
|
371
|
+
created_at=current_dt,
|
|
372
|
+
updated_at=current_dt,
|
|
373
|
+
)
|
|
374
|
+
db.add(db_serial)
|
|
375
|
+
|
|
376
|
+
return db_serial
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
@router.post("/serial_numbers/",
|
|
380
|
+
response_model=IssuedSerialTable,
|
|
381
|
+
status_code=201,
|
|
382
|
+
responses={200: {"model": IssuedSerialTable, "description": "Existing issuance for the same application"}})
|
|
383
|
+
def apply_serial_number(
|
|
384
|
+
application: SerialNumberApplication,
|
|
385
|
+
response: Response,
|
|
386
|
+
db: sa_orm.Session = Depends(make_session),
|
|
387
|
+
clock: Callable[[sa_orm.Session], datetime.datetime] = Depends(get_clock),
|
|
388
|
+
) -> IssuedSerialTable:
|
|
389
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
390
|
+
return _apply_serial_number(application, response, db, clock)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
class RobotSerialNumberApplication(BaseModel):
|
|
394
|
+
sequencer: Annotated[str, pdt.StringConstraints(min_length=1, max_length=64)] = "robot_body@1.0"
|
|
395
|
+
manufacturing_unit_id: Annotated[str, pdt.StringConstraints(min_length=1, max_length=128)]
|
|
396
|
+
params: dict[str, str] = pdt.Field(default_factory=dict)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
@router.post("/robots/serial_numbers/",
|
|
400
|
+
response_model=IssuedSerialTable,
|
|
401
|
+
status_code=201,
|
|
402
|
+
responses={200: {"model": IssuedSerialTable, "description": "Existing issuance for the same application"}})
|
|
403
|
+
def apply_robot_serial_number(
|
|
404
|
+
application: RobotSerialNumberApplication,
|
|
405
|
+
response: Response,
|
|
406
|
+
db: sa_orm.Session = Depends(make_session),
|
|
407
|
+
clock: Callable[[sa_orm.Session], datetime.datetime] = Depends(get_clock),
|
|
408
|
+
) -> IssuedSerialTable:
|
|
409
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
410
|
+
db_serial = _apply_serial_number(SerialNumberApplication(sequencer=application.sequencer,
|
|
411
|
+
request_key=application.manufacturing_unit_id,
|
|
412
|
+
params=application.params),
|
|
413
|
+
response,
|
|
414
|
+
db,
|
|
415
|
+
clock)
|
|
416
|
+
if sn_code_pattern.fullmatch(db_serial.serial_number) is None:
|
|
417
|
+
raise HTTPException(status_code=422, detail="Invalid robot serial number")
|
|
418
|
+
if response.status_code != 200:
|
|
419
|
+
db_robot = db.scalar(sa
|
|
420
|
+
.select(RobotTable.sqn)
|
|
421
|
+
.where(RobotTable.serial_number == db_serial.serial_number)
|
|
422
|
+
.limit(1))
|
|
423
|
+
if db_robot is not None:
|
|
424
|
+
raise HTTPException(status_code=409, detail="Serial number is already in the robot catalog")
|
|
425
|
+
return db_serial
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
@router.get("/robots/{robot_uuid}/qr_code",
|
|
429
|
+
response_class=Response,
|
|
430
|
+
responses={200: {"content": {"image/svg+xml": {}}}})
|
|
431
|
+
def generate_robot_qr_code(robot_uuid: py_uuid.UUID, db: sa_orm.Session = Depends(make_session)) -> Response:
|
|
432
|
+
db_robot = read_robot(robot_uuid, db)
|
|
433
|
+
fields = {
|
|
434
|
+
"uuid": str(db_robot.uuid),
|
|
435
|
+
"alias": db_robot.alias,
|
|
436
|
+
"serial_number": db_robot.serial_number,
|
|
437
|
+
"setup_spec": db_robot.setup_spec,
|
|
438
|
+
"setup_spec_title": db_robot.setup_spec_title,
|
|
439
|
+
"components": db_robot.components,
|
|
440
|
+
"extra_props": db_robot.extra_props,
|
|
441
|
+
}
|
|
442
|
+
payload = json.dumps(fields, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
|
|
443
|
+
|
|
444
|
+
try:
|
|
445
|
+
barcode = zxingcpp.create_barcode(payload, zxingcpp.BarcodeFormat.QRCode)
|
|
446
|
+
except (ValueError, RuntimeError) as exc:
|
|
447
|
+
raise HTTPException(status_code=422, detail="Robot record could not be encoded as a QR code") from exc
|
|
448
|
+
|
|
449
|
+
return Response(
|
|
450
|
+
content=barcode.to_svg(add_quiet_zones=True),
|
|
451
|
+
media_type="image/svg+xml",
|
|
452
|
+
headers={"Content-Disposition": f'inline; filename="{db_robot.uuid}.svg"'},
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
|
|
275
456
|
@router.post("/robots/", response_model=RobotWithTitles, status_code=201)
|
|
276
457
|
def register_robot(
|
|
277
458
|
robot: Robot,
|
|
@@ -301,7 +482,7 @@ def register_robot(
|
|
|
301
482
|
return RobotWithTitles.with_titles(db, [db_robot])[0]
|
|
302
483
|
|
|
303
484
|
|
|
304
|
-
class RobotTablesAndPagination(
|
|
485
|
+
class RobotTablesAndPagination(BaseModel):
|
|
305
486
|
robots: list[RobotWithTitles]
|
|
306
487
|
pagination: Pagination
|
|
307
488
|
|
|
@@ -598,14 +779,14 @@ def delete_episode(
|
|
|
598
779
|
return EpisodeWithTitles.with_titles(db, [db_episode])[0]
|
|
599
780
|
|
|
600
781
|
|
|
601
|
-
class TagFilter(
|
|
782
|
+
class TagFilter(BaseModel):
|
|
602
783
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
603
784
|
|
|
604
785
|
tagset_spec: str = pdt.Field(max_length=64)
|
|
605
786
|
tag: str = pdt.Field(max_length=128)
|
|
606
787
|
|
|
607
788
|
|
|
608
|
-
class ArtifactFilter(
|
|
789
|
+
class ArtifactFilter(BaseModel):
|
|
609
790
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
610
791
|
|
|
611
792
|
family: str | None = pdt.Field(None, max_length=32)
|
|
@@ -615,11 +796,11 @@ class ArtifactFilter(pdt.BaseModel):
|
|
|
615
796
|
@pdt.model_validator(mode="after")
|
|
616
797
|
def validate_selector(self):
|
|
617
798
|
if (self.family is None) == (self.format_spec is None):
|
|
618
|
-
raise ValueError("
|
|
799
|
+
raise ValueError("specify exactly one of family or format_spec")
|
|
619
800
|
return self
|
|
620
801
|
|
|
621
802
|
|
|
622
|
-
class EpisodeFilterSet(
|
|
803
|
+
class EpisodeFilterSet(BaseModel):
|
|
623
804
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
624
805
|
|
|
625
806
|
pipeline_name: str = pdt.Field(max_length=128)
|
|
@@ -700,7 +881,7 @@ def make_episode_filter_predicate_stmt(filter_set: EpisodeFilterSet):
|
|
|
700
881
|
return sa.and_(*sub_predicate_stmts)
|
|
701
882
|
|
|
702
883
|
|
|
703
|
-
class EpisodeSelection(
|
|
884
|
+
class EpisodeSelection(BaseModel):
|
|
704
885
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
705
886
|
|
|
706
887
|
select_filter_set: EpisodeFilterSet | None = None
|
|
@@ -709,13 +890,13 @@ class EpisodeSelection(pdt.BaseModel):
|
|
|
709
890
|
description="Episode bag UUIDs; exclusion overrides inclusion")
|
|
710
891
|
|
|
711
892
|
|
|
712
|
-
class TagSelector(
|
|
893
|
+
class TagSelector(BaseModel):
|
|
713
894
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
714
895
|
|
|
715
896
|
tagset_spec: str | None = pdt.Field(None, max_length=64)
|
|
716
897
|
|
|
717
898
|
|
|
718
|
-
class ArtifactSelector(
|
|
899
|
+
class ArtifactSelector(BaseModel):
|
|
719
900
|
model_config = pdt.ConfigDict(extra="forbid")
|
|
720
901
|
|
|
721
902
|
family: str | None = pdt.Field(None, max_length=32)
|
|
@@ -725,7 +906,7 @@ class ArtifactSelector(pdt.BaseModel):
|
|
|
725
906
|
@pdt.model_validator(mode="after")
|
|
726
907
|
def validate_selector(self):
|
|
727
908
|
if (self.family is None) == (self.format_spec is None):
|
|
728
|
-
raise ValueError("
|
|
909
|
+
raise ValueError("specify exactly one of family or format_spec")
|
|
729
910
|
return self
|
|
730
911
|
|
|
731
912
|
|
|
@@ -737,7 +918,7 @@ class QueryEpisodeRequest(EpisodeSelection):
|
|
|
737
918
|
limit: int = pdt.Field(100, ge=1, le=1000)
|
|
738
919
|
|
|
739
920
|
|
|
740
|
-
class EnrichedEpisode(
|
|
921
|
+
class EnrichedEpisode(BaseModel):
|
|
741
922
|
episode: EpisodeWithTitles
|
|
742
923
|
bag: BagWithTitles
|
|
743
924
|
tags: list[TagWithTitles] = pdt.Field(default_factory=list)
|
|
@@ -745,7 +926,7 @@ class EnrichedEpisode(pdt.BaseModel):
|
|
|
745
926
|
selected: bool = False
|
|
746
927
|
|
|
747
928
|
|
|
748
|
-
class EnrichedEpisodesAndPagination(
|
|
929
|
+
class EnrichedEpisodesAndPagination(BaseModel):
|
|
749
930
|
episodes: list[EnrichedEpisode]
|
|
750
931
|
pagination: Pagination
|
|
751
932
|
|
|
@@ -867,7 +1048,7 @@ class StatEpisodeRequest(EpisodeSelection):
|
|
|
867
1048
|
pass
|
|
868
1049
|
|
|
869
1050
|
|
|
870
|
-
class EpisodeStatistics(
|
|
1051
|
+
class EpisodeStatistics(BaseModel):
|
|
871
1052
|
total_count: int
|
|
872
1053
|
total_duration_ns: int
|
|
873
1054
|
|
|
@@ -948,12 +1129,12 @@ def create_dataset_from_selection(
|
|
|
948
1129
|
return db_dataset
|
|
949
1130
|
|
|
950
1131
|
|
|
951
|
-
class DatasetWithEpisodeCount(
|
|
1132
|
+
class DatasetWithEpisodeCount(BaseModel):
|
|
952
1133
|
dataset: DatasetTable
|
|
953
1134
|
episodes_count: int
|
|
954
1135
|
|
|
955
1136
|
|
|
956
|
-
class DatasetsAndPagination(
|
|
1137
|
+
class DatasetsAndPagination(BaseModel):
|
|
957
1138
|
datasets: list[DatasetWithEpisodeCount]
|
|
958
1139
|
pagination: Pagination
|
|
959
1140
|
|
|
@@ -31,8 +31,10 @@ from plexus.pulse.demeter.domains.robotic.models.catalog import (
|
|
|
31
31
|
DatasetItem,
|
|
32
32
|
Episode,
|
|
33
33
|
EpisodeFormatSpec,
|
|
34
|
+
IssuedSerial,
|
|
34
35
|
Robot,
|
|
35
36
|
RobotSetupSpec,
|
|
37
|
+
SerialSequencer,
|
|
36
38
|
Tag,
|
|
37
39
|
Tagset,
|
|
38
40
|
TagsetSpec,
|
|
@@ -46,8 +48,10 @@ from plexus.pulse.demeter.domains.robotic.tables.catalog import (
|
|
|
46
48
|
DatasetTable,
|
|
47
49
|
EpisodeFormatSpecTable,
|
|
48
50
|
EpisodeTable,
|
|
51
|
+
IssuedSerialTable,
|
|
49
52
|
RobotSetupSpecTable,
|
|
50
53
|
RobotTable,
|
|
54
|
+
SerialSequencerTable,
|
|
51
55
|
TagTable,
|
|
52
56
|
TagsetSpecTable,
|
|
53
57
|
TagsetTable,
|
|
@@ -70,6 +74,112 @@ exception_redirect = {
|
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
|
|
77
|
+
@router.post("/serial_sequencer/", response_model=SerialSequencerTable)
|
|
78
|
+
def create_serial_sequencer(
|
|
79
|
+
serial_sequencer: SerialSequencer,
|
|
80
|
+
created_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
81
|
+
db: sa_orm.Session = Depends(make_session),
|
|
82
|
+
) -> SerialSequencerTable:
|
|
83
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
84
|
+
return db_create_changing_model(db, SerialSequencerTable, serial_sequencer, created_at)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@router.post("/serial_sequencers/", response_model=list[SerialSequencerTable])
|
|
88
|
+
def create_serial_sequencers(
|
|
89
|
+
serial_sequencers: list[SerialSequencer],
|
|
90
|
+
created_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
91
|
+
db: sa_orm.Session = Depends(make_session),
|
|
92
|
+
) -> list[SerialSequencerTable]:
|
|
93
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
94
|
+
return db_create_changing_models(db, SerialSequencerTable, serial_sequencers, created_at)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@router.get("/serial_sequencer/{sqn}", response_model=SerialSequencerTable)
|
|
98
|
+
def read_serial_sequencer(sqn: int, db: sa_orm.Session = Depends(make_session)) -> SerialSequencerTable:
|
|
99
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
100
|
+
return db_read_sequence_model(db, SerialSequencerTable, sqn)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@router.get("/serial_sequencers/", response_model=list[SerialSequencerTable])
|
|
104
|
+
def read_serial_sequencers(
|
|
105
|
+
skip: int = Query(0, ge=0),
|
|
106
|
+
limit: int = Query(1000, ge=1, le=1000),
|
|
107
|
+
db: sa_orm.Session = Depends(make_session),
|
|
108
|
+
) -> list[SerialSequencerTable]:
|
|
109
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
110
|
+
return db_read_sequence_models(db, SerialSequencerTable, skip, limit)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@router.put("/serial_sequencer/{sqn}", response_model=SerialSequencerTable)
|
|
114
|
+
def update_serial_sequencer(
|
|
115
|
+
sqn: int,
|
|
116
|
+
serial_sequencer: SerialSequencer,
|
|
117
|
+
updated_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
118
|
+
db: sa_orm.Session = Depends(make_session),
|
|
119
|
+
) -> SerialSequencerTable:
|
|
120
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
121
|
+
return db_update_changing_model(db, SerialSequencerTable, serial_sequencer, sqn, updated_at)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@router.delete("/serial_sequencer/{sqn}", response_model=SerialSequencerTable)
|
|
125
|
+
def delete_serial_sequencer(sqn: int, db: sa_orm.Session = Depends(make_session)) -> SerialSequencerTable:
|
|
126
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
127
|
+
return db_delete_sequence_model(db, SerialSequencerTable, sqn)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@router.post("/issued_serial/", response_model=IssuedSerialTable)
|
|
131
|
+
def create_issued_serial(
|
|
132
|
+
issued_serial: IssuedSerial,
|
|
133
|
+
created_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
134
|
+
db: sa_orm.Session = Depends(make_session),
|
|
135
|
+
) -> IssuedSerialTable:
|
|
136
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
137
|
+
return db_create_changing_model(db, IssuedSerialTable, issued_serial, created_at)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@router.post("/issued_serials/", response_model=list[IssuedSerialTable])
|
|
141
|
+
def create_issued_serials(
|
|
142
|
+
issued_serials: list[IssuedSerial],
|
|
143
|
+
created_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
144
|
+
db: sa_orm.Session = Depends(make_session),
|
|
145
|
+
) -> list[IssuedSerialTable]:
|
|
146
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
147
|
+
return db_create_changing_models(db, IssuedSerialTable, issued_serials, created_at)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@router.get("/issued_serial/{sqn}", response_model=IssuedSerialTable)
|
|
151
|
+
def read_issued_serial(sqn: int, db: sa_orm.Session = Depends(make_session)) -> IssuedSerialTable:
|
|
152
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
153
|
+
return db_read_sequence_model(db, IssuedSerialTable, sqn)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@router.get("/issued_serials/", response_model=list[IssuedSerialTable])
|
|
157
|
+
def read_issued_serials(
|
|
158
|
+
skip: int = Query(0, ge=0),
|
|
159
|
+
limit: int = Query(1000, ge=1, le=1000),
|
|
160
|
+
db: sa_orm.Session = Depends(make_session),
|
|
161
|
+
) -> list[IssuedSerialTable]:
|
|
162
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
163
|
+
return db_read_sequence_models(db, IssuedSerialTable, skip, limit)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@router.put("/issued_serial/{sqn}", response_model=IssuedSerialTable)
|
|
167
|
+
def update_issued_serial(
|
|
168
|
+
sqn: int,
|
|
169
|
+
issued_serial: IssuedSerial,
|
|
170
|
+
updated_at: datetime.datetime = Query(default_factory=dt_utc_now),
|
|
171
|
+
db: sa_orm.Session = Depends(make_session),
|
|
172
|
+
) -> IssuedSerialTable:
|
|
173
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
174
|
+
return db_update_changing_model(db, IssuedSerialTable, issued_serial, sqn, updated_at)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@router.delete("/issued_serial/{sqn}", response_model=IssuedSerialTable)
|
|
178
|
+
def delete_issued_serial(sqn: int, db: sa_orm.Session = Depends(make_session)) -> IssuedSerialTable:
|
|
179
|
+
with database_transaction(db, redirect=exception_redirect):
|
|
180
|
+
return db_delete_sequence_model(db, IssuedSerialTable, sqn)
|
|
181
|
+
|
|
182
|
+
|
|
73
183
|
@router.post("/robot_setup_spec/", response_model=RobotSetupSpecTable)
|
|
74
184
|
def create_robot_setup_spec(
|
|
75
185
|
robot_setup_spec: RobotSetupSpec,
|