Skip to content

latent.stats.sop

Phase/SOP compliance scoring (FR-5.2).

Classes

SOPDefinition

SOPDefinition()

Definition of a Standard Operating Procedure as phases with ordering.

SOPPhase

SOPPhase()

A single phase in a Standard Operating Procedure.

Functions

phase_completion_score

phase_completion_score(actual_phases: list[str], sop: SOPDefinition) -> MetricResult

Score the percentage of required SOP phases that were completed.

Each required phase contributes its weight to the total. The score is the sum of weights for completed required phases divided by the total weight of all required phases.

Args: actual_phases: List of phase names actually executed. sop: The SOP definition.

Returns: MetricResult with point_estimate in [0, 1].

sequence_compliance

sequence_compliance(actual_phases: list[str], sop: SOPDefinition) -> MetricResult

Score how well the actual phase sequence follows the SOP ordering.

Computes edit distance between the actual sequence and all valid topological orderings of the SOP DAG, taking the minimum. The score is normalised as 1 - (edit_distance / max_distance).

Args: actual_phases: List of phase names in execution order. sop: The SOP definition (phases may have prerequisites).

Returns: MetricResult with point_estimate in [0, 1].