plexus-python-pulse-demeter 1.2.149__py3-none-any.whl → 1.2.150__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/domains/robotic/api/catalog_endpoints.py +183 -2
- plexus/pulse/demeter/domains/robotic/api/catalog_internal_endpoints.py +110 -0
- 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 +32 -0
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.150.dist-info}/METADATA +4 -1
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.150.dist-info}/RECORD +10 -9
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.150.dist-info}/WHEEL +0 -0
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.150.dist-info}/entry_points.txt +0 -0
- {plexus_python_pulse_demeter-1.2.149.dist-info → plexus_python_pulse_demeter-1.2.150.dist-info}/top_level.txt +0 -0
|
@@ -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,
|
|
@@ -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,
|
|
@@ -12,11 +12,14 @@ from plexus.common.utils.jsonutils import JsonObject
|
|
|
12
12
|
from plexus.pulse.common.utils.datautils import validate_colon_tag, validate_snake_case, validate_versioned_name
|
|
13
13
|
from sqlmodel import Field
|
|
14
14
|
|
|
15
|
+
from plexus.pulse.demeter.domains.robotic.models.serial import SerialGeneratorSpec
|
|
15
16
|
from plexus.pulse.demeter.platform.models import BaseModel
|
|
16
17
|
|
|
17
18
|
__all__ = [
|
|
18
19
|
"DELETED_FLAG",
|
|
19
20
|
"Acceptance",
|
|
21
|
+
"SerialSequencer",
|
|
22
|
+
"IssuedSerial",
|
|
20
23
|
"RobotSetupSpec",
|
|
21
24
|
"Robot",
|
|
22
25
|
"BagFormatSpec",
|
|
@@ -37,6 +40,104 @@ DELETED_FLAG = 1
|
|
|
37
40
|
Acceptance = Literal["ACCEPTED", "REJECTED", "UNDETERMINED"]
|
|
38
41
|
|
|
39
42
|
|
|
43
|
+
class SerialSequencer(BaseModel):
|
|
44
|
+
name: Annotated[str, pdt.StringConstraints(min_length=1, max_length=64)] = Field(
|
|
45
|
+
sa_column=sa.Column(sa_pg.VARCHAR(64), nullable=False),
|
|
46
|
+
description="Versioned identifier of the sequencer definition.",
|
|
47
|
+
schema_extra=dict(examples=["robot_body@1.0"]),
|
|
48
|
+
)
|
|
49
|
+
scope_key_template: Annotated[str, pdt.StringConstraints(max_length=128)] = Field(
|
|
50
|
+
sa_column=sa.Column(sa_pg.VARCHAR(128), nullable=False, server_default=""),
|
|
51
|
+
default="",
|
|
52
|
+
description="Format string for the counter scope key. An empty template denotes global scope.",
|
|
53
|
+
schema_extra=dict(
|
|
54
|
+
examples=[
|
|
55
|
+
"{prefix}",
|
|
56
|
+
"{site}:{batch}",
|
|
57
|
+
"",
|
|
58
|
+
],
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
template: Annotated[str, pdt.StringConstraints(min_length=1, max_length=128)] = Field(
|
|
62
|
+
sa_column=sa.Column(sa_pg.VARCHAR(128), nullable=False),
|
|
63
|
+
description="Format string that places input parameters, the sequence value, and computed characters.",
|
|
64
|
+
schema_extra=dict(
|
|
65
|
+
examples=[
|
|
66
|
+
"{prefix}{sequence}",
|
|
67
|
+
"{prefix}{decimal}",
|
|
68
|
+
],
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
generator_spec: JsonObject = Field(
|
|
72
|
+
sa_column=sa.Column(sa_pg.JSONB(), nullable=False),
|
|
73
|
+
description="Generator definition with named parameters.",
|
|
74
|
+
schema_extra=dict(
|
|
75
|
+
examples=[
|
|
76
|
+
{
|
|
77
|
+
"params": [
|
|
78
|
+
{"key": "prefix", "type": "literal", "regex": "^[A-Z0-9]+$"},
|
|
79
|
+
{"key": "decimal", "type": "sequencer", "width": 5},
|
|
80
|
+
{"key": "variant", "type": "sequencer", "expr": "$seq * 2 + 1", "base": 16},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"params": [
|
|
85
|
+
{"key": "nonce", "type": "uuid"},
|
|
86
|
+
{"key": "counter", "type": "sequencer", "base": 36, "width": 6},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"params": [
|
|
91
|
+
{"key": "site", "type": "literal", "regex": "^[A-Z]{3}$"},
|
|
92
|
+
{"key": "batch", "type": "literal", "regex": "^[0-9]{4}$"},
|
|
93
|
+
{"key": "counter", "type": "sequencer", "width": 5},
|
|
94
|
+
{"key": "nonce", "type": "token", "length": 4, "alphabet": "0123456789"},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
@pdt.field_validator("generator_spec")
|
|
102
|
+
@classmethod
|
|
103
|
+
def validate_generator_spec(cls, value: JsonObject) -> JsonObject:
|
|
104
|
+
SerialGeneratorSpec.model_validate(value)
|
|
105
|
+
return value
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class IssuedSerial(BaseModel):
|
|
109
|
+
sequencer: Annotated[str, pdt.StringConstraints(min_length=1, max_length=64)] = Field(
|
|
110
|
+
sa_column=sa.Column(sa_pg.VARCHAR(64), nullable=False),
|
|
111
|
+
description="Versioned sequencer identifier used to issue this serial number.",
|
|
112
|
+
schema_extra=dict(examples=["robot_body@1.0"]),
|
|
113
|
+
)
|
|
114
|
+
scope_key: Annotated[str, pdt.StringConstraints(max_length=64)] = Field(
|
|
115
|
+
sa_column=sa.Column(sa_pg.VARCHAR(64), nullable=False),
|
|
116
|
+
description="Canonical key identifying a counter within the sequencer. An empty string denotes global scope.",
|
|
117
|
+
schema_extra=dict(examples=["AWESOME", ""]),
|
|
118
|
+
)
|
|
119
|
+
sequence_value: Annotated[int, pdt.Field(ge=1)] = Field(
|
|
120
|
+
sa_column=sa.Column(sa_pg.BIGINT(), nullable=False),
|
|
121
|
+
description="Raw one-based counter for the sequencer and scope, before expression evaluation or formatting.",
|
|
122
|
+
schema_extra=dict(examples=[1, 42, 99999]),
|
|
123
|
+
)
|
|
124
|
+
serial_number: Annotated[str, pdt.StringConstraints(min_length=1, max_length=64)] = Field(
|
|
125
|
+
sa_column=sa.Column(sa_pg.VARCHAR(64), nullable=False),
|
|
126
|
+
description="Final serial number issued after rendering the template.",
|
|
127
|
+
schema_extra=dict(examples=["AWESOME00001"]),
|
|
128
|
+
)
|
|
129
|
+
request_key: Annotated[str, pdt.StringConstraints(min_length=1, max_length=128)] = Field(
|
|
130
|
+
sa_column=sa.Column(sa_pg.VARCHAR(128), nullable=False),
|
|
131
|
+
description="Caller-supplied idempotency key scoped to the sequencer.",
|
|
132
|
+
schema_extra=dict(examples=["unit-001"]),
|
|
133
|
+
)
|
|
134
|
+
params: JsonObject = Field(
|
|
135
|
+
sa_column=sa.Column(sa_pg.JSONB(), nullable=False),
|
|
136
|
+
description="Input parameters used to render the issued serial number.",
|
|
137
|
+
schema_extra=dict(examples=[{"prefix": "AWESOME"}]),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
40
141
|
class RobotSetupSpec(BaseModel):
|
|
41
142
|
flags: int = Field(
|
|
42
143
|
sa_column=sa.Column(sa_pg.INTEGER(), nullable=False),
|
|
@@ -53,10 +154,10 @@ class RobotSetupSpec(BaseModel):
|
|
|
53
154
|
).strip(),
|
|
54
155
|
schema_extra=dict(
|
|
55
156
|
examples=[
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
157
|
+
"demo_single@1.0",
|
|
158
|
+
"demo_dual@1.1",
|
|
159
|
+
"demo_mobile@1.1.0",
|
|
160
|
+
"demo_station@1.1.1",
|
|
60
161
|
]
|
|
61
162
|
),
|
|
62
163
|
)
|
|
@@ -89,8 +190,8 @@ class RobotSetupSpec(BaseModel):
|
|
|
89
190
|
"primary_arm": {
|
|
90
191
|
"type": "object",
|
|
91
192
|
"properties": {
|
|
92
|
-
"brand": {"const": "
|
|
93
|
-
"model": {"const": "
|
|
193
|
+
"brand": {"const": "example_arm_vendor"},
|
|
194
|
+
"model": {"const": "single_arm_v1"},
|
|
94
195
|
"serial_number": {
|
|
95
196
|
"type": "string",
|
|
96
197
|
"minLength": 1,
|
|
@@ -115,17 +216,17 @@ class RobotSetupSpec(BaseModel):
|
|
|
115
216
|
},
|
|
116
217
|
{
|
|
117
218
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
118
|
-
"title": "
|
|
219
|
+
"title": "Example dual-arm setup",
|
|
119
220
|
"type": "object",
|
|
120
221
|
"properties": {
|
|
121
222
|
"left_arm": {
|
|
122
223
|
"type": "object",
|
|
123
224
|
"properties": {
|
|
124
225
|
"brand": {
|
|
125
|
-
"const": "
|
|
226
|
+
"const": "example_arm_vendor"
|
|
126
227
|
},
|
|
127
228
|
"model": {
|
|
128
|
-
"const": "
|
|
229
|
+
"const": "dual_arm_v1"
|
|
129
230
|
},
|
|
130
231
|
"serial_number": {
|
|
131
232
|
"type": "string",
|
|
@@ -143,10 +244,10 @@ class RobotSetupSpec(BaseModel):
|
|
|
143
244
|
"type": "object",
|
|
144
245
|
"properties": {
|
|
145
246
|
"brand": {
|
|
146
|
-
"const": "
|
|
247
|
+
"const": "example_arm_vendor"
|
|
147
248
|
},
|
|
148
249
|
"model": {
|
|
149
|
-
"const": "
|
|
250
|
+
"const": "dual_arm_v1"
|
|
150
251
|
},
|
|
151
252
|
"serial_number": {
|
|
152
253
|
"type": "string",
|
|
@@ -385,10 +486,10 @@ class Robot(BaseModel):
|
|
|
385
486
|
).strip(),
|
|
386
487
|
schema_extra=dict(
|
|
387
488
|
examples=[
|
|
388
|
-
"
|
|
389
|
-
"
|
|
390
|
-
"
|
|
391
|
-
"
|
|
489
|
+
"demo_single-unit_01",
|
|
490
|
+
"demo_dual-unit_02",
|
|
491
|
+
"demo_mobile-00001",
|
|
492
|
+
"demo_station-00002",
|
|
392
493
|
]
|
|
393
494
|
),
|
|
394
495
|
)
|
|
@@ -398,8 +499,8 @@ class Robot(BaseModel):
|
|
|
398
499
|
description="Serial number of the robot's primary device",
|
|
399
500
|
schema_extra=dict(
|
|
400
501
|
examples=[
|
|
401
|
-
"
|
|
402
|
-
"
|
|
502
|
+
"DEMO-SINGLE-000123",
|
|
503
|
+
"DEMO-DUAL-000456",
|
|
403
504
|
None,
|
|
404
505
|
]
|
|
405
506
|
),
|
|
@@ -409,10 +510,10 @@ class Robot(BaseModel):
|
|
|
409
510
|
description="Versioned design that determines which component roles and properties this robot must provide.",
|
|
410
511
|
schema_extra=dict(
|
|
411
512
|
examples=[
|
|
412
|
-
"
|
|
413
|
-
"
|
|
414
|
-
"
|
|
415
|
-
"
|
|
513
|
+
"demo_single@1.0",
|
|
514
|
+
"demo_dual@1.1",
|
|
515
|
+
"demo_mobile@1.1.0",
|
|
516
|
+
"demo_station@1.1.1",
|
|
416
517
|
]
|
|
417
518
|
),
|
|
418
519
|
)
|
|
@@ -428,9 +529,9 @@ class Robot(BaseModel):
|
|
|
428
529
|
examples=[
|
|
429
530
|
{
|
|
430
531
|
"primary_arm": {
|
|
431
|
-
"brand": "
|
|
432
|
-
"model": "
|
|
433
|
-
"serial_number": "
|
|
532
|
+
"brand": "example_arm_vendor",
|
|
533
|
+
"model": "single_arm_v1",
|
|
534
|
+
"serial_number": "DEMO-SINGLE-000123",
|
|
434
535
|
},
|
|
435
536
|
"wrist_camera": {
|
|
436
537
|
"brand": "example_camera_vendor",
|
|
@@ -440,14 +541,14 @@ class Robot(BaseModel):
|
|
|
440
541
|
},
|
|
441
542
|
{
|
|
442
543
|
"left_arm": {
|
|
443
|
-
"brand": "
|
|
444
|
-
"model": "
|
|
445
|
-
"serial_number": "
|
|
544
|
+
"brand": "example_arm_vendor",
|
|
545
|
+
"model": "dual_arm_v1",
|
|
546
|
+
"serial_number": "DEMO-DUAL-000456",
|
|
446
547
|
},
|
|
447
548
|
"right_arm": {
|
|
448
|
-
"brand": "
|
|
449
|
-
"model": "
|
|
450
|
-
"serial_number": "
|
|
549
|
+
"brand": "example_arm_vendor",
|
|
550
|
+
"model": "dual_arm_v1",
|
|
551
|
+
"serial_number": "DEMO-DUAL-000457",
|
|
451
552
|
},
|
|
452
553
|
"controller": {
|
|
453
554
|
"brand": "example_controller_vendor",
|
|
@@ -493,9 +594,9 @@ class BagFormatSpec(BaseModel):
|
|
|
493
594
|
).strip(),
|
|
494
595
|
schema_extra=dict(
|
|
495
596
|
examples=[
|
|
496
|
-
"
|
|
497
|
-
"
|
|
498
|
-
"
|
|
597
|
+
"demo_single@1.0",
|
|
598
|
+
"demo_dual@1.1",
|
|
599
|
+
"demo_generic@1.1.0",
|
|
499
600
|
"lerobot3@1.1.1",
|
|
500
601
|
],
|
|
501
602
|
)
|
|
@@ -589,9 +690,9 @@ class Bag(BaseModel):
|
|
|
589
690
|
description="Identifies the raw recording format needed to read and process this bag.",
|
|
590
691
|
schema_extra=dict(
|
|
591
692
|
examples=[
|
|
592
|
-
"
|
|
593
|
-
"
|
|
594
|
-
"
|
|
693
|
+
"demo_single@1.0",
|
|
694
|
+
"demo_dual@1.1",
|
|
695
|
+
"demo_generic@1.1.0",
|
|
595
696
|
"lerobot3@1.1.1",
|
|
596
697
|
],
|
|
597
698
|
)
|
|
@@ -601,10 +702,10 @@ class Bag(BaseModel):
|
|
|
601
702
|
description="Bag name",
|
|
602
703
|
schema_extra=dict(
|
|
603
704
|
examples=[
|
|
604
|
-
"20260101T000000-
|
|
605
|
-
"20261231T235959-
|
|
606
|
-
"20260101T000000-
|
|
607
|
-
"20261231T235959-
|
|
705
|
+
"20260101T000000-demo_single-unit_01-ep00001",
|
|
706
|
+
"20261231T235959-demo_dual-unit_02-ep00002",
|
|
707
|
+
"20260101T000000-demo_mobile-00001-ep99999",
|
|
708
|
+
"20261231T235959-demo_station-00002-ep99998",
|
|
608
709
|
],
|
|
609
710
|
)
|
|
610
711
|
)
|
|
@@ -618,8 +719,8 @@ class Bag(BaseModel):
|
|
|
618
719
|
).strip(),
|
|
619
720
|
schema_extra=dict(
|
|
620
721
|
examples=[
|
|
621
|
-
"
|
|
622
|
-
"
|
|
722
|
+
"demo_single-unit_01",
|
|
723
|
+
"demo_dual-unit_02",
|
|
623
724
|
]
|
|
624
725
|
),
|
|
625
726
|
)
|
|
@@ -632,10 +733,10 @@ class Bag(BaseModel):
|
|
|
632
733
|
description="Storage path",
|
|
633
734
|
schema_extra=dict(
|
|
634
735
|
examples=[
|
|
635
|
-
"oss://
|
|
636
|
-
"oss://
|
|
637
|
-
"file://mnt/nas/volume1/20260101T000000-
|
|
638
|
-
"file://mnt/nas/volume99/20261231T235959-
|
|
736
|
+
"oss://example-robot-data/offload/20260101T000000-demo_single-unit_01-ep00001/",
|
|
737
|
+
"oss://example-robot-data/offload/20261231T235959-demo_dual-unit_02-ep00002.mcap",
|
|
738
|
+
"file://mnt/nas/volume1/20260101T000000-demo_mobile-00001-ep99999.zip",
|
|
739
|
+
"file://mnt/nas/volume99/20261231T235959-demo_station-00002-ep99998.mcap",
|
|
639
740
|
]
|
|
640
741
|
)
|
|
641
742
|
)
|
|
@@ -696,8 +797,8 @@ class EpisodeFormatSpec(BaseModel):
|
|
|
696
797
|
).strip(),
|
|
697
798
|
schema_extra=dict(
|
|
698
799
|
examples=[
|
|
699
|
-
"
|
|
700
|
-
"
|
|
800
|
+
"demo_unified@1.0",
|
|
801
|
+
"demo_unified@1.1.1",
|
|
701
802
|
]
|
|
702
803
|
)
|
|
703
804
|
)
|
|
@@ -813,8 +914,8 @@ class Episode(BaseModel):
|
|
|
813
914
|
description="Selects the versioned structure and storage format of this processed episode.",
|
|
814
915
|
schema_extra=dict(
|
|
815
916
|
examples=[
|
|
816
|
-
"
|
|
817
|
-
"
|
|
917
|
+
"demo_unified@1.0",
|
|
918
|
+
"demo_unified@1.1.1",
|
|
818
919
|
]
|
|
819
920
|
)
|
|
820
921
|
)
|
|
@@ -823,10 +924,10 @@ class Episode(BaseModel):
|
|
|
823
924
|
description="Episode name",
|
|
824
925
|
schema_extra=dict(
|
|
825
926
|
examples=[
|
|
826
|
-
"20260101T000000-
|
|
827
|
-
"20261231T235959-
|
|
828
|
-
"20260101T000000-
|
|
829
|
-
"20261231T235959-
|
|
927
|
+
"20260101T000000-demo_single-unit_01-ep00001",
|
|
928
|
+
"20261231T235959-demo_dual-unit_02-ep00002",
|
|
929
|
+
"20260101T000000-demo_mobile-00001-ep99999",
|
|
930
|
+
"20261231T235959-demo_station-00002-ep99998",
|
|
830
931
|
],
|
|
831
932
|
)
|
|
832
933
|
)
|
|
@@ -835,10 +936,10 @@ class Episode(BaseModel):
|
|
|
835
936
|
description="Storage path",
|
|
836
937
|
schema_extra=dict(
|
|
837
938
|
examples=[
|
|
838
|
-
"oss://
|
|
839
|
-
"oss://
|
|
840
|
-
"oss://
|
|
841
|
-
"oss://
|
|
939
|
+
"oss://example-robot-data/unified/20260101T000000-demo_single-unit_01-ep00001/",
|
|
940
|
+
"oss://example-robot-data/unified/20261231T235959-demo_dual-unit_02-ep00002/",
|
|
941
|
+
"oss://example-robot-data/unified/20260101T000000-demo_mobile-00001-ep99999/",
|
|
942
|
+
"oss://example-robot-data/unified/20261231T235959-demo_station-00002-ep99998/",
|
|
842
943
|
]
|
|
843
944
|
)
|
|
844
945
|
)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import operator
|
|
3
|
+
import secrets
|
|
4
|
+
import string
|
|
5
|
+
import uuid as py_uuid
|
|
6
|
+
from typing import Annotated, Literal, Self
|
|
7
|
+
|
|
8
|
+
import pydantic as pdt
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"SerialParam",
|
|
12
|
+
"SerialLiteralParam",
|
|
13
|
+
"SerialUuidParam",
|
|
14
|
+
"SerialTokenParam",
|
|
15
|
+
"SerialSequenceParam",
|
|
16
|
+
"SerialGeneratorSpec",
|
|
17
|
+
"render_serial_template",
|
|
18
|
+
"render_generated_serial",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseModel(pdt.BaseModel):
|
|
23
|
+
model_config = pdt.ConfigDict(extra="forbid")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SerialParam(BaseModel):
|
|
27
|
+
key: Annotated[str, pdt.StringConstraints(pattern=r"^[A-Za-z_][A-Za-z0-9_]*$")]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SerialLiteralParam(SerialParam):
|
|
31
|
+
type: Literal["literal"]
|
|
32
|
+
regex: str | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SerialUuidParam(SerialParam):
|
|
36
|
+
type: Literal["uuid"]
|
|
37
|
+
|
|
38
|
+
def generate(self) -> str:
|
|
39
|
+
return str(py_uuid.uuid4())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class SerialTokenParam(SerialParam):
|
|
43
|
+
type: Literal["token"]
|
|
44
|
+
length: Annotated[int, pdt.Field(strict=True, ge=1, le=64)]
|
|
45
|
+
alphabet: Annotated[str, pdt.StringConstraints(min_length=2)]
|
|
46
|
+
|
|
47
|
+
@pdt.field_validator("alphabet")
|
|
48
|
+
@classmethod
|
|
49
|
+
def validate_alphabet(cls, alphabet: str) -> str:
|
|
50
|
+
if len(set(alphabet)) != len(alphabet):
|
|
51
|
+
raise ValueError("token alphabet must contain distinct characters")
|
|
52
|
+
return alphabet
|
|
53
|
+
|
|
54
|
+
def generate(self) -> str:
|
|
55
|
+
return "".join(secrets.choice(self.alphabet) for _ in range(self.length))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class SerialSequenceParam(SerialParam):
|
|
59
|
+
type: Literal["sequencer"]
|
|
60
|
+
expr: Annotated[str, pdt.StringConstraints(min_length=1, max_length=128)] = "$seq"
|
|
61
|
+
base: Annotated[int, pdt.Field(strict=True, ge=2, le=36)] | None = None
|
|
62
|
+
alphabet: Annotated[str, pdt.StringConstraints(min_length=2, max_length=36)] | None = None
|
|
63
|
+
width: Annotated[int, pdt.Field(strict=True, ge=1, le=64)] | None = None
|
|
64
|
+
|
|
65
|
+
@pdt.model_validator(mode="after")
|
|
66
|
+
def validate_alphabet(self) -> Self:
|
|
67
|
+
if self.alphabet is not None:
|
|
68
|
+
if len(set(self.alphabet)) != len(self.alphabet):
|
|
69
|
+
raise ValueError("sequence alphabet must contain distinct characters")
|
|
70
|
+
if self.base is not None and len(self.alphabet) != self.base:
|
|
71
|
+
raise ValueError("sequence alphabet length must match the base")
|
|
72
|
+
return self
|
|
73
|
+
|
|
74
|
+
def evaluate(self, sequence: int) -> str:
|
|
75
|
+
source = self.expr.strip()
|
|
76
|
+
|
|
77
|
+
# Use a replacement of equal length so AST offsets still identify the original variable.
|
|
78
|
+
expression = ast.parse(source.replace("$seq", "_seq"), mode="eval")
|
|
79
|
+
|
|
80
|
+
def evaluate(node: ast.AST) -> int:
|
|
81
|
+
if isinstance(node, ast.Name):
|
|
82
|
+
name = ast.get_source_segment(source, node)
|
|
83
|
+
if name == "$seq":
|
|
84
|
+
return sequence
|
|
85
|
+
raise ValueError(f"unknown sequence variable: {name}")
|
|
86
|
+
if isinstance(node, ast.Constant) and type(node.value) is int:
|
|
87
|
+
return node.value
|
|
88
|
+
if isinstance(node, ast.BinOp):
|
|
89
|
+
match type(node.op):
|
|
90
|
+
case ast.Add:
|
|
91
|
+
return operator.add(evaluate(node.left), evaluate(node.right))
|
|
92
|
+
case ast.Sub:
|
|
93
|
+
return operator.sub(evaluate(node.left), evaluate(node.right))
|
|
94
|
+
case ast.Mult:
|
|
95
|
+
return operator.mul(evaluate(node.left), evaluate(node.right))
|
|
96
|
+
case ast.FloorDiv:
|
|
97
|
+
return operator.floordiv(evaluate(node.left), evaluate(node.right))
|
|
98
|
+
case ast.Mod:
|
|
99
|
+
return operator.mod(evaluate(node.left), evaluate(node.right))
|
|
100
|
+
case _:
|
|
101
|
+
raise ValueError("unsupported sequence operator")
|
|
102
|
+
if isinstance(node, ast.UnaryOp):
|
|
103
|
+
match type(node.op):
|
|
104
|
+
case ast.UAdd:
|
|
105
|
+
return operator.pos(evaluate(node.operand))
|
|
106
|
+
case ast.USub:
|
|
107
|
+
return operator.neg(evaluate(node.operand))
|
|
108
|
+
case _:
|
|
109
|
+
raise ValueError("unsupported sequence operator")
|
|
110
|
+
raise ValueError("unsupported sequence expression")
|
|
111
|
+
|
|
112
|
+
value = evaluate(expression.body)
|
|
113
|
+
if value < 0:
|
|
114
|
+
raise ValueError("sequence expression must produce a nonnegative integer")
|
|
115
|
+
|
|
116
|
+
alphabet = self.alphabet or (string.digits + string.ascii_uppercase)[:self.base or 10]
|
|
117
|
+
digits = []
|
|
118
|
+
while value:
|
|
119
|
+
value, digit = divmod(value, len(alphabet))
|
|
120
|
+
digits.append(alphabet[digit])
|
|
121
|
+
return ("".join(reversed(digits)) or alphabet[0]).rjust(self.width or 0, alphabet[0])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class SerialGeneratorSpec(BaseModel):
|
|
125
|
+
params: Annotated[list[Annotated[
|
|
126
|
+
SerialLiteralParam | SerialUuidParam | SerialTokenParam | SerialSequenceParam,
|
|
127
|
+
pdt.Field(discriminator="type"),
|
|
128
|
+
]], pdt.Field(min_length=1)]
|
|
129
|
+
|
|
130
|
+
@pdt.model_validator(mode="after")
|
|
131
|
+
def validate_unique_keys(self) -> Self:
|
|
132
|
+
keys = {param.key for param in self.params}
|
|
133
|
+
if len(keys) != len(self.params):
|
|
134
|
+
raise ValueError("serial parameter keys must be unique")
|
|
135
|
+
|
|
136
|
+
return self
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def render_serial_template(template: str, values: dict[str, str]) -> str:
|
|
140
|
+
for _, field, spec, conversion in string.Formatter().parse(template):
|
|
141
|
+
if field is not None and (field not in values or spec or conversion is not None):
|
|
142
|
+
raise ValueError("serial templates require plain named placeholders")
|
|
143
|
+
return template.format_map(values)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def render_generated_serial(
|
|
147
|
+
template: str,
|
|
148
|
+
spec: SerialGeneratorSpec,
|
|
149
|
+
params: dict[str, str],
|
|
150
|
+
sequence: int,
|
|
151
|
+
) -> str:
|
|
152
|
+
values = dict(params)
|
|
153
|
+
for param in spec.params:
|
|
154
|
+
if isinstance(param, SerialSequenceParam):
|
|
155
|
+
values[param.key] = param.evaluate(sequence)
|
|
156
|
+
elif isinstance(param, (SerialUuidParam, SerialTokenParam)):
|
|
157
|
+
values[param.key] = param.generate()
|
|
158
|
+
|
|
159
|
+
return render_serial_template(template, values)
|
|
@@ -15,8 +15,10 @@ from plexus.pulse.demeter.domains.robotic.models.catalog import (
|
|
|
15
15
|
DatasetItem,
|
|
16
16
|
Episode,
|
|
17
17
|
EpisodeFormatSpec,
|
|
18
|
+
IssuedSerial,
|
|
18
19
|
Robot,
|
|
19
20
|
RobotSetupSpec,
|
|
21
|
+
SerialSequencer,
|
|
20
22
|
Tag,
|
|
21
23
|
Tagset,
|
|
22
24
|
TagsetSpec,
|
|
@@ -24,6 +26,8 @@ from plexus.pulse.demeter.domains.robotic.models.catalog import (
|
|
|
24
26
|
from plexus.pulse.demeter.platform.database import DatabaseModel
|
|
25
27
|
|
|
26
28
|
__all__ = [
|
|
29
|
+
"SerialSequencerTable",
|
|
30
|
+
"IssuedSerialTable",
|
|
27
31
|
"RobotSetupSpecTable",
|
|
28
32
|
"RobotTable",
|
|
29
33
|
"BagFormatSpecTable",
|
|
@@ -40,6 +44,33 @@ __all__ = [
|
|
|
40
44
|
]
|
|
41
45
|
|
|
42
46
|
|
|
47
|
+
class SerialSequencerTable(SerialSequencer, make_changing_model_mixin(), DatabaseModel, table=True):
|
|
48
|
+
__tablename__ = "serial_sequencer"
|
|
49
|
+
|
|
50
|
+
__table_args__ = (
|
|
51
|
+
changing_model_mixin.make_index_created_at("ix_serial_sequencer_created_at"),
|
|
52
|
+
sa.UniqueConstraint("name", name="uq_serial_sequencer_name"),
|
|
53
|
+
sa.CheckConstraint(sa.column("updated_at") >= sa.column("created_at"), name="ck_serial_sequencer_updated_at"),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class IssuedSerialTable(IssuedSerial, make_changing_model_mixin(), DatabaseModel, table=True):
|
|
58
|
+
__tablename__ = "issued_serial"
|
|
59
|
+
|
|
60
|
+
__table_args__ = (
|
|
61
|
+
changing_model_mixin.make_index_created_at("ix_issued_serial_created_at"),
|
|
62
|
+
sa.UniqueConstraint("sequencer", "request_key", name="uq_issued_serial_request_key"),
|
|
63
|
+
sa.ForeignKeyConstraint(["sequencer"],
|
|
64
|
+
["pulse_demeter.serial_sequencer.name"],
|
|
65
|
+
name="fk_issued_serial_sequencer",
|
|
66
|
+
ondelete="RESTRICT"),
|
|
67
|
+
sa.UniqueConstraint("sequencer", "scope_key", "sequence_value", name="uq_issued_serial_scope_sequence"),
|
|
68
|
+
sa.UniqueConstraint("sequencer", "serial_number", name="uq_issued_serial_serial_number"),
|
|
69
|
+
sa.CheckConstraint(sa.column("sequence_value") >= 1, name="ck_issued_serial_sequence_value"),
|
|
70
|
+
sa.CheckConstraint(sa.column("updated_at") >= sa.column("created_at"), name="ck_issued_serial_updated_at"),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
43
74
|
class RobotSetupSpecTable(RobotSetupSpec, make_changing_model_mixin(), DatabaseModel, table=True):
|
|
44
75
|
__tablename__ = "robot_setup_spec"
|
|
45
76
|
|
|
@@ -60,6 +91,7 @@ class RobotTable(Robot, make_revision_model_mixin(), DatabaseModel, table=True):
|
|
|
60
91
|
revision_model_mixin.make_active_unique_index_record_sqn("ix_robot_active_record"),
|
|
61
92
|
revision_model_mixin.make_active_unique_index_for("ix_robot_active_uuid", "uuid"),
|
|
62
93
|
revision_model_mixin.make_active_unique_index_for("ix_robot_active_alias", "alias"),
|
|
94
|
+
revision_model_mixin.make_active_unique_index_for("ix_robot_active_serial_number", "serial_number"),
|
|
63
95
|
sa.Index("ix_robot_setup_spec", "setup_spec"),
|
|
64
96
|
sa.ForeignKeyConstraint(["setup_spec"],
|
|
65
97
|
["pulse_demeter.robot_setup_spec.name"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plexus-python-pulse-demeter
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.150
|
|
4
4
|
Classifier: Programming Language :: Python :: 3
|
|
5
5
|
Classifier: Programming Language :: Python :: 3.12
|
|
6
6
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -22,6 +22,7 @@ Requires-Dist: prometheus-client>=0.21; extra == "api"
|
|
|
22
22
|
Requires-Dist: python-multipart; extra == "api"
|
|
23
23
|
Requires-Dist: uvicorn; extra == "api"
|
|
24
24
|
Requires-Dist: plexus-python-pulse-common[api,tags]>=1.2; extra == "api"
|
|
25
|
+
Requires-Dist: zxing-cpp>=3.1; extra == "api"
|
|
25
26
|
Provides-Extra: cli
|
|
26
27
|
Requires-Dist: click>=8.1; extra == "cli"
|
|
27
28
|
Requires-Dist: cloudpathlib[s3]>=0.21; extra == "cli"
|
|
@@ -36,8 +37,10 @@ Requires-Dist: plexus-python-pulse-common[s3]>=1.2; extra == "sdk"
|
|
|
36
37
|
Provides-Extra: test
|
|
37
38
|
Requires-Dist: ddt>=1.7; extra == "test"
|
|
38
39
|
Requires-Dist: moto[s3,server]>=5.1; extra == "test"
|
|
40
|
+
Requires-Dist: pillow>=11.0; extra == "test"
|
|
39
41
|
Requires-Dist: pytest-cov>=5.0; extra == "test"
|
|
40
42
|
Requires-Dist: pytest-httpx2>=1.0; extra == "test"
|
|
41
43
|
Requires-Dist: pytest-order>=1.3; extra == "test"
|
|
42
44
|
Requires-Dist: pytest-postgresql>=6.1; extra == "test"
|
|
43
45
|
Requires-Dist: pytest>=9.2; extra == "test"
|
|
46
|
+
Requires-Dist: resvg-py>=0.5; extra == "test"
|
|
@@ -31,8 +31,8 @@ plexus/pulse/demeter/domains/robotic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
|
|
|
31
31
|
plexus/pulse/demeter/domains/robotic/capsule.py,sha256=Ydz_bAfUr9Kd_UDC0Upn_vP-ehULEoSGMXdsZQFQyT8,41481
|
|
32
32
|
plexus/pulse/demeter/domains/robotic/client.py,sha256=p_hI-zauLbMQxXY9QHjzX6FpGS2OHmnEWj8r_AuI6jQ,7262
|
|
33
33
|
plexus/pulse/demeter/domains/robotic/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
plexus/pulse/demeter/domains/robotic/api/catalog_endpoints.py,sha256
|
|
35
|
-
plexus/pulse/demeter/domains/robotic/api/catalog_internal_endpoints.py,sha256=
|
|
34
|
+
plexus/pulse/demeter/domains/robotic/api/catalog_endpoints.py,sha256=4vZhvR_pBgbGobBWhaH8YXOTBRseVe4IJk4QeyU3_2w,48778
|
|
35
|
+
plexus/pulse/demeter/domains/robotic/api/catalog_internal_endpoints.py,sha256=8lWY3a5VLE7z2c2AhZYRyXADop528G9qlJZjbzkfk9k,36136
|
|
36
36
|
plexus/pulse/demeter/domains/robotic/api/pipeline_endpoints.py,sha256=dPnePjtROvzbrYO2lPkNRqG5vZMWbTcRnibply20mF0,48959
|
|
37
37
|
plexus/pulse/demeter/domains/robotic/api/pipeline_internal_endpoints.py,sha256=AU8IUrbEiGOQv8o3E5r14Q6f9kEgHA3q8XVwrqgqq2Y,17723
|
|
38
38
|
plexus/pulse/demeter/domains/robotic/api/pipeline_metrics_endpoints.py,sha256=DGsABhXGJ_qg-rECu4paBOS1JpdkVV6prWsYstPzhV4,8560
|
|
@@ -41,14 +41,15 @@ plexus/pulse/demeter/domains/robotic/cli/flow_ops.py,sha256=wvGjkjEqo5p5P3qId9F-
|
|
|
41
41
|
plexus/pulse/demeter/domains/robotic/cli/pipeline.py,sha256=OTSwRTIYN1ApIs3xlHoEOoBalfmlKGLXMpm-H4uQCHo,12980
|
|
42
42
|
plexus/pulse/demeter/domains/robotic/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
43
|
plexus/pulse/demeter/domains/robotic/models/capsule.py,sha256=7_eLgL_1W8Q1ujd3uBvMnygHxRT3FSgJiN6XbN0i74w,13179
|
|
44
|
-
plexus/pulse/demeter/domains/robotic/models/catalog.py,sha256=
|
|
44
|
+
plexus/pulse/demeter/domains/robotic/models/catalog.py,sha256=wtnaAqx6Zt_NgG_q9YmAi_o2I74c-8MV2jo2-bc9EsU,57683
|
|
45
45
|
plexus/pulse/demeter/domains/robotic/models/flow.py,sha256=li8RKuvmtViEWnlmkLbQ46EB0mqleHZz4NJq4nIGrIg,6388
|
|
46
46
|
plexus/pulse/demeter/domains/robotic/models/pipeline.py,sha256=deRI3hG7Z4kfTRyQEb8X3BZ4RFjW4SW6JIT6aw_ET3M,19442
|
|
47
|
+
plexus/pulse/demeter/domains/robotic/models/serial.py,sha256=GnmNqgYJTmRJ9KXx9ssFOu9fRi-lGfT9OAJEmwjVDZ4,5954
|
|
47
48
|
plexus/pulse/demeter/domains/robotic/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
49
|
plexus/pulse/demeter/domains/robotic/sdk/flow.py,sha256=KWZvXYfS3bCEwVELdlUcpELWvtAFfwdP6DmOHJhjuak,1806
|
|
49
50
|
plexus/pulse/demeter/domains/robotic/sdk/oss.py,sha256=wMzHzRUZsU_p6P-qIGU7kTa4W1JV4bl7KPXk2SsVcwY,1874
|
|
50
51
|
plexus/pulse/demeter/domains/robotic/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
|
-
plexus/pulse/demeter/domains/robotic/tables/catalog.py,sha256=
|
|
52
|
+
plexus/pulse/demeter/domains/robotic/tables/catalog.py,sha256=sgX_TFIl_Q_034SxM0AbPJbBg9nqkRd1q31V_7lr5M8,13140
|
|
52
53
|
plexus/pulse/demeter/domains/robotic/tables/pipeline.py,sha256=UUVO0ikGl7dX0PkZ_ArtyUqgyMyk8dpLEFhRgSyHJKQ,9353
|
|
53
54
|
plexus/pulse/demeter/platform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
54
55
|
plexus/pulse/demeter/platform/cli.py,sha256=v43SCZvF76JIk2sR-a5PY0n2YbeW0bHTsk2FC26mw-8,1977
|
|
@@ -62,8 +63,8 @@ plexus/pulse/demeter/platform/models/__init__.py,sha256=eDzE5DfmvnE1258XLGQir_K3
|
|
|
62
63
|
plexus/pulse/demeter/platform/models/iam.py,sha256=v7M6UCHoHekFbVK_shYXGln9R5DkO3Q070EtmIdRwf0,9713
|
|
63
64
|
plexus/pulse/demeter/platform/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
64
65
|
plexus/pulse/demeter/platform/tables/iam.py,sha256=K0Jaf0KIr9vKsmQ92n4_nh1ZJhN2Tr9l0JpiixBtFfg,10568
|
|
65
|
-
plexus_python_pulse_demeter-1.2.
|
|
66
|
-
plexus_python_pulse_demeter-1.2.
|
|
67
|
-
plexus_python_pulse_demeter-1.2.
|
|
68
|
-
plexus_python_pulse_demeter-1.2.
|
|
69
|
-
plexus_python_pulse_demeter-1.2.
|
|
66
|
+
plexus_python_pulse_demeter-1.2.150.dist-info/METADATA,sha256=mtpX0P7RVEVgSlg7rkdqEfQ6PbIcApDHNN9ujcpgSmw,1942
|
|
67
|
+
plexus_python_pulse_demeter-1.2.150.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
68
|
+
plexus_python_pulse_demeter-1.2.150.dist-info/entry_points.txt,sha256=hJz_bf2aQIWXZTWbZIvtGQQNZFTQk-sro9leV_zHTdw,110
|
|
69
|
+
plexus_python_pulse_demeter-1.2.150.dist-info/top_level.txt,sha256=ug_g7CVwaMQuas5UzAXbHUrQvKGCn8ezc6ZNvvRlJOE,7
|
|
70
|
+
plexus_python_pulse_demeter-1.2.150.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|