Skip to content

Commit

Permalink
[Fix #554] Use required failure rate from model instead of one create…
Browse files Browse the repository at this point in the history
…d by the fault tree Editor component
  • Loading branch information
kostobog committed Aug 28, 2024
1 parent 16e8f7b commit cf33243
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/components/editor/faultTree/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { FTABoundary } from "@components/editor/faultTree/shapes/shapesDefinitio
import * as joint from "jointjs";
import { Rectangle } from "@models/utils/Rectangle";
import { JOINTJS_NODE_MODEL } from "@components/editor/faultTree/shapes/constants";
import { calculateCutSets } from "@services/faultTreeService";
import { FaultEventScenario } from "@models/faultEventScenario";
import { useAppBar } from "../../../contexts/AppBarContext";
import { asArray } from "@utils/utils";
Expand Down Expand Up @@ -50,13 +49,8 @@ const Editor = () => {

useEffect(() => {
if (faultTree) {
const rootReqProb = faultTree.manifestingEvent.supertypes?.hasFailureRate?.requirement?.upperBound;
const updatedRootEvent = rootReqProb
? { ...faultTree.manifestingEvent, probabilityRequirement: rootReqProb }
: faultTree.manifestingEvent;

setAppBarTitle(faultTree.name);
setRootEvent(updatedRootEvent);
setRootEvent(faultTree.manifestingEvent);

if (faultTree.faultEventScenarios) {
setFaultEventScenarios([getScenarioWithHighestProbability(asArray(faultTree.faultEventScenarios))]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const FaultEventMenu = ({ selectedShapeToolData, onEventUpdated, refreshTree, ro
const [resetMenu, setResetMenu] = useState<boolean>(false);
const [shapeToolData, setShapeToolData] = useState<FaultEvent | undefined>(undefined);

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

useEffect(() => {
if (isModified) {
setShowUnsavedChangesDialog(true);
Expand Down Expand Up @@ -284,7 +286,6 @@ const FaultEventMenu = ({ selectedShapeToolData, onEventUpdated, refreshTree, ro
}, [isDirty]);

const basedFailureRate = shapeToolData?.supertypes?.hasFailureRate?.estimate?.value;
const requiredFailureRate = shapeToolData?.supertypes?.hasFailureRate?.requirement?.upperBound;
const { predictionIri, operationalIri } = getFailureRateIris(shapeToolData?.supertypes?.supertypes);

const FailureRateBox = ({ value, label, rate, selected, outdated }) => (
Expand Down Expand Up @@ -338,11 +339,11 @@ const FaultEventMenu = ({ selectedShapeToolData, onEventUpdated, refreshTree, ro
</Typography>
</Box>
)}
{shapeToolData?.probabilityRequirement && (
{getRequiredFailureRate() && (
<Box className={classes.eventPropertyRow}>
<Typography>
<span className={classes.label}>{t("faultEventMenu.requiredFailureRate")}:</span>
{shapeToolData?.probabilityRequirement.toExponential(2)}
{getRequiredFailureRate().toExponential(2)}
</Typography>
</Box>
)}
Expand Down Expand Up @@ -370,11 +371,11 @@ const FaultEventMenu = ({ selectedShapeToolData, onEventUpdated, refreshTree, ro
</Typography>
</Box>
)}
{requiredFailureRate && (
{getRequiredFailureRate() && (
<Box className={classes.eventPropertyRow}>
<Typography>
<span className={classes.label}>{t("faultEventMenu.requiredFailureRate")}:</span>
{shapeToolData?.supertypes?.hasFailureRate?.requirement?.upperBound.toExponential(2)}
{getRequiredFailureRate().toExponential(2)}
</Typography>
</Box>
)}
Expand Down
6 changes: 1 addition & 5 deletions src/components/editor/faultTree/shapes/RenderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { sequenceListToArray } from "../../../../services/faultEventService";
import * as faultEventService from "../../../../services/faultEventService";
import { Link } from "./shapesDefinitions";
import { flatten } from "lodash";
import { has } from "lodash";
import {
ERROR_PATH_COLOR,
JOINTJS_NODE_MODEL,
DEFAULT_NODE_SHAPE_SIZE,
LABEL_FONT_SIZE,
} from "@components/editor/faultTree/shapes/constants";
import { getNodeWidthForText } from "@utils/treeUtils";
import { Status } from "@utils/constants";
import { asArray } from "@utils/utils";

const referenceIcon =
Expand Down Expand Up @@ -82,9 +80,7 @@ const renderTree = async (container, node, parentShape = null, pathsToHighlight,
}
}

const probReqValue =
(isReferencedNode(node) && node.supertypes?.hasFailureRate?.requirement?.upperBound?.toExponential(2)) ||
(has(node, "probabilityRequirement") && node.probabilityRequirement.toExponential(2));
const probReqValue = node?.supertypes?.hasFailureRate?.requirement?.upperBound?.toExponential(2);

if (probReqValue) {
nodeShape.attr(["probabilityRequirementLabel", "text"], probReqValue);
Expand Down

0 comments on commit cf33243

Please sign in to comment.