src.dackar.RCA.cmms_integration.cmms_adapter

cmms_adapter — CMMSContextAdapter Protocol, NoOpCMMSAdapter, MockCMMSAdapter.

Concrete live adapters (MaximoCMMSAdapter, SAPPMCMMSAdapter) live in separate files and implement the same Protocol. See CMMS_INTEGRATION_GUIDE.md for the implementation skeleton.

Attributes

JsonDict

_STATUS_OPEN

_STATUS_CLOSED

_STATUS_CANCELLED

Classes

CMMSContextAdapter

Protocol for live CMMS data adapters.

NoOpCMMSAdapter

Silently returns empty CR and WO lists.

MockCMMSAdapter

Returns configurable fixture CR and WO records.

Functions

normalize_cmms_status(raw_status)

Map a raw CMMS status code to the cmms_context schema enum.

Module Contents

src.dackar.RCA.cmms_integration.cmms_adapter.JsonDict[source]
src.dackar.RCA.cmms_integration.cmms_adapter._STATUS_OPEN[source]
src.dackar.RCA.cmms_integration.cmms_adapter._STATUS_CLOSED[source]
src.dackar.RCA.cmms_integration.cmms_adapter._STATUS_CANCELLED[source]
src.dackar.RCA.cmms_integration.cmms_adapter.normalize_cmms_status(raw_status)[source]

Map a raw CMMS status code to the cmms_context schema enum.

Recognizes every documented Maximo and SAP PM code plus the already- normalized values; any unrecognized or empty value maps to "unknown" so the artifact never carries a status outside schemas/cmms_context.json (status enum: open / closed / cancelled / unknown).

Parameters:

raw_status (Any)

Return type:

str

class src.dackar.RCA.cmms_integration.cmms_adapter.CMMSContextAdapter[source]

Bases: Protocol

Protocol for live CMMS data adapters.

Implementations must be read-only with respect to the CMMS — no writes. Results should be idempotent for the same (asset_id, lookback window) inputs: calling fetch() twice with the same arguments must return the same records (within CMMS data consistency guarantees).

fetch(primary_asset_id, sister_component_ids, lookback_from, lookback_to, event)[source]

Fetch CR and WO records from the CMMS.

Parameters:
  • primary_asset_id (str) – Asset ID of the event asset. Used as the primary query scope.

  • sister_component_ids (List[str]) – KG component IDs of sister equipment (same_train / adjacent). These are opaque KG identifiers; a live adapter must resolve them to CMMS FLOCs / equipment IDs (via the maximo_floc / sap_equipment_id KG properties, the same lookup CAPExportSerializer uses) before querying. This Protocol passes only the IDs, so an adapter that needs the mapping must be constructed with its own KG/FLOC resolver (or a site config table). Threading a schema-shaped query scope (component ID + FLOC + equipment ID) or a KG resolver through fetch() itself is a planned contract enhancement, deferred to the live-adapter / injection MR — see CMMS_INTEGRATION_GUIDE.md §4.

  • lookback_from (str) – ISO-8601 UTC timestamp — start of the query window (inclusive). Derived from the last PM date on the primary asset, or the event_time minus the configured fallback window.

  • lookback_to (str) – ISO-8601 UTC timestamp — end of the query window (inclusive). Typically the event timestamp.

  • event (JsonDict) – The raw event dict, passed for adapter-specific context (e.g., failure mode keywords for full-text search).

Returns:

Must contain at minimum: {"cr_records": [...], "wo_records": [...]} Each record should include at least: an ID field, status, short_description, created_date, and is_sister_equipment.

Return type:

dict

class src.dackar.RCA.cmms_integration.cmms_adapter.NoOpCMMSAdapter[source]

Silently returns empty CR and WO lists.

Used in unit tests, CI, and deployments where no CMMS connection is available. Makes no network calls and has no external dependencies.

fetch(primary_asset_id, sister_component_ids, lookback_from, lookback_to, event)[source]
Parameters:
  • primary_asset_id (str)

  • sister_component_ids (List[str])

  • lookback_from (str)

  • lookback_to (str)

  • event (JsonDict)

Return type:

JsonDict

class src.dackar.RCA.cmms_integration.cmms_adapter.MockCMMSAdapter(cr_records=None, wo_records=None, filter_by_asset=False)[source]

Returns configurable fixture CR and WO records.

Designed for unit testing CMMSContextBuilder and the synthesizer prompt without a live CMMS connection.

Parameters:
  • cr_records (Optional[List[JsonDict]]) – List of CR record dicts to return from fetch(). Each dict should follow the cmms_context.json schema cr_records item structure (minus derived fields that CMMSContextBuilder computes: days_before_event, component_id).

  • wo_records (Optional[List[JsonDict]]) – List of WO record dicts to return from fetch().

  • filter_by_asset (bool) – If True, only records whose functional_location or equipment_id contains primary_asset_id (case-insensitive substring) are returned for the primary scope; all others are treated as sister records. Defaults to False (all records returned regardless of asset).

_cr_records = [][source]
_wo_records = [][source]
_filter_by_asset = False[source]
fetch(primary_asset_id, sister_component_ids, lookback_from, lookback_to, event)[source]
Parameters:
  • primary_asset_id (str)

  • sister_component_ids (List[str])

  • lookback_from (str)

  • lookback_to (str)

  • event (JsonDict)

Return type:

JsonDict

static _scope(record, primary_asset_id)[source]

Return a copy of record with is_sister_equipment set by a case-insensitive substring match of primary_asset_id against the record’s functional_location / equipment_id.

Parameters:
  • record (JsonDict)

  • primary_asset_id (str)

Return type:

JsonDict