feat(viewer): unify spatial clipping, planning and observation surfaces
Share spatial clipping and height slices across live planning and recorded observations. Refine scene navigation, report serialization and viewer presentation.
This commit is contained in:
@@ -21,6 +21,7 @@ from .drafts import DraftConflict
|
||||
from .live_display_buffer import LiveDisplayBuffer
|
||||
from .live_limits import live_route_limits
|
||||
from .live_presentation import PRESENTATION_POLICY, LivePresentation, stored_alignment
|
||||
from .live_report_json import ReportJSONCache
|
||||
from .live_scene import scene_bytes
|
||||
from .live_scene_delta import scene_delta
|
||||
from .observation_profiles import SCENE_INPUT
|
||||
@@ -58,6 +59,7 @@ class PlanningLiveTests:
|
||||
self.cancel = threading.Event()
|
||||
self.thread = None
|
||||
self.revision = 0
|
||||
self._report_json = ReportJSONCache()
|
||||
self.last_frame_ns = 0
|
||||
self.last_result_ns = 0
|
||||
self.source = None
|
||||
@@ -189,36 +191,66 @@ class PlanningLiveTests:
|
||||
self.revision += 1
|
||||
self.persist()
|
||||
|
||||
def get(self):
|
||||
def get_status(self):
|
||||
return self.get(compact=True)
|
||||
|
||||
def get(self, *, compact=False):
|
||||
with self.lock:
|
||||
if self.run is None:
|
||||
return None
|
||||
result = json.loads(json.dumps(self.run))
|
||||
now = time.monotonic_ns()
|
||||
result["frame_age_s"] = (now - self.last_frame_ns) / 1e9 if self.last_frame_ns else None
|
||||
result["result_age_s"] = (
|
||||
(now - self.last_result_ns) / 1e9 if self.last_result_ns else None
|
||||
)
|
||||
result["stale"] = not self.last_frame_ns or now - self.last_frame_ns > 8_000_000_000
|
||||
result["scene_available"] = self.reference is not None
|
||||
result["scene_height_min_m"], result["scene_height_max_m"] = self.scene_height_bounds()
|
||||
result["scene_revision"] = self.revision
|
||||
result["presentation_state"] = (
|
||||
"live"
|
||||
if self._view_live(now)
|
||||
else "historical"
|
||||
if self.presentation.result
|
||||
else "unlocalized"
|
||||
)
|
||||
result["pose_age_s"] = (
|
||||
(now - self.latest_pose["monotonic_ns"]) / 1e9 if self.latest_pose else None
|
||||
)
|
||||
result["scanner_pose"] = self.latest_pose
|
||||
if self.display.packet is not None or "display" not in result:
|
||||
result["display"] = self.display.diagnostics()
|
||||
result["browser_presentation"] = self.browser_presentation.diagnostics()
|
||||
if compact:
|
||||
from .live_status import status_document
|
||||
result = status_document(self.run)
|
||||
else:
|
||||
result = json.loads(json.dumps(self.run))
|
||||
fields = self._runtime_status(compact=compact)
|
||||
if not compact and self.display.packet is None and "display" in self.run:
|
||||
fields.pop("display") # Preserve the independent report copy.
|
||||
result.update(fields)
|
||||
return result
|
||||
|
||||
def get_json(self):
|
||||
"""Full legacy report without repeatedly copying immutable numerical evidence."""
|
||||
with self.lock:
|
||||
if self.run is None:
|
||||
self._report_json.clear()
|
||||
return b"null"
|
||||
return self._report_json.encode(
|
||||
self.run, self.revision, self._runtime_status(),
|
||||
cacheable=self.run["state"] in TERMINAL,
|
||||
)
|
||||
|
||||
def _runtime_status(self, *, compact=False):
|
||||
result = {}
|
||||
now = time.monotonic_ns()
|
||||
result["frame_age_s"] = (now - self.last_frame_ns) / 1e9 if self.last_frame_ns else None
|
||||
result["result_age_s"] = (
|
||||
(now - self.last_result_ns) / 1e9 if self.last_result_ns else None
|
||||
)
|
||||
result["stale"] = not self.last_frame_ns or now - self.last_frame_ns > 8_000_000_000
|
||||
result["scene_available"] = self.reference is not None
|
||||
result["scene_height_min_m"], result["scene_height_max_m"] = self.scene_height_bounds()
|
||||
result["scene_revision"] = self.revision
|
||||
result["presentation_state"] = (
|
||||
"live"
|
||||
if self._view_live(now)
|
||||
else "historical"
|
||||
if self.presentation.result
|
||||
else "unlocalized"
|
||||
)
|
||||
if compact:
|
||||
return result
|
||||
result["pose_age_s"] = (
|
||||
(now - self.latest_pose["monotonic_ns"]) / 1e9 if self.latest_pose else None
|
||||
)
|
||||
result["scanner_pose"] = self.latest_pose
|
||||
if self.display.packet is not None or "display" not in self.run:
|
||||
result["display"] = self.display.diagnostics()
|
||||
else:
|
||||
result["display"] = self.run["display"]
|
||||
result["browser_presentation"] = self.browser_presentation.diagnostics()
|
||||
return result
|
||||
|
||||
def scene_height_bounds(self):
|
||||
# Reference arrays are frozen and replaced as a unit. Do not rescan
|
||||
# and copy a route-wide map under the consumer lock on every UI poll.
|
||||
|
||||
Reference in New Issue
Block a user