diff --git a/docs/AWB_FORMAT.md b/docs/AWB_FORMAT.md index 41329e83..f1b6b303 100644 --- a/docs/AWB_FORMAT.md +++ b/docs/AWB_FORMAT.md @@ -187,22 +187,26 @@ the `Id` label. |---:|---|---| | 0 | Exponential | `FmMttf` = mean time to failure | | 1 | Weibull | `FmEta1` = scale, `FmBeta1` = shape, `FmGamma1` = location | -| 2 | Bi-Weibull | three modes; RAPTOR keeps the first | -| 3 | Tri-Weibull | three modes; RAPTOR keeps the first | +| 2 | Bi-Weibull | two competing modes (mode-3 columns are an unused placeholder); RAPTOR moment-matches one Weibull | +| 3 | Tri-Weibull | three competing modes; RAPTOR moment-matches one Weibull | | 4 | Fixed | `FmMttf` = fixed time | | 5 | Lognormal | `FmMttf` = mean, `FmStd` = standard deviation | | 6 | Normal | `FmMttf` = mean, `FmStd` = standard deviation | | 7 | Buffer | stored capacity; no RAPTOR equivalent | -| 8 | Phased Bi-Weibull | phased; RAPTOR keeps the first mode | -| 9 | Phased Tri-Weibull | phased; RAPTOR keeps the first mode | +| 8 | Phased Bi-Weibull | phased; RAPTOR moment-matches the two modes | +| 9 | Phased Tri-Weibull | phased; RAPTOR moment-matches the three modes | All times in AWB are **hours**. RAPTOR converts from its model unit with `raptor/core/units_conv.py` (`days` = 24, `years` = 8760, etc.) and records the conversion in the summary. -RAPTOR reads the same enum in reverse. A multi-mode or buffer law becomes -its first Weibull mode and is listed under "multi-mode or buffer failure -distribution". A dormant AWB failure (`FmDormant = 1`) becomes a RAPTOR +RAPTOR reads the same enum in reverse. AWB's Weibull modes compete (the +item fails at the first of them), so a bi-/tri-Weibull law becomes one +Weibull with the same mean and coefficient of variation as the competing-risk +life, located at the earliest mode's location. This is an approximation: +failure counts agree, but the hazard shape, and so the effect of PM, is only +close. A buffer law becomes its first mode. Both are listed under +"multi-mode or buffer failure distribution". A dormant AWB failure (`FmDormant = 1`) becomes a RAPTOR block with no repair. A non-zero start-up failure probability is reported but cannot be modelled by RAPTOR. @@ -286,9 +290,11 @@ AWB field was written; the `.raptor.json` sidecar keeps the RAPTOR copy). | Feature | Why | |---|---| | consequences and cost models | RAPTOR has no financial/safety/environmental consequence model | -| inspection tasks | AWB inspections are not imported as RAPTOR PM | +| inspection tasks | a dormant failure with an enabled inspection uses the expected detection delay; other inspections remain partial | | extra planned tasks | RAPTOR has one PM per block; extra AWB tasks are not imported | | two-level spare holdings | AWB level-1 and level-2 stock are summed | +| spare supply chain | AWB level 3 never runs out: every RAPTOR pool emergency-orders after level 1 + 2 + 3 delays, and stocked pools reorder one-for-one after the level 3 + 2 delay | +| level-1 spare logistic delay on stocked spares | the per-draw level-1 delay on a spare taken from stock is not modelled | | spare repair shop | AWB spare repair/recycling is not imported | | labour call-out delay | AWB labour logistics delay is not imported | | phase capacity/load rules | only AWB phase logic/out-of-service rules are imported | @@ -300,7 +306,7 @@ AWB field was written; the `.raptor.json` sidecar keeps the RAPTOR copy). | standby and NOT logic | RAPTOR nodes have no equivalent | | block consequence links | not imported | | dormant failures | modelled as never repaired | -| multi-mode/buffer failure laws | only the first Weibull mode is kept | +| multi-mode/buffer failure laws | moment-matched to one Weibull (buffer: first mode) | | non-maintainable blocks | RAPTOR repair is off | | start-up failure probability | not modelled by RAPTOR | diff --git a/docs/AWB_VALIDATION.md b/docs/AWB_VALIDATION.md index f7890546..78c91705 100644 --- a/docs/AWB_VALIDATION.md +++ b/docs/AWB_VALIDATION.md @@ -140,6 +140,64 @@ losses: capacity is preserved in the sidecar, and the repair law is mean-matched for AWB. AWB demonstration mode may still refuse to analyse a project of this size; that is its object limit, not a file-format failure. +### Shipped AWB examples + +Stored AWB results vs RAPTOR on the imported model (100 trials, AWB's own +count; same lifetime). Measured 2026-11-20 with the junction-node fix from +`main` (#339) applied: without it every AWB fan-out is mis-wired. + +| AWB project | AWB Am | RAPTOR A | Result | +|---|---:|---:|---| +| OilAndGasExample | 0.9732 | 0.9747 | agrees (+0.15 pp) | +| SapDemo | 0.6293 | 0.6522 | agrees within the approximations (+2.3 pp) | +| Example1 | 0.0883 | 0.0959 | agrees within the approximations (+0.8 pp) | +| MaximoDemo | 0.6118 | 0.3654 | AWB's stored results look stale (below) | + +`ALTExample` and the `PumpExample` library example have no RBD blocks. + +Three import defects made Example1/SapDemo/MaximoDemo look "not +comparable" (≈0.5 % available) before this: + +* **Spare pools ran dry.** An AWB spare with no stock came in as a RAPTOR + pool with no ordering, so the first demand left the block `Done` + (`No_spares`). AWB level 3 is unlimited; pools now emergency-order after + the level 1+2+3 delay. +* **Planned tasks waited for spares.** AWB's spare logistic delays hold + up corrective actions only; imported PM no longer draws on the pool. +* **Bi-Weibull picked a placeholder mode.** The shortest-η rule included + the unused third-mode columns (8760 h). Multi-mode laws are now + moment-matched to the competing-risk life. + +The per-subsystem figures (top-level superblocks, each run on its own) agree +to within about 2 pp for Example1 and SapDemo. The dormant `PO` block, +modelled with the inspection detection-delay approximation, gives 0.682 vs +AWB 0.655 (SapDemo) and 0.183 vs 0.175 (Example1, inspection disabled, never +repaired). RAPTOR's outage counts run lower than AWB's `W` because AWB +counts zero-duration PM/inspection outages that RAPTOR does not. + +**MaximoDemo.** Its spares carry level-2/3 delays of 96 h and 480 h, like +Example1's, but AWB's stored per-block spare downtime is only about the +level-1 delay (for example 45 h over 1.5 demands for the drive shaft), and its +subsystem results are almost identical to SapDemo's, which has no level-2/3 +delays. RAPTOR's MaximoDemo subsystems instead resemble AWB's own Example1 +results (ELEC 0.67 vs 0.73, MON 0.80 vs 0.80). The stored results were most +likely computed before those delays were entered. This has not been checked +by re-running AWB. + +---|---:|---:|---| +| OilAndGasExample | 0.973217 | 0.974734 | Δ 0.152 pp; agrees | +| Example1 | 0.088322 | 0.006982 | not comparable | +| SapDemo | 0.629333 | 0.005037 | not comparable | +| MaximoDemo | 0.611809 | 0.005037 | not comparable | + +`ALTExample` and the `PumpExample` library example have no RBD blocks. + +The new inspection approximation improves the model but does not make +Example1/SapDemo/MaximoDemo comparable: Example1 has its inspection +disabled, while SapDemo/MaximoDemo still lose PM/inspection timing, +multi-mode Weibull shape and topology semantics. OilAndGasExample remains +the clean shipped-AWB comparison. + --- ## 2. Compatibility screening of all 27 examples diff --git a/docs/manual.adoc b/docs/manual.adoc index 1363b5cd..f20ef08a 100644 --- a/docs/manual.adoc +++ b/docs/manual.adoc @@ -1804,8 +1804,8 @@ In short: |Mission phases |partial: durations and block cut/linked rules |partial: durations and cut/linked rules; node/hierarchy and capacity/load rules are not imported |Out-of-service states |yes: applied to the AWB copy |yes: AWB global logic state becomes a RAPTOR cut/linked state |Block dependencies |not exported |partial: AWB state dependencies become 100% idle dependencies -|Preventive maintenance |partial: one planned task per failure model |partial: first enabled planned task; inspections and extra tasks are not imported -|Spare holdings |partial: level-1 stock and lead time |partial: level 1 + 2 become one pool; repair shop is not imported +|Preventive maintenance |partial: one planned task per failure model |partial: first enabled planned task; dormant inspections become a detection delay; other inspections/extra tasks are partial +|Spare holdings |partial: level-1 stock and lead time |partial: level 1 + 2 become one pool that emergency-orders after the level 1 + 2 + 3 delay (AWB never runs out); planned tasks do not wait for spares; repair shop is not imported |Labour/equipment resources |partial: resource pools and task links |partial: labour/equipment become RAPTOR resources; call-out delay is not imported |Capacity products and capacity targets |not exported |not imported |Consequence and cost models |not exported |not imported diff --git a/docs/manual.html b/docs/manual.html index e4b5be7b..bc506e03 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -2685,12 +2685,12 @@

