Добавление канонического графа M4.7
This commit is contained in:
@@ -12,8 +12,10 @@ from typing import Final
|
||||
from .contracts import LocalObstacleMap, ThreatAssessment
|
||||
|
||||
GRAPH_RESULT_SCHEMA: Final = "missioncore.reference-perception-graph-result/v1"
|
||||
GRAPH_RESULT_SCHEMA_V2: Final = "missioncore.reference-perception-graph-result/v2"
|
||||
TERMINAL_OUTCOME_SCHEMA: Final = "missioncore.perception-terminal-outcome/v1"
|
||||
REFERENCE_GRAPH_ID: Final = "reference-perception-graph/v1"
|
||||
REFERENCE_GRAPH_ID_V2: Final = "reference-perception-graph/v2"
|
||||
_SAFE_IDENTIFIER: Final = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$")
|
||||
|
||||
|
||||
@@ -31,6 +33,13 @@ class GraphState(StrEnum):
|
||||
FAILED = "failed"
|
||||
|
||||
|
||||
class GraphRunMode(StrEnum):
|
||||
"""Bounded queue behavior for realtime and deterministic replay."""
|
||||
|
||||
SOURCE_PACED_LATEST_WINS = "source-paced-latest-wins"
|
||||
LOSSLESS_REPLAY = "lossless-replay"
|
||||
|
||||
|
||||
class TerminalOutcomeType(StrEnum):
|
||||
DELIVERED = "delivered"
|
||||
SUPERSEDED = "superseded"
|
||||
@@ -110,6 +119,33 @@ class GraphRunResult:
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class GraphRunResultV2:
|
||||
graph_id: str
|
||||
source_profile_id: str
|
||||
run_mode: GraphRunMode
|
||||
state: GraphState
|
||||
admitted_count: int
|
||||
terminal_outcomes: tuple[TerminalOutcome, ...]
|
||||
deliveries: tuple[DeliveredFrame, ...]
|
||||
queue_high_watermarks: tuple[tuple[str, int], ...]
|
||||
canonical_payload_sha256: str
|
||||
|
||||
def to_dict(self) -> dict[str, object]:
|
||||
return {
|
||||
"schema_version": GRAPH_RESULT_SCHEMA_V2,
|
||||
"graph_id": self.graph_id,
|
||||
"source_profile_id": self.source_profile_id,
|
||||
"run_mode": self.run_mode.value,
|
||||
"state": self.state.value,
|
||||
"admitted_count": self.admitted_count,
|
||||
"terminal_outcomes": [item.to_dict() for item in self.terminal_outcomes],
|
||||
"deliveries": [item.canonical_dict() for item in self.deliveries],
|
||||
"queue_high_watermarks": dict(self.queue_high_watermarks),
|
||||
"canonical_payload_sha256": self.canonical_payload_sha256,
|
||||
}
|
||||
|
||||
|
||||
def build_graph_run_result(
|
||||
*,
|
||||
graph_id: str,
|
||||
@@ -137,15 +173,52 @@ def build_graph_run_result(
|
||||
)
|
||||
|
||||
|
||||
def build_graph_run_result_v2(
|
||||
*,
|
||||
graph_id: str,
|
||||
source_profile_id: str,
|
||||
run_mode: GraphRunMode,
|
||||
state: GraphState,
|
||||
admitted_count: int,
|
||||
outcomes: tuple[TerminalOutcome, ...],
|
||||
deliveries: tuple[DeliveredFrame, ...],
|
||||
queue_high_watermarks: tuple[tuple[str, int], ...],
|
||||
) -> GraphRunResultV2:
|
||||
canonical = {
|
||||
"graph_id": graph_id,
|
||||
"source_profile_id": source_profile_id,
|
||||
"run_mode": run_mode.value,
|
||||
"terminal_outcomes": [item.to_dict() for item in outcomes],
|
||||
"deliveries": [item.canonical_dict() for item in deliveries],
|
||||
}
|
||||
payload = json.dumps(canonical, sort_keys=True, separators=(",", ":")).encode()
|
||||
return GraphRunResultV2(
|
||||
graph_id=graph_id,
|
||||
source_profile_id=source_profile_id,
|
||||
run_mode=run_mode,
|
||||
state=state,
|
||||
admitted_count=admitted_count,
|
||||
terminal_outcomes=outcomes,
|
||||
deliveries=deliveries,
|
||||
queue_high_watermarks=queue_high_watermarks,
|
||||
canonical_payload_sha256=hashlib.sha256(payload).hexdigest(),
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"GRAPH_RESULT_SCHEMA",
|
||||
"GRAPH_RESULT_SCHEMA_V2",
|
||||
"REFERENCE_GRAPH_ID",
|
||||
"REFERENCE_GRAPH_ID_V2",
|
||||
"TERMINAL_OUTCOME_SCHEMA",
|
||||
"DeliveredFrame",
|
||||
"GraphExecutionError",
|
||||
"GraphRunResult",
|
||||
"GraphRunResultV2",
|
||||
"GraphRunMode",
|
||||
"GraphState",
|
||||
"TerminalOutcome",
|
||||
"TerminalOutcomeType",
|
||||
"build_graph_run_result",
|
||||
"build_graph_run_result_v2",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user