Skip to content

Commit

Permalink
[Fix patially kbss-cvut/fta-fmea-ui#390] Implement api for fault tree…
Browse files Browse the repository at this point in the history
… evaluation with operational data and operational data filter
  • Loading branch information
kostobog committed Jun 19, 2024
1 parent 76547ff commit 4c44c55
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cz.cvut.kbss.analysis.model.*;
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.FaultTreeEvaluationService;
import cz.cvut.kbss.analysis.service.FaultTreeRepositoryService;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
Expand All @@ -24,6 +25,7 @@
public class FaultTreeController {

private final FaultTreeRepositoryService repositoryService;
private final FaultTreeEvaluationService faultTreeEvaluationService;
private final IdentifierService identifierService;

@GetMapping
Expand Down Expand Up @@ -132,8 +134,8 @@ public void performCutSetAnalysis(@PathVariable(name = "faultTreeFragment") Stri
@PutMapping(value = "/{faultTreeFragment}/evaluate")
public void evaluate(@PathVariable(name = "faultTreeFragment") String faultTreeFragment, @RequestBody OperationalDataFilter filter){
URI faultTreeUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
log.info("> performCutSetAnalysis - {}", faultTreeFragment);
repositoryService.evaluate(faultTreeUri, filter);
log.info("> evaluate - {}", faultTreeFragment);
faultTreeEvaluationService.evaluate(faultTreeUri, filter);
}

}
11 changes: 11 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventScenarioDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.kbss.analysis.config.conf.PersistenceConf;
import cz.cvut.kbss.analysis.model.FaultEventScenario;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.EntityManager;
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -12,6 +13,8 @@

@Repository
public class FaultEventScenarioDao extends BaseDao<FaultEventScenario> {

public static URI HAS_SCENARIO_PROP = URI.create(Vocabulary.s_p_has_scenario);
@Autowired
protected FaultEventScenarioDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) {
super(FaultEventScenario.class, em, config, identifierService);
Expand All @@ -21,4 +24,12 @@ protected FaultEventScenarioDao(EntityManager em, PersistenceConf config, Identi
public EntityDescriptor getEntityDescriptor(URI uri) {
return super.getEntityDescriptor(uri);
}

public void addScenarioToTree(URI faultTreeUri, FaultEventScenario scenario){
persistPropertyInContext(faultTreeUri, HAS_SCENARIO_PROP, scenario.getUri(), scenario.getContext());
}

public void removeScenarios(URI faultTreeUri){
removeAll(faultTreeUri, HAS_SCENARIO_PROP, faultTreeUri);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cz.cvut.kbss.analysis.service;

import cz.cvut.kbss.analysis.model.FaultTree;
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.net.URI;

@Service
@Slf4j
public class FaultTreeEvaluationService
{
private final FaultTreeRepositoryService faultTreeRepositoryService;
private final OperationalDataFilterService operationalDataFilterService;
private final FaultTreeService faultTreeService;

public FaultTreeEvaluationService(FaultTreeRepositoryService faultTreeRepositoryService, OperationalDataFilterService operationalDataFilterService, FaultTreeService faultTreeService) {
this.faultTreeRepositoryService = faultTreeRepositoryService;
this.operationalDataFilterService = operationalDataFilterService;
this.faultTreeService = faultTreeService;
}

public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) {

operationalDataFilterService.updateFaultTreeFilter(faultTreeUri, filter);

FaultTree faultTree = faultTreeService.findWithDetails(faultTreeUri);

faultTreeRepositoryService.updateFaultTreeOperationalFailureRates(faultTree, filter);

return faultTreeRepositoryService.evaluate(faultTree);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,6 @@ public FaultTree performCutSetAnalysis(URI faultTreeUri){
return faultTree;
}

@Transactional
public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) {

operationalDataFilterService.updateFaultTreeFilter(faultTreeUri, filter);

FaultTree faultTree = findWithDetails(faultTreeUri);

updateFaultTreeOperationalFailureRates(faultTree, filter);

return evaluate(faultTree);
}

/**
* Updates the provided fault tree sns' failures with operational failure rate calculated based on filter. The update
* is reflected in the persistent storage and in the input fault tree.
Expand Down Expand Up @@ -634,18 +622,25 @@ public FaultTree evaluate(FaultTree faultTree) {

if(faultTree.getFaultEventScenarios() != null) {
for (FaultEventScenario faultEventScenario : faultTree.getFaultEventScenarios())
faultEventScenarioDao.remove(faultEventScenario);
faultEventScenarioDao.remove(faultEventScenario.getUri());
faultEventScenarioDao.removeScenarios(faultTree.getUri());
faultTree.setFaultEventScenarios(null);
}

FTAMinimalCutSetEvaluation evaluator = new FTAMinimalCutSetEvaluation();
evaluator.evaluate(faultTree);

for(FaultEvent evt : faultTree.getAllEvents().stream().filter(e -> e.getEventType() != FtaEventType.BASIC).toList()){
faultEventDao.setProbability(evt.getUri(), evt.getProbability(), faultTree.getUri());
}

if(faultTree.getFaultEventScenarios() != null) {
for (FaultEventScenario scenario : faultTree.getFaultEventScenarios()) {
scenario.setContext(faultTree.getUri());
scenario.updateProbability();
faultEventScenarioDao.persist(scenario);
faultEventScenarioDao.addScenarioToTree(faultTree.getUri(), scenario);
}
getPrimaryDao().update(faultTree);
}
return faultTree;
}
Expand Down

0 comments on commit 4c44c55

Please sign in to comment.