Source code for src.dackar.RCA.signal_evidence.models

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Optional

from orchestrators.temporal_relations import Interval


@dataclass
[docs] class AnomalyRecord: """A single flagged anomaly on one sensor over a time interval. Fields carry the sensor and (resolved) component ids, the anomaly window, a ``pattern`` label, a ``severity`` in ``[0, 1]``, the ``source`` that produced it (``"telemetry_summary"`` or ``"historian"``), and optional raw values / units. """
[docs] sensor_id: str
[docs] component_id: Optional[str]
[docs] timestamp_start: datetime
[docs] timestamp_end: datetime
[docs] pattern: str
[docs] severity: float
[docs] source: str
[docs] raw_value_start: Optional[float] = None
[docs] raw_value_peak: Optional[float] = None
[docs] units: Optional[str] = None
[docs] def to_interval(self) -> Interval: """Return this record's ``[start, end]`` as a temporal ``Interval``.""" return Interval(start=self.timestamp_start, end=self.timestamp_end)
@dataclass
[docs] class PropagationEdge: """A directed propagation edge between two anomalies (by list index). ``allen_rel`` captures the temporal relation between the two anomaly intervals and ``allen_score`` its raw event-calibrated relevance prior (kept for provenance). ``prop_score`` is the *propagation*-calibrated weight actually used to rank chains: it rewards a demonstrated causal lead at least as much as a co-temporal overlap and discounts co-temporal edges, so a clean ``precedes`` lead is never outranked by an ``overlaps`` edge the way the raw event score would (MR#49 review). ``edge_type`` is the KG relation (``containment`` / ``connectivity`` / ``mixed``), and ``onset_lag_h`` the onset lead in hours from source to target. """
[docs] from_idx: int
[docs] to_idx: int
[docs] allen_rel: str
[docs] allen_score: float
[docs] prop_score: float
[docs] edge_type: str
[docs] onset_lag_h: float
@dataclass
[docs] class NodeTopology: """In/out degree and derived pattern (linear/divergence/convergence/hub/isolated) for one anomaly node."""
[docs] anomaly_idx: int
[docs] in_degree: int
[docs] out_degree: int
[docs] pattern_type: str
@dataclass
[docs] class ScoredChain: """A scored propagation path plus the factors that produced its ``path_score``. ``path_score`` is driven by ``mean_propagation_score`` (the lead-time-aware edge weight); ``mean_allen_score`` is retained alongside as the mean of the raw event-calibrated relation priors, for provenance. """
[docs] chain_id: str
[docs] path: list[int]
[docs] path_score: float
[docs] topology_alignment_factor: float
[docs] lag_consistency_factor: float
[docs] mean_allen_score: float
[docs] mean_propagation_score: float
[docs] hub_boost: float
[docs] root_pattern_type: str
[docs] nodes: list[dict]