Skip to content

Commit

Permalink
Merge pull request #23 from kieler/jep/ftaGeneration
Browse files Browse the repository at this point in the history
generated ft components are sort by causal factor
  • Loading branch information
Drakae authored Jan 24, 2024
2 parents e5e93fc + ee08757 commit 7500167
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions extension/src-language-server/stpa/ftaGeneration/fta-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,9 @@ function createFaulTreeForHazard(scenarios: Map<string, LossScenario[]>, hazard:
ftaModel.components = [];
ftaModel.gates = [];

// add scenarios as components and sort them by their causal factor
// sort scenarios by their causal factor
const causalFactors: Map<string, LossScenario[]> = new Map();
for (const scenario of scenarios.get(hazard.name) || []) {
const component = {
name: scenario.name,
description: scenario.description,
$container: ftaModel,
$type: "Component",
} as Component;
ftaModel.components.push(component);
const causalFactor = scenario.factor;
if (causalFactor) {
addToListMap(causalFactors, causalFactor, scenario);
Expand All @@ -84,12 +77,25 @@ function createFaulTreeForHazard(scenarios: Map<string, LossScenario[]>, hazard:
}
}

// add scenarios as components ordered by their causal factor
for (const causalFactor of causalFactors.keys()) {
for (const scenario of causalFactors.get(causalFactor) || []) {
const component = {
name: scenario.name,
description: scenario.description,
$container: ftaModel,
$type: "Component",
} as Component;
ftaModel.components.push(component);
}
}

// create gate for each causal factor
let counter = 1;
for (const causalFactor of causalFactors.keys()) {
const children = causalFactors.get(causalFactor)?.map((scenario) => {
const children = causalFactors.get(causalFactor)?.map(scenario => {
return {
ref: ftaModel.components.find((component) => component.name === scenario.name),
ref: ftaModel.components.find(component => component.name === scenario.name),
$refText: scenario.name,
} as Reference<Children>;
});
Expand All @@ -107,7 +113,7 @@ function createFaulTreeForHazard(scenarios: Map<string, LossScenario[]>, hazard:
}

// create gate to connect top event with all other gates
const gateChildren = ftaModel.gates.map((gate) => {
const gateChildren = ftaModel.gates.map(gate => {
return { ref: gate, $refText: gate.name } as Reference<Children>;
});
const gate = {
Expand Down

0 comments on commit 7500167

Please sign in to comment.