feat(observatory): add portable calculation profiles
This commit is contained in:
@@ -12,8 +12,11 @@ import json
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path, PurePosixPath
|
||||
from typing import Any, Final, Literal
|
||||
from typing import Any, Final, Literal, cast
|
||||
|
||||
from k1link.observatory.canonical_result import (
|
||||
is_admitted_observatory_recorded_result,
|
||||
)
|
||||
from k1link.sessions.models import SessionSummary
|
||||
|
||||
LABORATORY_SETUP_REGISTRY_SCHEMA: Final = (
|
||||
@@ -22,6 +25,9 @@ LABORATORY_SETUP_REGISTRY_SCHEMA: Final = (
|
||||
LABORATORY_SETUP_CATALOG_SCHEMA: Final = (
|
||||
"missioncore.observatory-laboratory-setup-catalog/v1"
|
||||
)
|
||||
OBSERVATORY_CALCULATION_PROFILE_SCHEMA: Final = (
|
||||
"missioncore.observatory-calculation-profile/v1"
|
||||
)
|
||||
_MAX_REGISTRY_BYTES: Final = 256 * 1024
|
||||
_MAX_CONFIGURATION_BYTES: Final = 4 * 1024 * 1024
|
||||
_IDENTIFIER: Final = re.compile(r"^[a-z][a-z0-9-]{2,95}$")
|
||||
@@ -282,6 +288,42 @@ class LaboratorySetupRegistry:
|
||||
return result.result_kind
|
||||
return None
|
||||
|
||||
def observatory_calculation_profile(
|
||||
self,
|
||||
summary: SessionSummary,
|
||||
) -> dict[str, object] | None:
|
||||
"""Project an exact preserved legacy profile without inferring identity."""
|
||||
|
||||
for setup in self.setups:
|
||||
for result in setup.preserved_results:
|
||||
if (
|
||||
result.access != "observatory"
|
||||
or result.result_id != summary.session_id
|
||||
):
|
||||
continue
|
||||
if (
|
||||
setup.origin != "existing-result"
|
||||
or setup.run_definition is not None
|
||||
):
|
||||
return None
|
||||
if not is_admitted_observatory_recorded_result(
|
||||
summary,
|
||||
expected_result_id=result.result_id,
|
||||
expected_source_session_id=setup.source_session_id,
|
||||
expected_result_kind=result.result_kind,
|
||||
):
|
||||
return None
|
||||
return {
|
||||
"schema_version": OBSERVATORY_CALCULATION_PROFILE_SCHEMA,
|
||||
"setup_id": setup.setup_id,
|
||||
"display_name": setup.display_name,
|
||||
"origin": setup.origin,
|
||||
"definition_id": None,
|
||||
"definition_version": None,
|
||||
"definition_sha256": None,
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
def _setup(value: object, *, repository_root: Path) -> LaboratorySetup:
|
||||
row = _object(value, "setup")
|
||||
@@ -330,7 +372,7 @@ def _setup(value: object, *, repository_root: Path) -> LaboratorySetup:
|
||||
setup_id=_identifier(row["setup_id"], "setup_id"),
|
||||
display_name=_text(row["display_name"], "display_name"),
|
||||
description=_text(row["description"], "description"),
|
||||
origin=origin,
|
||||
origin=cast(SetupOrigin, origin),
|
||||
source_session_id=_text(source["session_id"], "source session_id"),
|
||||
source_label=_text(source["label"], "source label"),
|
||||
required_modalities=modalities,
|
||||
@@ -427,7 +469,7 @@ def _preserved_result(value: object) -> _PreservedResult:
|
||||
result_id=result_id,
|
||||
result_kind=_identifier(row["result_kind"], "result_kind"),
|
||||
relation=_identifier(row["relation"], "result relation"),
|
||||
access=access,
|
||||
access=cast(ResultAccess, access),
|
||||
created_at_utc=_text(row["created_at_utc"], "created_at_utc"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user