scene_service.annotations

User annotations — user-authored semantics anchored to the SLAM map.

Functions

validate_annotation_fields(kind, name, ...)

Validate user-supplied annotation fields; return an error string on the first violation, None when everything is acceptable.

Classes

Annotation(annotation_id, kind, name, ...)

One user annotation.

AnnotationStore(base_dir, *, map_id[, ...])

Per-map JSON persistence for user annotations.

class scene_service.annotations.Annotation(annotation_id: str, kind: str, name: str, points: list[list[float]] = <factory>, theta: float | None = None, created_at: float = 0.0, updated_at: float = 0.0, stale: bool = False, stale_reason: str = '')[source]

Bases: object

One user annotation.

annotation_id: str
created_at: float = 0.0
classmethod from_json(d: dict) → Annotation[source]

Rebuild from a stored dict, dropping unknown keys so a file written by a newer scene still loads (forward-tolerant).

kind: str
name: str
points: list[list[float]]
stale: bool = False
stale_reason: str = ''
theta: float | None = None
to_json() → dict[source]
updated_at: float = 0.0
class scene_service.annotations.AnnotationStore(base_dir: str, *, map_id: str, generation: int | None = None)[source]

Bases: object

Per-map JSON persistence for user annotations.

create(*, kind: str, name: str, points: list, theta: float | None = None) → Annotation[source]

Create + persist an annotation and return it.

delete(annotation_id: str) → bool[source]

Remove an annotation; True when it existed. Persists on change.

delete_map(map_id: str) → bool[source]

Delete exactly one persisted annotation partition.

get(annotation_id: str) → Annotation | None[source]
has_saved(map_id: str) → bool[source]

True when a persisted annotation file already exists for map_id.

list() → list[Annotation][source]
list_json() → list[dict][source]

JSON-ready dump of every annotation (the /api/state field and GET /api/annotations share this shape).

property map_id: str
mark_all_stale(reason: str, *, new_generation: int | None = None) → int[source]

Flag every non-stale annotation stale with reason (map frame epoch changed at runtime — the _lifecycle_watch hook).

property path: Path
read_saved(map_id: str) → list[dict][source]

Another map’s regions, read without rebinding; [] if unreadable.

rebind(map_id: str, *, generation: int | None = None, carry_current: bool = False) → None[source]

Switch this store to another map partition.

reconcile_generation(live_generation: int) → int[source]

Called when the map’s true generation becomes known at runtime (the lifecycle watcher’s confirmation) — a store built under a static binding (generation None) cannot judge staleness at load time, so the judgement happens here instead.

snapshot(map_id: str, *, generation: int | None = None) → Path[source]

Write another map’s snapshot without changing the live partition.

update(annotation_id: str, *, name: str | None = None, points: list | None = None, theta: float | None = None, clear_stale: bool = False) → Annotation | None[source]

Apply the provided fields to an existing annotation (None = keep), bump updated_at, persist, and return it; None when the id is unknown.

scene_service.annotations.normalize_kind(kind)[source]

The current name for an annotation kind, mapping deprecated ones.

scene_service.annotations.validate_annotation_fields(kind: str, name: Any, points: Any, theta: Any) → str | None[source]

Validate user-supplied annotation fields; return an error string on the first violation, None when everything is acceptable.