-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from kbss-cvut/feature/implement-fault-tree-e…
…valuation-with-operational-data Feature/implement fault tree evaluation with operational data
- Loading branch information
Showing
5 changed files
with
144 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/cz/cvut/kbss/analysis/service/FaultTreeEvaluationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cz.cvut.kbss.analysis.service; | ||
|
||
import cz.cvut.kbss.analysis.dao.FailureModeDao; | ||
import cz.cvut.kbss.analysis.dao.FaultTreeDao; | ||
import cz.cvut.kbss.analysis.model.Event; | ||
import cz.cvut.kbss.analysis.model.FaultEvent; | ||
import cz.cvut.kbss.analysis.model.FaultTree; | ||
import cz.cvut.kbss.analysis.model.Item; | ||
import cz.cvut.kbss.analysis.service.util.Pair; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.URI; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Stack; | ||
|
||
@Service | ||
@Slf4j | ||
public class FaultTreeService{ | ||
|
||
private final FaultEventRepositoryService faultEventRepositoryService; | ||
private final FailureModeDao failureModeDao; | ||
private final FaultTreeRepositoryService faultTreeRepositoryService; | ||
private final FaultTreeDao faultTreeDao; | ||
|
||
public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService, FailureModeDao failureModeDao, FaultTreeRepositoryService faultTreeRepositoryService, FaultTreeDao faultTreeDao) { | ||
this.faultEventRepositoryService = faultEventRepositoryService; | ||
this.failureModeDao = failureModeDao; | ||
this.faultTreeRepositoryService = faultTreeRepositoryService; | ||
this.faultTreeDao = faultTreeDao; | ||
} | ||
|
||
public FaultTree findWithDetails(URI id) { | ||
FaultTree ft = faultTreeRepositoryService.findRequired(id); | ||
Collection<Event> events = faultTreeDao.getRelatedEventTypes(ft); | ||
setRelatedBehaviors(events); | ||
|
||
events.stream().map(e -> e.getBehavior()).forEach(b -> { | ||
Item item = b.getItem(); | ||
if(item == null) | ||
return; | ||
|
||
item.setComponents(null); | ||
Optional.ofNullable(item.getSupertypes()).ifPresent(s -> s.forEach(st -> st.setComponents(null))); | ||
}); | ||
|
||
setReferences(ft); | ||
|
||
FaultTree summary = faultTreeRepositoryService.findSummary(ft.getUri()); | ||
ft.setOperationalDataFilter(summary.getOperationalDataFilter()); | ||
ft.setSystem(summary.getSystem()); | ||
ft.setSubsystem(summary.getSubsystem()); | ||
|
||
return ft; | ||
} | ||
|
||
protected void setReferences(FaultTree faultTree){ | ||
if(faultTree.getManifestingEvent() == null) | ||
return; | ||
|
||
Stack<Pair<URI, FaultEvent>> stack = new Stack<>(); | ||
stack.add(Pair.of(null,faultTree.getManifestingEvent())); | ||
while(!stack.isEmpty()){ | ||
Pair<URI,FaultEvent> p = stack.pop(); | ||
FaultEvent fe = p.getSecond(); | ||
faultEventRepositoryService.setExternalReference(p.getFirst(), fe); | ||
if(fe.getChildren() == null) | ||
continue; | ||
fe.getChildren().forEach(c -> stack.push(Pair.of(fe.getUri(), c))); | ||
} | ||
} | ||
|
||
protected void setRelatedBehaviors(Collection<Event> events){ | ||
for(Event event : events){ | ||
if(event.getBehavior() == null) | ||
event.setBehavior(failureModeDao.findByEvent(event.getUri())); | ||
} | ||
} | ||
} |