feat(lab): publish E31 through E33 results
This commit is contained in:
@@ -0,0 +1,366 @@
|
||||
export interface E31LaboratoryResult {
|
||||
resultId: string;
|
||||
createdAtUtc: string | null;
|
||||
sourceSessionId: string;
|
||||
status: "accepted-diagnostic-source-profile";
|
||||
eligibleForE32: true;
|
||||
profileId: string;
|
||||
producerSha256: string;
|
||||
metrics: {
|
||||
frameCount: number;
|
||||
availableBindingCount: number;
|
||||
availableFraction: number;
|
||||
lidarCameraP95Ms: number;
|
||||
posePointP95Ms: number;
|
||||
selectedOffsetMs: number;
|
||||
correspondenceCount: number;
|
||||
supportedFraction: number;
|
||||
semanticSelfSampleCount: number;
|
||||
semanticSelfCollateralCount: number;
|
||||
exactGeometryCorrectionCount: number;
|
||||
geometryPointMaskStatus: string;
|
||||
};
|
||||
limitations: readonly string[];
|
||||
access: "read-only";
|
||||
}
|
||||
|
||||
export interface E32LaboratoryResult {
|
||||
resultId: string;
|
||||
createdAtUtc: string | null;
|
||||
sourceSessionId: string;
|
||||
status: "accepted-diagnostic-track-geometry-replay";
|
||||
profileId: string;
|
||||
producerSha256: string;
|
||||
e31ResultId: string;
|
||||
metrics: {
|
||||
framesTotal: number;
|
||||
framesSourceAvailable: number;
|
||||
semanticPublished: number;
|
||||
semanticMasked: number;
|
||||
geometryPublished: number;
|
||||
observationsArbitrated: number;
|
||||
overlappingClaimsRemoved: number;
|
||||
qualifiedPointsPublished: number;
|
||||
qualifiedPointsWithheld: number;
|
||||
frameProcessingP95Ms: number;
|
||||
buildElapsedMs: number;
|
||||
};
|
||||
access: "read-only";
|
||||
}
|
||||
|
||||
export interface E33LaboratoryResult {
|
||||
resultId: string;
|
||||
createdAtUtc: string | null;
|
||||
sourceSessionId: string;
|
||||
status: "accepted-recorded-source-paced-shadow";
|
||||
e32ResultId: string;
|
||||
pipelineId: string;
|
||||
mode: string;
|
||||
worker: {
|
||||
node: string;
|
||||
containerImage: string;
|
||||
python: string;
|
||||
numpy: string;
|
||||
};
|
||||
metrics: {
|
||||
sourceFrames: number;
|
||||
deliveredFrames: number;
|
||||
inputSuperseded: number;
|
||||
resultSuperseded: number;
|
||||
effectiveDeliveryFps: number;
|
||||
deadlineMissFraction: number;
|
||||
processingP95Ms: number;
|
||||
releaseLagP95Ms: number;
|
||||
resultAgeP95Ms: number;
|
||||
processRssP95Mib: number;
|
||||
gpuUtilizationP95Percent: number;
|
||||
gpuVisible: boolean;
|
||||
workQueueCapacity: number;
|
||||
resultQueueCapacity: number;
|
||||
wallToIdealRatio: number;
|
||||
};
|
||||
access: "read-only";
|
||||
}
|
||||
|
||||
export interface AdvancedLaboratoryResults {
|
||||
e31: E31LaboratoryResult | null;
|
||||
e32: E32LaboratoryResult | null;
|
||||
e33: E33LaboratoryResult | null;
|
||||
}
|
||||
|
||||
export class AdvancedLaboratoryContractError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "AdvancedLaboratoryContractError";
|
||||
}
|
||||
}
|
||||
|
||||
type LaboratoryFetch = (
|
||||
input: RequestInfo | URL,
|
||||
init?: RequestInit,
|
||||
) => Promise<Response>;
|
||||
|
||||
function record(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидался объект.`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function stringValue(value: unknown, label: string): string {
|
||||
if (typeof value !== "string" || !value.trim()) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидалась строка.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function optionalString(value: unknown, label: string): string | null {
|
||||
return value === null ? null : stringValue(value, label);
|
||||
}
|
||||
|
||||
function numberValue(value: unknown, label: string): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидалось число.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function integerValue(value: unknown, label: string): number {
|
||||
const parsed = numberValue(value, label);
|
||||
if (!Number.isSafeInteger(parsed)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидалось целое число.`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function booleanValue(value: unknown, label: string): boolean {
|
||||
if (typeof value !== "boolean") {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидался boolean.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function trueValue(value: unknown, label: string): true {
|
||||
if (value !== true) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидалось true.`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function finiteNumber(value: unknown, label: string): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидалось число.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function exactString<T extends string>(
|
||||
value: unknown,
|
||||
expected: T,
|
||||
label: string,
|
||||
): T {
|
||||
if (value !== expected) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: неверное значение.`);
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
|
||||
function strings(value: unknown, label: string): readonly string[] {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: ожидался массив.`);
|
||||
}
|
||||
return value.map((item, index) => stringValue(item, `${label}[${index}]`));
|
||||
}
|
||||
|
||||
function contentId(value: unknown, prefix: string, label: string): string {
|
||||
const parsed = stringValue(value, label);
|
||||
if (!new RegExp(`^${prefix}-[a-f0-9]{64}$`).test(parsed)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: неверный content id.`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function sha256(value: unknown, label: string): string {
|
||||
const parsed = stringValue(value, label);
|
||||
if (!/^[a-f0-9]{64}$/.test(parsed)) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: неверный SHA-256.`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function diagnosticAuthority(value: unknown, label: string): void {
|
||||
const authority = record(value, label);
|
||||
if (
|
||||
authority.commands_enabled !== false
|
||||
|| authority.navigation_or_safety_accepted !== false
|
||||
) {
|
||||
throw new AdvancedLaboratoryContractError(`${label}: запрещённые полномочия.`);
|
||||
}
|
||||
}
|
||||
|
||||
function parseCatalog<T>(
|
||||
payload: unknown,
|
||||
parseItem: (value: unknown) => T,
|
||||
): T | null {
|
||||
const value = record(payload, "Каталог LAB");
|
||||
exactString(
|
||||
value.schema_version,
|
||||
"missioncore.laboratory-advanced-catalog/v1",
|
||||
"Каталог LAB.schema_version",
|
||||
);
|
||||
booleanValue(value.configured, "Каталог LAB.configured");
|
||||
integerValue(value.candidate_total, "Каталог LAB.candidate_total");
|
||||
integerValue(value.invalid_total, "Каталог LAB.invalid_total");
|
||||
exactString(value.access, "read-only", "Каталог LAB.access");
|
||||
if (!Array.isArray(value.items)) {
|
||||
throw new AdvancedLaboratoryContractError("Каталог LAB.items: ожидался массив.");
|
||||
}
|
||||
if (value.items.length > 1) {
|
||||
throw new AdvancedLaboratoryContractError("Каталог LAB.items: нарушен limit=1.");
|
||||
}
|
||||
return value.items.length ? parseItem(value.items[0]) : null;
|
||||
}
|
||||
|
||||
function parseE31(value: unknown): E31LaboratoryResult {
|
||||
const item = record(value, "E31");
|
||||
const metrics = record(item.metrics, "E31.metrics");
|
||||
diagnosticAuthority(item.authority, "E31.authority");
|
||||
return {
|
||||
resultId: contentId(item.result_id, "e31-source-qualification", "E31.result_id"),
|
||||
createdAtUtc: optionalString(item.created_at_utc, "E31.created_at_utc"),
|
||||
sourceSessionId: stringValue(item.source_session_id, "E31.source_session_id"),
|
||||
status: exactString(
|
||||
item.status,
|
||||
"accepted-diagnostic-source-profile",
|
||||
"E31.status",
|
||||
),
|
||||
eligibleForE32: trueValue(item.eligible_for_e32, "E31.eligible_for_e32"),
|
||||
profileId: stringValue(item.profile_id, "E31.profile_id"),
|
||||
producerSha256: sha256(item.producer_sha256, "E31.producer_sha256"),
|
||||
metrics: {
|
||||
frameCount: integerValue(metrics.frame_count, "E31.metrics.frame_count"),
|
||||
availableBindingCount: integerValue(metrics.available_binding_count, "E31.metrics.available_binding_count"),
|
||||
availableFraction: numberValue(metrics.available_fraction, "E31.metrics.available_fraction"),
|
||||
lidarCameraP95Ms: numberValue(metrics.lidar_camera_p95_ms, "E31.metrics.lidar_camera_p95_ms"),
|
||||
posePointP95Ms: numberValue(metrics.pose_point_p95_ms, "E31.metrics.pose_point_p95_ms"),
|
||||
selectedOffsetMs: finiteNumber(metrics.selected_offset_ms, "E31.metrics.selected_offset_ms"),
|
||||
correspondenceCount: integerValue(metrics.correspondence_count, "E31.metrics.correspondence_count"),
|
||||
supportedFraction: numberValue(metrics.supported_fraction, "E31.metrics.supported_fraction"),
|
||||
semanticSelfSampleCount: integerValue(metrics.semantic_self_sample_count, "E31.metrics.semantic_self_sample_count"),
|
||||
semanticSelfCollateralCount: integerValue(metrics.semantic_self_collateral_count, "E31.metrics.semantic_self_collateral_count"),
|
||||
exactGeometryCorrectionCount: integerValue(metrics.exact_geometry_correction_count, "E31.metrics.exact_geometry_correction_count"),
|
||||
geometryPointMaskStatus: stringValue(metrics.geometry_point_mask_status, "E31.metrics.geometry_point_mask_status"),
|
||||
},
|
||||
limitations: strings(item.limitations, "E31.limitations"),
|
||||
access: exactString(item.access, "read-only", "E31.access"),
|
||||
};
|
||||
}
|
||||
|
||||
function parseE32(value: unknown): E32LaboratoryResult {
|
||||
const item = record(value, "E32");
|
||||
const metrics = record(item.metrics, "E32.metrics");
|
||||
diagnosticAuthority(item.authority, "E32.authority");
|
||||
return {
|
||||
resultId: contentId(item.result_id, "e32-track-geometry", "E32.result_id"),
|
||||
createdAtUtc: optionalString(item.created_at_utc, "E32.created_at_utc"),
|
||||
sourceSessionId: stringValue(item.source_session_id, "E32.source_session_id"),
|
||||
status: exactString(
|
||||
item.status,
|
||||
"accepted-diagnostic-track-geometry-replay",
|
||||
"E32.status",
|
||||
),
|
||||
profileId: stringValue(item.profile_id, "E32.profile_id"),
|
||||
producerSha256: sha256(item.producer_sha256, "E32.producer_sha256"),
|
||||
e31ResultId: contentId(item.e31_result_id, "e31-source-qualification", "E32.e31_result_id"),
|
||||
metrics: {
|
||||
framesTotal: integerValue(metrics.frames_total, "E32.metrics.frames_total"),
|
||||
framesSourceAvailable: integerValue(metrics.frames_source_available, "E32.metrics.frames_source_available"),
|
||||
semanticPublished: integerValue(metrics.semantic_published, "E32.metrics.semantic_published"),
|
||||
semanticMasked: integerValue(metrics.semantic_masked, "E32.metrics.semantic_masked"),
|
||||
geometryPublished: integerValue(metrics.geometry_published, "E32.metrics.geometry_published"),
|
||||
observationsArbitrated: integerValue(metrics.observations_arbitrated, "E32.metrics.observations_arbitrated"),
|
||||
overlappingClaimsRemoved: integerValue(metrics.overlapping_claims_removed, "E32.metrics.overlapping_claims_removed"),
|
||||
qualifiedPointsPublished: integerValue(metrics.qualified_points_published, "E32.metrics.qualified_points_published"),
|
||||
qualifiedPointsWithheld: integerValue(metrics.qualified_points_withheld, "E32.metrics.qualified_points_withheld"),
|
||||
frameProcessingP95Ms: numberValue(metrics.frame_processing_p95_ms, "E32.metrics.frame_processing_p95_ms"),
|
||||
buildElapsedMs: numberValue(metrics.build_elapsed_ms, "E32.metrics.build_elapsed_ms"),
|
||||
},
|
||||
access: exactString(item.access, "read-only", "E32.access"),
|
||||
};
|
||||
}
|
||||
|
||||
function parseE33(value: unknown): E33LaboratoryResult {
|
||||
const item = record(value, "E33");
|
||||
const worker = record(item.worker, "E33.worker");
|
||||
const metrics = record(item.metrics, "E33.metrics");
|
||||
diagnosticAuthority(item.authority, "E33.authority");
|
||||
return {
|
||||
resultId: contentId(item.result_id, "e33-worker-shadow", "E33.result_id"),
|
||||
createdAtUtc: optionalString(item.created_at_utc, "E33.created_at_utc"),
|
||||
sourceSessionId: stringValue(item.source_session_id, "E33.source_session_id"),
|
||||
status: exactString(
|
||||
item.status,
|
||||
"accepted-recorded-source-paced-shadow",
|
||||
"E33.status",
|
||||
),
|
||||
e32ResultId: contentId(item.e32_result_id, "e32-track-geometry", "E33.e32_result_id"),
|
||||
pipelineId: stringValue(item.pipeline_id, "E33.pipeline_id"),
|
||||
mode: stringValue(item.mode, "E33.mode"),
|
||||
worker: {
|
||||
node: stringValue(worker.node, "E33.worker.node"),
|
||||
containerImage: stringValue(worker.container_image, "E33.worker.container_image"),
|
||||
python: stringValue(worker.python, "E33.worker.python"),
|
||||
numpy: stringValue(worker.numpy, "E33.worker.numpy"),
|
||||
},
|
||||
metrics: {
|
||||
sourceFrames: integerValue(metrics.source_frames, "E33.metrics.source_frames"),
|
||||
deliveredFrames: integerValue(metrics.delivered_frames, "E33.metrics.delivered_frames"),
|
||||
inputSuperseded: integerValue(metrics.input_superseded, "E33.metrics.input_superseded"),
|
||||
resultSuperseded: integerValue(metrics.result_superseded, "E33.metrics.result_superseded"),
|
||||
effectiveDeliveryFps: numberValue(metrics.effective_delivery_fps, "E33.metrics.effective_delivery_fps"),
|
||||
deadlineMissFraction: numberValue(metrics.deadline_miss_fraction, "E33.metrics.deadline_miss_fraction"),
|
||||
processingP95Ms: numberValue(metrics.processing_p95_ms, "E33.metrics.processing_p95_ms"),
|
||||
releaseLagP95Ms: numberValue(metrics.release_lag_p95_ms, "E33.metrics.release_lag_p95_ms"),
|
||||
resultAgeP95Ms: numberValue(metrics.result_age_p95_ms, "E33.metrics.result_age_p95_ms"),
|
||||
processRssP95Mib: numberValue(metrics.process_rss_p95_mib, "E33.metrics.process_rss_p95_mib"),
|
||||
gpuUtilizationP95Percent: numberValue(metrics.gpu_utilization_p95_percent, "E33.metrics.gpu_utilization_p95_percent"),
|
||||
gpuVisible: booleanValue(metrics.gpu_visible, "E33.metrics.gpu_visible"),
|
||||
workQueueCapacity: integerValue(metrics.work_queue_capacity, "E33.metrics.work_queue_capacity"),
|
||||
resultQueueCapacity: integerValue(metrics.result_queue_capacity, "E33.metrics.result_queue_capacity"),
|
||||
wallToIdealRatio: numberValue(metrics.wall_to_ideal_ratio, "E33.metrics.wall_to_ideal_ratio"),
|
||||
},
|
||||
access: exactString(item.access, "read-only", "E33.access"),
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchOne<T>(
|
||||
path: string,
|
||||
parser: (value: unknown) => T,
|
||||
fetcher: LaboratoryFetch,
|
||||
signal?: AbortSignal,
|
||||
): Promise<T | null> {
|
||||
const response = await fetcher(path, {
|
||||
method: "GET",
|
||||
headers: { Accept: "application/json" },
|
||||
signal,
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new AdvancedLaboratoryContractError(`Каталог LAB недоступен: HTTP ${response.status}.`);
|
||||
}
|
||||
return parseCatalog(await response.json(), parser);
|
||||
}
|
||||
|
||||
export async function fetchAdvancedLaboratoryResults({
|
||||
fetcher = fetch,
|
||||
signal,
|
||||
}: {
|
||||
fetcher?: LaboratoryFetch;
|
||||
signal?: AbortSignal;
|
||||
} = {}): Promise<AdvancedLaboratoryResults> {
|
||||
const [e31, e32, e33] = await Promise.all([
|
||||
fetchOne("/api/v1/laboratory/e31/results?limit=1", parseE31, fetcher, signal),
|
||||
fetchOne("/api/v1/laboratory/e32/results?limit=1", parseE32, fetcher, signal),
|
||||
fetchOne("/api/v1/laboratory/e33/results?limit=1", parseE33, fetcher, signal),
|
||||
]);
|
||||
return { e31, e32, e33 };
|
||||
}
|
||||
Reference in New Issue
Block a user