Skip to content

Commit

Permalink
Merge pull request #651 from kbss-cvut/fix/640-fix-missing-predicted-…
Browse files Browse the repository at this point in the history
…failure-rate-in-fault-tree-diagram

Fix/640 fix missing predicted failure rate in fault tree diagram
  • Loading branch information
kostobog authored Nov 5, 2024
2 parents 62442f7 + 6e5f89a commit 2d30416
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TextField,
} from "@mui/material";
import FaultEventShapeToolPane from "./FaultEventShapeToolPane";
import { EventType, FaultEvent } from "@models/eventModel";
import { EventType, FaultEvent, getFailureRates } from "@models/eventModel";
import * as React from "react";
import FailureModeDialog from "../../../../dialog/failureMode/create/FailureModeDialog";
import { useState, useEffect } from "react";
Expand Down Expand Up @@ -72,18 +72,6 @@ const FaultEventMenu = ({

const getRequiredFailureRate = () => shapeToolData.supertypes?.hasFailureRate?.requirement?.upperBound;

const getFailureRates = (shapeToolData) => {
const _types = asArray(shapeToolData?.supertypes);
if (_types.length === 0) return { undefined, undefined };
const __types = asArray(_types?.[0]?.supertypes);

const frPrediction =
_types[0].hasFailureRate?.prediction || __types.map((t) => t.hasFailureRate?.prediction).filter((p) => p)?.[0];
const frEstimate =
__types.map((t) => t.hasFailureRate?.estimate).filter((e) => e)?.[0] || _types?.[0].hasFailureRate?.estimate;
return { frPrediction, frEstimate };
};

useEffect(() => {
if (isModified) {
setShowUnsavedChangesDialog(true);
Expand Down
17 changes: 5 additions & 12 deletions src/components/editor/faultTree/shapes/RenderTree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createShape } from "../../../../services/jointService";
import { EventType, isReferencedNode, isRootOrIntermediateNode } from "../../../../models/eventModel";
import { EventType, getFailureRates, isReferencedNode, isRootOrIntermediateNode } from "../../../../models/eventModel";
import { sequenceListToArray } from "../../../../services/faultEventService";
import * as faultEventService from "../../../../services/faultEventService";
import { Link } from "./shapesDefinitions";
Expand Down Expand Up @@ -57,18 +57,11 @@ const renderTree = async (container, node, parentShape = null, pathsToHighlight,
if (node?.probability) {
if (node?.selectedEstimate) {
const iriOfSelectedValue = node.selectedEstimate.iri;
const { predictionIri, operationalIri } = asArray(node.supertypes.supertypes).reduce(
(acc, item) => {
if (item?.hasFailureRate?.prediction?.iri) acc.predictionIri = item.hasFailureRate.prediction.iri;
if (item?.hasFailureRate?.estimate?.iri) acc.operationalIri = item.hasFailureRate.estimate.iri;
return acc;
},
{ predictionIri: "", operationalIri: "" },
);

if (iriOfSelectedValue === predictionIri) {
const { frPrediction, frEstimate } = getFailureRates(node);

if (iriOfSelectedValue === frPrediction.iri) {
nodeShape.attr(["probabilityLabel", "text"], `(P) ${node.probability.toExponential(2)}`);
} else if (iriOfSelectedValue === operationalIri) {
} else if (iriOfSelectedValue === frEstimate.iri) {
nodeShape.attr(["probabilityLabel", "text"], `(O) ${node.probability.toExponential(2)}`);
}
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/models/eventModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ export const isSimpleBasicNode = (node: FaultEvent): boolean => {
export const isSNSNode = (node: FaultEvent): boolean => {
return node.eventType === EventType.BASIC && asArray(node.supertypes).length === 0;
};

export const getFailureRates = (event) => {
const _types = asArray(event?.supertypes);
if (_types.length === 0) return { undefined, undefined };
const __types = asArray(_types?.[0]?.supertypes);

const frPrediction =
_types[0].hasFailureRate?.prediction || __types.map((t) => t.hasFailureRate?.prediction).filter((p) => p)?.[0];
const frEstimate =
__types.map((t) => t.hasFailureRate?.estimate).filter((e) => e)?.[0] || _types?.[0].hasFailureRate?.estimate;
return { frPrediction, frEstimate };
};

0 comments on commit 2d30416

Please sign in to comment.