Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated ft components are sort by causal factor #23

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading