# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-persist-interpolation-assumptions-when-sampling-missing-telemetry-data.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-persist-interpolation-assumptions-when-sampling-missing-telemetry-data.warrant.json # Markdown SHA-256: f4fa1505d16dd768bc5fea89106513b15a43c92a6cc021cf094ce901211e4976 # Code AST SHA-256: b7b63218b250368782d0d01ee408e6cdbdaf54deed0240074dd72604b13a8e9d # Verified Classes: ObservationType, InterpolationVerdict, TelemetryPoint, InterpolationPolicy, InterpolationManifest, TelemetryInterpolationGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class ObservationType(Enum): EMPIRICAL = auto() IMPUTED = auto() UNKNOWN = auto() class InterpolationVerdict(Enum): ACCEPT_EMPIRICAL = auto() ACCEPT_IMPUTED_BOUNDED = auto() REJECT_UNBOUNDED_GAP = auto() @dataclass(frozen=True) class TelemetryPoint: timestamp: float value: float | None gap_size_sec: float observation_type: ObservationType @dataclass(frozen=True) class InterpolationPolicy: max_gap_tolerance_sec: float require_bounds: bool @dataclass(frozen=True) class InterpolationManifest: verdict: InterpolationVerdict confidence_interval: tuple[float, float] | None directive: str manifest_digest: str class TelemetryInterpolationGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_point( cls, point: TelemetryPoint, policy: InterpolationPolicy ) -> InterpolationManifest: # Gate 1: Empirical data if point.observation_type is ObservationType.EMPIRICAL and point.value is not None: digest = cls._hash(json.dumps({ "timestamp": f"{point.timestamp:.3f}", "value": f"{point.value:.6f}", "type": "EMPIRICAL" }, sort_keys=True)) return InterpolationManifest( verdict=InterpolationVerdict.ACCEPT_EMPIRICAL, confidence_interval=None, directive="PROCEED: Empirical observation accepted.", manifest_digest=digest ) # Gate 2: Gap size check if point.gap_size_sec > policy.max_gap_tolerance_sec: return InterpolationManifest( verdict=InterpolationVerdict.REJECT_UNBOUNDED_GAP, confidence_interval=None, directive=f"HALT: Gap {point.gap_size_sec:.1f}s exceeds tolerance {policy.max_gap_tolerance_sec:.1f}s. Mark UNKNOWN.", manifest_digest=cls._hash(f"GAP:{point.gap_size_sec:.1f}") ) # Gate 3: Imputation bounds if point.observation_type is ObservationType.IMPUTED: if policy.require_bounds and point.value is None: return InterpolationManifest( verdict=InterpolationVerdict.REJECT_UNBOUNDED_GAP, confidence_interval=None, directive="HALT: Imputed point lacks bounds. Policy requires bounds.", manifest_digest=cls._hash("NO_BOUNDS") ) # Example bounds generation (in production, compute from interpolation algorithm) if point.value is not None: bound_width = point.value * 0.05 # 5% error bound ci = (point.value - bound_width, point.value + bound_width) digest = cls._hash(json.dumps({ "timestamp": f"{point.timestamp:.3f}", "value": f"{point.value:.6f}", "type": "IMPUTED", "bounds": f"{ci[0]:.6f},{ci[1]:.6f}" }, sort_keys=True)) return InterpolationManifest( verdict=InterpolationVerdict.ACCEPT_IMPUTED_BOUNDED, confidence_interval=ci, directive=f"PROCEED: Imputed value {point.value:.2f} with bounds ±{bound_width:.2f}.", manifest_digest=digest ) # Gate 4: Unknown return InterpolationManifest( verdict=InterpolationVerdict.REJECT_UNBOUNDED_GAP, confidence_interval=None, directive="HALT: Point cannot be classified as empirical or bounded imputed.", manifest_digest=cls._hash("UNKNOWN") )