fix(perception): reconstruct rolling occupancy from K1 increments

This commit is contained in:
DCCONSTRUCTIONS
2026-08-05 21:12:47 +03:00
parent c70ad345ea
commit 7aa3ce55c0
16 changed files with 1489 additions and 141 deletions
+9 -3
View File
@@ -14,8 +14,10 @@ from fastapi import APIRouter, HTTPException, Query
from k1link.perception.threat_replay import (
THREAT_REPLAY_FRAME_SCHEMA,
THREAT_REPLAY_FRAME_SCHEMA_V2,
THREAT_REPLAY_RESULT_PREFIX,
THREAT_REPLAY_VISUAL_SCHEMA,
THREAT_REPLAY_VISUAL_SCHEMA_V2,
ThreatReplayError,
ThreatReplayResult,
read_threat_replay_result,
@@ -57,10 +59,11 @@ def build_m4_threat_replay_router(
items: list[dict[str, object]] = []
invalid_total = 0
for candidate in candidates:
if len(items) >= limit:
break
try:
frozen = result(candidate.name)
if len(items) < limit:
items.append(_project_result(frozen))
items.append(_project_result(frozen))
except HTTPException:
invalid_total += 1
return {
@@ -149,7 +152,8 @@ def _cached_video_overlay(
frames = []
for expected_sequence, row in enumerate(_iter_jsonl(root / "frames.jsonl")):
if (
row.get("schema_version") != THREAT_REPLAY_FRAME_SCHEMA
row.get("schema_version")
not in {THREAT_REPLAY_FRAME_SCHEMA, THREAT_REPLAY_FRAME_SCHEMA_V2}
or row.get("sequence") != expected_sequence
):
raise ValueError("M4.6 video frame order changed")
@@ -288,7 +292,9 @@ def _iter_jsonl(path: Path) -> Iterator[dict[str, object]]:
raise ValueError("M4.6 JSONL row is invalid")
if value.get("schema_version") not in {
THREAT_REPLAY_FRAME_SCHEMA,
THREAT_REPLAY_FRAME_SCHEMA_V2,
THREAT_REPLAY_VISUAL_SCHEMA,
THREAT_REPLAY_VISUAL_SCHEMA_V2,
}:
raise ValueError("M4.6 JSONL schema is invalid")
yield value