Skip to content

Protocols

protocols

Protocols for the results extension.

Classes

ResultProtocol

Bases: Protocol

Protocol for a single logical persisted result series.

Functions
to_record_payload
to_record_payload(analysis_id)

Serialize the result to a Django-compatible payload.

Source code in src/owi/metadatabase/results/protocols.py
def to_record_payload(self, analysis_id: int) -> dict[str, Any]:
    """Serialize the result to a Django-compatible payload."""

PlotStrategyProtocol

Bases: Protocol

Protocol for chart rendering strategies.

Functions
render
render(data, request)

Render a chart from normalized analysis data.

Source code in src/owi/metadatabase/results/protocols.py
def render(self, data: pd.DataFrame, request: PlotRequest) -> PlotResponse:
    """Render a chart from normalized analysis data."""

AnalysisProtocol

Bases: Protocol

Protocol for executable analyses.

Functions
validate_inputs
validate_inputs(payload)

Validate an analysis payload.

Source code in src/owi/metadatabase/results/protocols.py
def validate_inputs(self, payload: Any) -> Any:
    """Validate an analysis payload."""
compute
compute(payload)

Compute or normalize analysis input data.

Source code in src/owi/metadatabase/results/protocols.py
def compute(self, payload: Any) -> pd.DataFrame:
    """Compute or normalize analysis input data."""
to_results
to_results(payload)

Convert a validated payload into persisted result objects.

Source code in src/owi/metadatabase/results/protocols.py
def to_results(self, payload: Any) -> list[ResultSeries]:
    """Convert a validated payload into persisted result objects."""
from_results
from_results(results)

Reconstruct normalized analysis data from persisted results.

Source code in src/owi/metadatabase/results/protocols.py
def from_results(self, results: Sequence[ResultSeries]) -> pd.DataFrame:
    """Reconstruct normalized analysis data from persisted results."""
plot
plot(results, request=None, plot_strategy=None)

Plot reconstructed results using the default or injected strategy.

Source code in src/owi/metadatabase/results/protocols.py
def plot(
    self,
    results: Sequence[ResultSeries],
    request: PlotRequest | None = None,
    plot_strategy: PlotStrategyProtocol | None = None,
) -> PlotResponse:
    """Plot reconstructed results using the default or injected strategy."""

SerializerProtocol

Bases: Protocol

Protocol for domain-to-backend serializers.

Functions
to_payload
to_payload(obj)

Serialize a validated domain object.

Source code in src/owi/metadatabase/results/protocols.py
def to_payload(self, obj: Any) -> dict[str, Any]:
    """Serialize a validated domain object."""
from_mapping
from_mapping(mapping)

Deserialize a mapping into a validated domain object.

Source code in src/owi/metadatabase/results/protocols.py
def from_mapping(self, mapping: Mapping[str, Any]) -> Any:
    """Deserialize a mapping into a validated domain object."""

AnalysisRegistryProtocol

Bases: Protocol

Protocol for analysis registration and resolution.

Functions
register
register(analysis_type)

Register an analysis implementation.

Source code in src/owi/metadatabase/results/protocols.py
def register(self, analysis_type: type[AnalysisProtocol]) -> type[AnalysisProtocol]:
    """Register an analysis implementation."""
get
get(analysis_name)

Return an analysis instance by name.

Source code in src/owi/metadatabase/results/protocols.py
def get(self, analysis_name: str) -> AnalysisProtocol:
    """Return an analysis instance by name."""
names
names()

Return the registered analysis names.

Source code in src/owi/metadatabase/results/protocols.py
def names(self) -> list[str]:
    """Return the registered analysis names."""

ResultsRepositoryProtocol

Bases: Protocol

Protocol for raw result persistence and retrieval.

Functions
list_analyses
list_analyses(name=None, **kwargs)

Retrieve analysis rows from the backend.

