feat(lidar): add point-aligned ground review
This commit is contained in:
+73
-15
@@ -14,14 +14,13 @@ from k1link.compute import (
|
||||
LidarReplayError,
|
||||
LidarReplayPackV2,
|
||||
lidar_ground_benchmark_catalog_item,
|
||||
lidar_ground_frame_detail,
|
||||
lidar_pack_catalog_item,
|
||||
lidar_pack_detail,
|
||||
)
|
||||
|
||||
LIDAR_CATALOG_SCHEMA: Final = "missioncore.lidar-replay-pack-catalog/v1"
|
||||
LIDAR_GROUND_CATALOG_SCHEMA: Final = (
|
||||
"missioncore.lidar-ground-benchmark-catalog/v1"
|
||||
)
|
||||
LIDAR_GROUND_CATALOG_SCHEMA: Final = "missioncore.lidar-ground-benchmark-catalog/v1"
|
||||
_PACK_ID = re.compile(r"^lidar-replay-pack-[a-f0-9]{64}$")
|
||||
_BENCHMARK_ID = re.compile(r"^ground-benchmark-[a-f0-9]{64}$")
|
||||
RootProvider = Callable[[], Path | None]
|
||||
@@ -143,8 +142,7 @@ def build_lidar_router(
|
||||
(
|
||||
candidate
|
||||
for candidate in root.iterdir()
|
||||
if candidate.is_dir()
|
||||
and _BENCHMARK_ID.fullmatch(candidate.name) is not None
|
||||
if candidate.is_dir() and _BENCHMARK_ID.fullmatch(candidate.name) is not None
|
||||
),
|
||||
key=lambda candidate: candidate.stat().st_mtime_ns,
|
||||
reverse=True,
|
||||
@@ -153,13 +151,8 @@ def build_lidar_router(
|
||||
try:
|
||||
benchmark = LidarGroundBenchmarkV1(candidate)
|
||||
try:
|
||||
if (
|
||||
pack_id is None
|
||||
or benchmark.identity.get("replay_pack_id") == pack_id
|
||||
):
|
||||
items.append(
|
||||
lidar_ground_benchmark_catalog_item(benchmark)
|
||||
)
|
||||
if pack_id is None or benchmark.identity.get("replay_pack_id") == pack_id:
|
||||
items.append(lidar_ground_benchmark_catalog_item(benchmark))
|
||||
finally:
|
||||
benchmark.close()
|
||||
except (LidarGroundError, OSError):
|
||||
@@ -196,9 +189,7 @@ def build_lidar_router(
|
||||
benchmark = LidarGroundBenchmarkV1(candidate)
|
||||
try:
|
||||
return {
|
||||
"schema_version": (
|
||||
"missioncore.lidar-ground-benchmark-detail/v1"
|
||||
),
|
||||
"schema_version": ("missioncore.lidar-ground-benchmark-detail/v1"),
|
||||
"benchmark": lidar_ground_benchmark_catalog_item(benchmark),
|
||||
"report": benchmark.report,
|
||||
"access": "read-only",
|
||||
@@ -211,4 +202,71 @@ def build_lidar_router(
|
||||
detail="LiDAR ground benchmark не прошёл проверку целостности",
|
||||
) from exc
|
||||
|
||||
@router.get("/ground-benchmarks/{benchmark_id}/frames/{frame_index}")
|
||||
def get_lidar_ground_frame(
|
||||
benchmark_id: str,
|
||||
frame_index: int,
|
||||
) -> dict[str, object]:
|
||||
if _BENCHMARK_ID.fullmatch(benchmark_id) is None or frame_index < 0:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="LiDAR ground frame не найден",
|
||||
)
|
||||
ground_root = ground_root_provider()
|
||||
replay_root = root_provider()
|
||||
if ground_root is None or not ground_root.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="LiDAR ground storage не настроен",
|
||||
)
|
||||
if replay_root is None or not replay_root.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="LiDAR replay storage не настроен",
|
||||
)
|
||||
benchmark_path = ground_root / benchmark_id
|
||||
if not benchmark_path.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="LiDAR ground benchmark не найден",
|
||||
)
|
||||
try:
|
||||
benchmark = LidarGroundBenchmarkV1(benchmark_path)
|
||||
try:
|
||||
replay_pack_id = benchmark.identity.get("replay_pack_id")
|
||||
if (
|
||||
not isinstance(replay_pack_id, str)
|
||||
or _PACK_ID.fullmatch(replay_pack_id) is None
|
||||
):
|
||||
raise LidarGroundError("Ground benchmark replay identity is invalid")
|
||||
replay_path = replay_root / replay_pack_id
|
||||
if not replay_path.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный LiDAR replay pack не найден",
|
||||
)
|
||||
replay = LidarReplayPackV2(replay_path)
|
||||
try:
|
||||
return lidar_ground_frame_detail(
|
||||
benchmark,
|
||||
replay,
|
||||
frame_index,
|
||||
)
|
||||
finally:
|
||||
replay.close()
|
||||
finally:
|
||||
benchmark.close()
|
||||
except IndexError as exc:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="LiDAR ground frame не найден",
|
||||
) from exc
|
||||
except HTTPException:
|
||||
raise
|
||||
except (LidarGroundError, LidarReplayError, OSError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="LiDAR ground frame не прошёл проверку целостности",
|
||||
) from exc
|
||||
|
||||
return router
|
||||
|
||||
Reference in New Issue
Block a user