Availability Workbench interchange

Preventive maintenance

partial: one planned task per failure model

-

partial: first enabled planned task; inspections and extra tasks are not imported

+

partial: first enabled planned task; dormant inspections become a detection delay; other inspections/extra tasks are partial

Spare holdings

partial: level-1 stock and lead time

-

partial: level 1 + 2 become one pool; repair shop is not imported

+

partial: level 1 + 2 become one pool that emergency-orders after the level 1 + 2 + 3 delay (AWB never runs out); planned tasks do not wait for spares; repair shop is not imported

Labour/equipment resources

diff --git a/raptor/core/fileio/awb.py b/raptor/core/fileio/awb.py index 2e9c5666..f0dcb3d5 100644 --- a/raptor/core/fileio/awb.py +++ b/raptor/core/fileio/awb.py @@ -605,15 +605,18 @@ def _sidecar_payload(rbd: RbdFile) -> dict[str, Any]: # noqa: C901, PLR0912, PL data["comments"] = [dict(c) for c in _section_list(rbd, "COMMENTS")] block_extras = {} for b in _section_list(rbd, "BLOCK_DATA"): - bid = _text(b.get("ID")) - if bid in ("", "0"): + if _text(b.get("ID")) in ("", "0"): continue + # Keyed by name: the export writes the block name as the AWB Id, + # the import names the block from it, and apply_sidecar looks the + # block up by that name (the RAPTOR ID is renumbered on import). + bid = _text(b.get("blockName")) or _text(b.get("ID")) extra = {k: b.get(k) for k in ( "DepType", "DepNum", "DepNothing", "DepIdle", "DepPM", "DepFail", "DepPMThresh", "defDepStateIdle", "Phasing", "SimStart", "AmtExhausted", "SBStress", "GDType", "GDRate", "GDLimit", "_DutyCycle", "_StartAge", "_RestoreFactor", - "_RestoreType", "NonOperational", "usesPM", "PMFreq", + "_RestoreType", "NonOperational", "usesPM", "PMFreq", "PMSpare", "Dist", "Param1#3", "Param2#3", "Param3#3", "initial", "Running", "standby", "idle", "repHold", "repPerTime", "repFixed", "donePerTime", "doneFixed", @@ -757,6 +760,10 @@ def apply_sidecar(doc: dict[str, Any], data: dict[str, Any], # noqa: C901, PLR0 if key == "phases": target["uses_phasing"] = True target.setdefault("legacy", {}).update(value) + elif key == "PMSpare": + # The import leaves AWB PM off the spare pool; a RAPTOR + # model's own setting comes back from the sidecar. + target["pm_spare"] = str(value) == "1" elif key not in target: target[key] = value for nid, extra in (data.get("node_extras") or {}).items(): @@ -1871,24 +1878,43 @@ def task_law(task: dict[str, Any]) -> tuple[int, list[float]]: spare_doc: list[dict[str, Any]] = [] spare_name: dict[int, str] = {} used_spares: set[str] = set() + stocked_l1_delay = 0 for i, sp in enumerate(spare_rows): name = _unique(_safe_id(_text(sp.get("Id"), f"Spare{i + 1}"), 20), used_spares, 20) stock = max(0, _int(sp.get("CapacityLevel1"), 0) + _int(sp.get("CapacityLevel2"), 0)) - arrive = max(1.0, _num(sp.get("LogisticDelayLevel2"), 0.0) - or _num(sp.get("LogisticDelayLevel3"), 24.0)) - emer = max(1.0, _num(sp.get("LogisticDelayLevel3"), arrive)) + # AWB level 3 is an unlimited manufacturing source: a demand that + # level 1 and level 2 cannot meet waits the level 3 -> 2 -> 1 -> + # task delays, and AvSim never runs out (manual, "Spares - Level 3 + # Properties"). RAPTOR's nearest equivalent is emergency ordering + # with that summed delay, plus a one-for-one stock-level reorder + # (reorder at stock-1, quantity 1) that refills held stock after + # the level 3 -> 1 delay. Without ESO a zero-stock pool would be + # permanently empty and every block using it would end "Done". + d1 = max(0.0, _num(sp.get("LogisticDelayLevel1"), 0.0)) + d2 = max(0.0, _num(sp.get("LogisticDelayLevel2"), 0.0)) + d3 = max(0.0, _num(sp.get("LogisticDelayLevel3"), 0.0)) + emer = max(1e-6, d1 + d2 + d3) + resupply = max(1e-6, d2 + d3) + if stock and d1 > 0: + stocked_l1_delay += 1 spare_doc.append({ "name": name, "stock": stock, "new_spares": max(1, _int(sp.get("MinimumReorderQuantity"), 1)), - "arrive_every": arrive, "eso": 1 if stock else 0, - "emer_time": emer, "slo": 0, "level": 0, "quantity": 1, - "slo_time": 24.0, "rso": 0, + "arrive_every": resupply, "eso": 1, + "emer_time": emer, "slo": 1 if stock else 0, + "level": max(0, stock - 1), "quantity": 1, + "slo_time": resupply, "rso": 0, "spare_cost": max(0.0, _num(sp.get("UnitCost"), 1.0)), "emer_ship_cost": max(0.0, _num(sp.get("TransportationCostLevel2"), 1.0)), }) spare_name[i] = name + report.add("level-1 spare logistic delay on stocked spares", + stocked_l1_delay, + "AWB's level-1 delay on a spare drawn from stock is not " + "modelled; only a stock-out waits the summed delay", + kind="partial") if any(_int(sp.get("CapacityLevel2"), 0) for sp in spare_rows): report.add("two-level spare holdings", 1, "AWB level-1 and level-2 stock are summed into one " @@ -1938,6 +1964,14 @@ def add_resource(kind: str, i: int, row: dict[str, Any], "one RAPTOR PM per block: extra AWB planned tasks, and " "inspection tasks, are not imported") + inspection_by_fm: dict[int, dict[str, Any]] = {} + for t in sched_tasks: + if _int(t.get("Type"), 0) != 1 or not _int(t.get("Enabled"), 0): + continue + fm_i = _int(t.get("FailureModel"), -1) + if fm_i >= 0 and fm_i not in inspection_by_fm: + inspection_by_fm[fm_i] = t + corr_spare_by_fm: dict[int, dict[str, Any]] = {} for row in corr_spares: fm_i = _int(row.get("FailureModel"), -1) @@ -1947,6 +1981,7 @@ def add_resource(kind: str, i: int, row: dict[str, Any], fm_i = _int(row.get("FailureModel"), -1) corr_labor_by_fm.setdefault(fm_i, row) sched_spare_by_fm: dict[int, dict[str, Any]] = {} + planned_spares = 0 for row in sched_spares: fm_i = _int(row.get("FailureModel"), -1) sched_spare_by_fm.setdefault(fm_i, row) @@ -1991,6 +2026,7 @@ def add_resource(kind: str, i: int, row: dict[str, Any], # ---- ordinary blocks -------------------------------------------------- block_losses: dict[str, int] = {} block_by_row: dict[int, dict[str, Any]] = {} + used_inspections = 0 for i, b in enumerate(blocks): if i == root_i or i in super_rows: continue @@ -2013,6 +2049,20 @@ def add_resource(kind: str, i: int, row: dict[str, Any], "repair_dist": rdist, "repair_params": rparams, } fm_i = _int(b.get("FailureModel"), -1) + inspection = inspection_by_fm.get(fm_i) + if (inspection is not None and 0 <= fm_i < len(fms) + and _int(fms[fm_i].get("FmDormant"), 0) + and _int(b.get("LogicMode"), 0) != 1): + repair = next((t for t in tasks + if _int(t.get("FailureModel"), -1) == fm_i), None) + block["repair_dist"], block["repair_params"] = _task_repair_law(repair) + block["pre_ldt_dist"] = _R_FIXED + block["pre_ldt_params"] = [_inspection_delay(inspection), 0.0, 0.0] + if block_losses.get("dormant failures"): + block_losses["dormant failures"] -= 1 + if not block_losses["dormant failures"]: + del block_losses["dormant failures"] + used_inspections += 1 pm = pm_by_fm.get(fm_i) if pm is not None: pm_dist, pm_params = task_law(pm) @@ -2025,8 +2075,14 @@ def add_resource(kind: str, i: int, row: dict[str, Any], "uses_pm": True, "pm_freq": pm_freq, "pm_duration_dist": pm_dist, "pm_params": pm_params, "pm_refresh": _num(pm.get("AgeReductionFactor"), 0.0) >= 0.999, - "pm_spare": fm_i in sched_spare_by_fm, + # AWB spare logistic delays hold up corrective actions + # only; a planned task's spares are on hand (manual, + # "Spares - Overview"). RAPTOR's PM would wait the whole + # supply chain for a pooled spare, so do not draw one. + "pm_spare": False, }) + if fm_i in sched_spare_by_fm: + planned_spares += 1 pm_res = sched_labor_by_fm.get(fm_i) if pm_res is not None: kind_i = _int(pm_res.get("Labor"), -1) @@ -2085,7 +2141,7 @@ def add_resource(kind: str, i: int, row: dict[str, Any], for feature, count in sorted(block_losses.items()): detail = { "multi-mode or buffer failure distribution": - "AWB multi-mode/buffer laws kept their first Weibull mode only", + "AWB multi-mode laws kept their shortest-life Weibull mode", "dormant failures": "a dormant AWB failure is modelled as never repaired", "start-up failure probability": @@ -2094,6 +2150,17 @@ def add_resource(kind: str, i: int, row: dict[str, Any], "AWB marks the block non-maintainable; RAPTOR repair is off", }.get(feature, "") report.add(feature, count, detail) + if used_inspections: + report.notes.append( + f"{used_inspections} dormant failure(s) approximated by the " + "expected AWB inspection detection delay") + enabled_inspections = [t for t in sched_tasks + if _int(t.get("Type"), 0) == 1 + and _int(t.get("Enabled"), 0)] + if len(enabled_inspections) > used_inspections: + report.add("inspection tasks", len(enabled_inspections) - used_inspections, + "enabled inspections without a dormant failure model " + "were not used", kind="partial") dep_count = 0 for row in rule_rows: dep_row = _int(row.get("DependentBlock"), -1) @@ -2350,6 +2417,10 @@ def add_junction(owner: int, name: str, x: float, y: float) -> int: project = _rows(tables, "Project")[0] if _rows(tables, "Project") else {} lifetime = max(1.0, _num(project.get("LifeTime"), 87600.0)) trials = max(1, _int(project.get("AvsimNoSimulationsRequested"), 1000)) + report.add("planned-task spares", planned_spares, + "AWB delays only corrective tasks for spares; imported PM " + "does not draw on the spare pool, so planned spare use is " + "not counted against stock", kind="partial") report.counts.update(blocks=len(elements["blocks"]), nodes=len(elements["nodes"]), hierarchies=len(elements["hierarchies"]), @@ -2466,6 +2537,102 @@ def _endpoint(kind: int, index: int, block_id: dict[int, int], return None +def _task_repair_law(task: dict[str, Any] | None) -> tuple[int, list[float]]: + """AWB corrective task -> RAPTOR repair law.""" + if task is None: + return _R_FIXED, [0.0, 0.0, 0.0] + duration = max(0.0, _num(task.get("TaskDuration")) + + _num(task.get("RampTime"))) + dist = _int(task.get("Distribution"), 2) + std = max(0.0, _num(task.get("Std"))) + if dist == 0: + return _R_EXPO, [max(1e-9, duration), 0.0, 0.0] + if dist == 1: + return _R_LOGNORM, [max(1e-9, duration), std, 0.0] + if dist == 3: + return _R_WEIBULL, [max(1e-9, _num(task.get("Beta"), 2.0)), + max(1e-9, duration), + max(0.0, _num(task.get("Gamma")))] + if std > 0: + return _R_NORM, [max(1e-9, duration), std, 0.0] + return _R_FIXED, [max(0.0, duration), 0.0, 0.0] + + +def _inspection_delay(task: dict[str, Any]) -> float: + """Expected detection delay for a dormant failure under an inspection.""" + interval = max(1e-9, _num(task.get("TaskInterval"), 8760.0)) + first = _num(task.get("Offset"), 0.0) + first = interval if first <= 0 else min(interval, first) + detection = min(1.0, max(0.01, _num(task.get("DetectionP"), 1.0))) + inspection_time = max(0.0, _num(task.get("TaskDuration")) + + _num(task.get("RampTime"))) + # A failure appears uniformly in the inspection interval; a perfect + # inspection finds it on average half an interval later. A detection + # probability below 1 stretches that by 1/p. + return first / (2.0 * detection) + inspection_time + + +def _competing_weibull_fit(modes: list[tuple[float, float, float]] + ) -> tuple[float, float, float]: + """One Weibull (beta, eta, gamma) approximating competing Weibull modes. + + *modes* are (eta, beta, gamma). The item's life is the minimum of the + mode lives. This is a moment match, not an exact conversion: the + fitted law has the same mean and coefficient of variation (measured + from the earliest location parameter), so failure counts agree but the + hazard shape, which matters for PM timing, is only approximate. + """ + if len(modes) == 1: + eta, beta, gamma = modes[0] + return beta, eta, gamma + g0 = min(m[2] for m in modes) + + def survival(t: float) -> float: + h = 0.0 + for eta, beta, gamma in modes: + x = t + g0 - gamma + if x > 0: + h += (x / eta) ** beta + return math.exp(-h) + + # Integrate on a log grid out to where the longest-lived mode alone + # would have near-zero survival. + upper = max(gamma - g0 + eta * 40.0 ** (1.0 / beta) + for eta, beta, gamma in modes) + lo = min(eta for eta, _, _ in modes) * 1e-6 + n = 4000 + ratio = (upper / lo) ** (1.0 / n) + ts = [0.0] + [lo * ratio ** i for i in range(n + 1)] + m1 = m2 = 0.0 + prev_t, prev_s = ts[0], survival(ts[0]) + for t in ts[1:]: + cur = survival(t) + dt = t - prev_t + m1 += 0.5 * (prev_s + cur) * dt + m2 += (prev_t * prev_s + t * cur) * dt + prev_t, prev_s = t, cur + var = max(0.0, m2 - m1 * m1) + if m1 <= 0: + eta, beta, gamma = min(modes, key=lambda m: m[0]) + return beta, eta, gamma + cv2 = var / (m1 * m1) + + def weibull_cv2(b: float) -> float: + g1 = math.gamma(1.0 + 1.0 / b) + return math.gamma(1.0 + 2.0 / b) / (g1 * g1) - 1.0 + + lo_b, hi_b = 0.05, 50.0 # CV^2 falls as beta rises + for _ in range(100): + mid = math.sqrt(lo_b * hi_b) + if weibull_cv2(mid) > cv2: + lo_b = mid + else: + hi_b = mid + beta = math.sqrt(lo_b * hi_b) + eta = m1 / math.gamma(1.0 + 1.0 / beta) + return beta, eta, g0 + + def _block_data(block: dict[str, Any], fms: list[dict[str, Any]], # noqa: C901, PLR0912 tasks: list[dict[str, Any]], losses: dict[str, int]) -> tuple[int, list[float], int, list[float]]: @@ -2494,8 +2661,19 @@ def _block_data(block: dict[str, Any], fms: list[dict[str, Any]], # noqa: C901, elif dist == _AWB_NORMAL: fdist, fparams = _R_NORM, [mttf, max(0.0, _num(fm.get("FmStd"))), 0.0] else: - # Bi-/tri-Weibull, buffer and phased laws have no exact RAPTOR - # equivalent in the friendly model. Keep the first mode and say so. + # Bi-/tri-Weibull and phased laws have no exact RAPTOR equivalent. + # AWB's modes compete (the item fails at the first of them), so fit + # one Weibull to the mean and spread of that competing-risk life. + # Only the modes the law uses count: a bi-Weibull's third-mode + # columns hold AWB's 8760 h placeholder, not data. + n_modes = {_AWB_BI_WEIBULL: 2, _AWB_PHASED_BI: 2, + _AWB_TRI_WEIBULL: 3, _AWB_PHASED_TRI: 3}.get(dist, 1) + modes = [(_num(fm.get(f"FmEta{k}"), eta), _num(fm.get(f"FmBeta{k}"), beta), + _num(fm.get(f"FmGamma{k}"), gamma)) + for k in range(1, n_modes + 1)] + modes = [m for m in modes if m[0] > 0 and m[1] > 0] + if modes: + beta, eta, gamma = _competing_weibull_fit(modes) fdist, fparams = _R_WEIBULL, [beta, eta, gamma] losses["multi-mode or buffer failure distribution"] = ( losses.get("multi-mode or buffer failure distribution", 0) + 1) @@ -2557,11 +2735,6 @@ def _check_import_features(tables: dict[str, AwbTable], report: AwbReport) -> No len(planned) - len(fms_with_planned), "RAPTOR has one PM per block; only the first planned " "task per failure model is imported", kind="partial") - inspections = [t for t in sched - if _int(t.get("Type"), 0) == 1 and _int(t.get("Enabled"), 0)] - if inspections: - report.add("inspection tasks", len(inspections), - "AWB inspection tasks are not imported as RAPTOR PM") calendar_pm = [t for t in planned if _int(t.get("FixedInterval"), 0)] if calendar_pm: report.add("calendar-interval PM", len(calendar_pm), diff --git a/tests/unit/test_awb.py b/tests/unit/test_awb.py index 8570dd74..d626a01d 100644 --- a/tests/unit/test_awb.py +++ b/tests/unit/test_awb.py @@ -378,8 +378,19 @@ def test_pm_spares_resources_phases_and_out_of_service_round_trip(tmp_path): assert pump["Resource1Name"] assert pump["P 001"].startswith("C:") assert back.out_of_service.get("block:2") == "cut" - assert "non-maintainable blocks" not in { - loss.feature for loss in report.not_in_target} + features = {loss.feature for loss in report.not_in_target} + assert "non-maintainable blocks" not in features + # The sidecar restores RAPTOR's own PM-spare setting on a round trip. + assert pump["PMSpare"] == "1" + # A plain AWB project (no sidecar): AWB delays only corrective tasks for + # spares, so the imported PM must not wait on the pool. + path.with_name(path.name + ".raptor.json").unlink() + plain, plain_report = import_awb(path) + plain_pump = next(r for r in _rows(plain, "BLOCK_DATA") + if r["blockName"] == "Pump") + assert plain_pump.get("PMSpare", "0") in ("0", "") + assert "planned-task spares" in { + loss.feature for loss in plain_report.not_in_target} def test_sidecar_preserves_raptor_only_metadata(tmp_path): @@ -503,6 +514,89 @@ def test_cli_no_sidecar(tmp_path): assert not dest.with_name(dest.name + ".raptor.json").exists() +def test_dormant_failure_uses_inspection_detection_delay(tmp_path): + from raptor.core.fileio import awb as awb_mod + path = tmp_path / "inspection.awb" + export_awb(_model(), path) + tables = read_awb(path) + fm = tables["FailureModels"].rows[0] + fm["FmDormant"] = 1 + task = awb_mod._row( + "FailureModelScheduledTasks", FailureModel=0, SubIndex=0, Type=1, + Description="Inspect dormant pump", TaskId="IN1", Enabled=1, + DetectionP=1.0, TaskDuration=1.0, RampTime=0.0, + TaskInterval=1000.0, FixedInterval=0, Offset=0.0) + tables["FailureModelScheduledTasks"] = AwbTable( + "FailureModelScheduledTasks", + _SCHEMA["FailureModelScheduledTasks"], [task]) + write_awb(path, tables) + back, report = import_awb(path) + pump = next(r for r in _rows(back, "BLOCK_DATA") if r["blockName"] == "Pump") + assert pump["RDist"] != "18" + assert float(pump["Pre-LDTDist"]) == 19 + assert 500.0 < float(pump["Param1#1"]) < 502.0 + assert "inspection detection delay" in " ".join(report.notes).lower() + + +def test_zero_stock_awb_spare_never_leaves_the_pool_dry(tmp_path): + """AWB level 3 is unlimited: a zero-stock spare must still be ordered. + + Before the fix the pool came in with stock 0 and no ordering, so every + block using it ended Done (No_spares) at its first failure. + """ + from raptor.core.fileio import awb as awb_mod + path = tmp_path / "spares.awb" + export_awb(_model(), path) + tables = read_awb(path) + rows = [awb_mod._row("Spares", Id="ZERO", CapacityLevel1=0, + LogisticDelayLevel1=48.0, LogisticDelayLevel2=96.0, + LogisticDelayLevel3=480.0), + awb_mod._row("Spares", Id="HELD", CapacityLevel1=3, + LogisticDelayLevel1=0.0, LogisticDelayLevel2=10.0, + LogisticDelayLevel3=20.0)] + tables["Spares"] = AwbTable("Spares", _SCHEMA["Spares"], rows) + write_awb(path, tables) + back, _ = import_awb(path) + pools = {r["PoolName"]: r for r in back.sections["SPARE_POOL_DATA"].rows} + zero, held = pools["ZERO"], pools["HELD"] + assert int(zero["Stock"]) == 0 and int(zero["ESO"]) == 1 + assert float(zero["EmerTime"]) == pytest.approx(624.0) + assert int(held["Stock"]) == 3 and int(held["ESO"]) == 1 + assert int(held["SLO"]) == 1 and int(held["Level"]) == 2 + assert float(held["SLOTime"]) == pytest.approx(30.0) + + +def test_competing_weibull_fit_matches_the_minimum_of_the_modes(): + import math + + from raptor.core.fileio.awb import _competing_weibull_fit + # Two equal exponentials compete as one exponential of half the mean. + beta, eta, gamma = _competing_weibull_fit([(100.0, 1.0, 0.0), + (100.0, 1.0, 0.0)]) + assert beta == pytest.approx(1.0, rel=1e-3) + assert eta == pytest.approx(50.0, rel=1e-3) + assert gamma == 0.0 + # An exponential and a wear-out mode: mean of min(T1, T2) by quadrature. + modes = [(20000.0, 1.0, 0.0), (4472.1, 2.0, 1000.0)] + beta, eta, _ = _competing_weibull_fit(modes) + mean = eta * math.gamma(1.0 + 1.0 / beta) + assert mean == pytest.approx(4316.0, rel=0.01) + + +def test_bi_weibull_ignores_the_unused_third_mode(tmp_path): + path = tmp_path / "biweibull.awb" + export_awb(_model(), path) + tables = read_awb(path) + fm = tables["FailureModels"].rows[0] + fm.update(FmDistribution=2, FmEta1=200000.0, FmBeta1=1.0, FmGamma1=0.0, + FmEta2=44721.0, FmBeta2=2.0, FmGamma2=0.0, + FmEta3=8760.0, FmBeta3=1.0, FmGamma3=0.0) + write_awb(path, tables) + back, _ = import_awb(path) + pump = next(r for r in _rows(back, "BLOCK_DATA") if r["blockName"] == "Pump") + # The placeholder 8760 h mode would have dragged eta down to 8760. + assert float(pump["FParam2"]) > 30000.0 + # -- review fixes (#288) ------------------------------------------------------- def _twins(**extra):