perf(data): bound lidar readers and lab session loading
This commit is contained in:
+25
-78
@@ -9,14 +9,11 @@ from typing import Annotated, Any, Final
|
||||
from fastapi import APIRouter, HTTPException, Query, Response
|
||||
|
||||
from k1link.compute import (
|
||||
E10LidarFieldSource,
|
||||
K1LocalSurfaceV1,
|
||||
LidarFieldReviewV1,
|
||||
LidarGroundBenchmarkV1,
|
||||
LidarGroundError,
|
||||
LidarReplayError,
|
||||
LidarReplayPackV2,
|
||||
k1_local_surface_catalog_item,
|
||||
lidar_field_review_catalog_item,
|
||||
lidar_ground_benchmark_catalog_item,
|
||||
lidar_ground_frame_detail,
|
||||
@@ -33,6 +30,10 @@ from k1link.datasets import (
|
||||
read_dataset_ground_preview,
|
||||
read_dataset_native_scan_preview,
|
||||
)
|
||||
from k1link.web.lidar_local_surface_service import (
|
||||
K1LocalSurfaceReadService,
|
||||
LocalSurfaceSourceUnavailable,
|
||||
)
|
||||
|
||||
LIDAR_CATALOG_SCHEMA: Final = "missioncore.lidar-replay-pack-catalog/v1"
|
||||
LIDAR_GROUND_CATALOG_SCHEMA: Final = "missioncore.lidar-ground-benchmark-catalog/v1"
|
||||
@@ -42,7 +43,6 @@ _PACK_ID = re.compile(r"^lidar-replay-pack-[a-f0-9]{64}$")
|
||||
_BENCHMARK_ID = re.compile(r"^ground-benchmark-[a-f0-9]{64}$")
|
||||
_FIELD_REVIEW_ID = re.compile(r"^lidar-field-review-[a-f0-9]{64}$")
|
||||
_LOCAL_SURFACE_ID = re.compile(r"^k1-local-surface-[a-f0-9]{64}$")
|
||||
_E10_PACK_ID = re.compile(r"^e10-lidar-pack-[a-f0-9]{64}$")
|
||||
RootProvider = Callable[[], Path | None]
|
||||
DatasetArtifactProvider = Callable[[], Path | None]
|
||||
|
||||
@@ -84,8 +84,10 @@ def build_lidar_router(
|
||||
dataset_rellis_preview_provider: DatasetArtifactProvider = lambda: None,
|
||||
dataset_rellis_admission_provider: DatasetArtifactProvider = lambda: None,
|
||||
dataset_ground_preview_provider: DatasetArtifactProvider = configured_dataset_ground_preview,
|
||||
local_surface_read_service: K1LocalSurfaceReadService | None = None,
|
||||
) -> APIRouter:
|
||||
router = APIRouter(prefix="/api/v1/lidar", tags=["lidar"])
|
||||
surface_reader = local_surface_read_service or K1LocalSurfaceReadService()
|
||||
|
||||
@router.get("/dataset-gateway")
|
||||
def get_dataset_gateway() -> dict[str, object]:
|
||||
@@ -531,11 +533,7 @@ def build_lidar_router(
|
||||
if len(items) >= limit:
|
||||
break
|
||||
try:
|
||||
model = K1LocalSurfaceV1(candidate)
|
||||
try:
|
||||
items.append(k1_local_surface_catalog_item(model))
|
||||
finally:
|
||||
model.close()
|
||||
items.append(surface_reader.catalog_item(candidate))
|
||||
except (LidarGroundError, OSError):
|
||||
invalid_total += 1
|
||||
return {
|
||||
@@ -575,29 +573,12 @@ def build_lidar_router(
|
||||
detail="K1 local-surface model не найден",
|
||||
)
|
||||
try:
|
||||
model = K1LocalSurfaceV1(model_path)
|
||||
try:
|
||||
source_pack_id = model.identity.get("source_pack_id")
|
||||
if (
|
||||
not isinstance(source_pack_id, str)
|
||||
or _E10_PACK_ID.fullmatch(source_pack_id) is None
|
||||
):
|
||||
raise LidarGroundError("K1 local-surface source id is invalid")
|
||||
source_path = source_root / source_pack_id
|
||||
if not source_path.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
)
|
||||
source = E10LidarFieldSource(source_path)
|
||||
try:
|
||||
return model.timeline_detail(source)
|
||||
finally:
|
||||
source.close()
|
||||
finally:
|
||||
model.close()
|
||||
except HTTPException:
|
||||
raise
|
||||
return surface_reader.timeline_detail(model_path, source_root)
|
||||
except LocalSurfaceSourceUnavailable as exc:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
) from exc
|
||||
except (LidarGroundError, OSError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
@@ -630,29 +611,12 @@ def build_lidar_router(
|
||||
detail="K1 local-surface model не найден",
|
||||
)
|
||||
try:
|
||||
model = K1LocalSurfaceV1(model_path)
|
||||
try:
|
||||
source_pack_id = model.identity.get("source_pack_id")
|
||||
if (
|
||||
not isinstance(source_pack_id, str)
|
||||
or _E10_PACK_ID.fullmatch(source_pack_id) is None
|
||||
):
|
||||
raise LidarGroundError("K1 local-surface source id is invalid")
|
||||
source_path = source_root / source_pack_id
|
||||
if not source_path.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
)
|
||||
source = E10LidarFieldSource(source_path)
|
||||
try:
|
||||
return model.review_detail(source)
|
||||
finally:
|
||||
source.close()
|
||||
finally:
|
||||
model.close()
|
||||
except HTTPException:
|
||||
raise
|
||||
return surface_reader.review_detail(model_path, source_root)
|
||||
except LocalSurfaceSourceUnavailable as exc:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
) from exc
|
||||
except (LidarGroundError, OSError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
@@ -688,34 +652,17 @@ def build_lidar_router(
|
||||
detail="K1 local-surface model не найден",
|
||||
)
|
||||
try:
|
||||
model = K1LocalSurfaceV1(model_path)
|
||||
try:
|
||||
source_pack_id = model.identity.get("source_pack_id")
|
||||
if (
|
||||
not isinstance(source_pack_id, str)
|
||||
or _E10_PACK_ID.fullmatch(source_pack_id) is None
|
||||
):
|
||||
raise LidarGroundError("K1 local-surface source id is invalid")
|
||||
source_path = source_root / source_pack_id
|
||||
if not source_path.is_dir():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
)
|
||||
source = E10LidarFieldSource(source_path)
|
||||
try:
|
||||
return model.frame_detail(source, frame_index)
|
||||
finally:
|
||||
source.close()
|
||||
finally:
|
||||
model.close()
|
||||
return surface_reader.frame_detail(model_path, source_root, frame_index)
|
||||
except IndexError as exc:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="K1 local-surface frame не найден",
|
||||
) from exc
|
||||
except HTTPException:
|
||||
raise
|
||||
except LocalSurfaceSourceUnavailable as exc:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Связанный E10 LiDAR source не найден",
|
||||
) from exc
|
||||
except (LidarGroundError, OSError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
|
||||
Reference in New Issue
Block a user