Source code in src/owi/metadatabase/results/protocols.py
def list_analyses(self, name: str | None = None, **kwargs: Any) -> pd.DataFrame:
    """Retrieve analysis rows from the backend."""
list_results
list_results(query)

Retrieve raw rows from the backend.

Source code in src/owi/metadatabase/results/protocols.py
def list_results(self, query: ResultQuery) -> pd.DataFrame:
    """Retrieve raw rows from the backend."""
create_analysis
create_analysis(payload)

Create an analysis record.

Source code in src/owi/metadatabase/results/protocols.py
def create_analysis(self, payload: Mapping[str, Any]) -> Mapping[str, Any]:
    """Create an analysis record."""
create_result
create_result(payload)

Create a single result record.

Source code in src/owi/metadatabase/results/protocols.py
def create_result(self, payload: Mapping[str, Any]) -> Mapping[str, Any]:
    """Create a single result record."""
create_results_bulk
create_results_bulk(payloads)

Create multiple result records.

Source code in src/owi/metadatabase/results/protocols.py
def create_results_bulk(self, payloads: Sequence[Mapping[str, Any]]) -> Mapping[str, Any]:
    """Create multiple result records."""
create_or_update_results_bulk
create_or_update_results_bulk(payloads)

Create missing result records and patch existing ones.

Source code in src/owi/metadatabase/results/protocols.py
def create_or_update_results_bulk(self, payloads: Sequence[Mapping[str, Any]]) -> Mapping[str, Any]:
    """Create missing result records and patch existing ones."""
update_result
update_result(result_id, payload)

Patch a single result record.

Source code in src/owi/metadatabase/results/protocols.py
def update_result(self, result_id: int, payload: Mapping[str, Any]) -> Mapping[str, Any]:
    """Patch a single result record."""
get_location_frame
get_location_frame(location_ids)

Return location metadata required by geo-oriented workflows.

Source code in src/owi/metadatabase/results/protocols.py
def get_location_frame(self, location_ids: Sequence[int]) -> pd.DataFrame:
    """Return location metadata required by geo-oriented workflows."""

QueryServiceProtocol

Bases: Protocol

Protocol for high-level result retrieval and plotting.

Functions
deserialize_result_series
deserialize_result_series(raw_data)

Deserialize raw backend rows into typed result series.

Source code in src/owi/metadatabase/results/protocols.py
def deserialize_result_series(
    self,
    raw_data: Sequence[Mapping[str, Any]] | pd.DataFrame,
) -> list[ResultSeries]:
    """Deserialize raw backend rows into typed result series."""
get_result_series
get_result_series(analysis_name, filters=None)

Return typed persisted series for an analysis.

Source code in src/owi/metadatabase/results/protocols.py
def get_result_series(
    self,
    analysis_name: str,
    filters: ResultQuery | Mapping[str, Any] | None = None,
) -> list[ResultSeries]:
    """Return typed persisted series for an analysis."""
get_location_frame
get_location_frame(location_ids)

Return location metadata required by geo-oriented workflows.

Source code in src/owi/metadatabase/results/protocols.py
def get_location_frame(self, location_ids: Sequence[int]) -> pd.DataFrame:
    """Return location metadata required by geo-oriented workflows."""
get_results
get_results(analysis_name, filters=None)

Return normalized analysis data.

Source code in src/owi/metadatabase/results/protocols.py
def get_results(self, analysis_name: str, filters: ResultQuery | Mapping[str, Any] | None = None) -> pd.DataFrame:
    """Return normalized analysis data."""
plot_results
plot_results(
    analysis_name, filters=None, *, plot_type=None
)

Return a chart for normalized analysis data.

Source code in src/owi/metadatabase/results/protocols.py
def plot_results(
    self,
    analysis_name: str,
    filters: ResultQuery | Mapping[str, Any] | None = None,
    *,
    plot_type: str | None = None,
) -> PlotResponse:
    """Return a chart for normalized analysis data."""