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

Fix/fix fault tree and fault evet status #161

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ public Query getSummariesQuery() {
return em.createNativeQuery("""
PREFIX fta: <http://onto.fel.cvut.cz/ontologies/fta-fmea-application/>
SELECT * WHERE {
BIND(?_uri as ?uri)
?uri a ?type.
BIND(?_uri as ?uri)
?uri a ?type.
?uri ?pName ?name.
OPTIONAL{?uri ?pDescription ?description.}
OPTIONAL{?uri ?pDescription ?description.}
OPTIONAL{?uri ?pStatus ?status.}
OPTIONAL{?uri ?pCreated ?created.}
OPTIONAL{?uri ?pModified ?modified.}
OPTIONAL{?uri ?pCreator ?creator.}
OPTIONAL{?uri ?pLastEditor ?lastEditor.}
OPTIONAL{
OPTIONAL{
?uri fta:is-manifested-by ?rootEvent .
?rootEvent fta:is-derived-from ?rootEventType.
OPTIONAL{
Expand All @@ -132,7 +133,7 @@ public Query getSummariesQuery() {
?fhaFailureRateQ fta:has-estimate ?fhaFailureRateP.
?fhaFailureRateP a fta:failure-rate-estimate;
fta:value ?fhaBasedFailureRate.
}
}
OPTIONAL{
?rootEventType fta:is-manifestation-of ?behavior .
?behavior fta:has-component ?_subsystemUri.
Expand All @@ -141,7 +142,7 @@ public Query getSummariesQuery() {
?systemUri fta:is-part-of ?system2.
}
?systemUri fta:name ?systemName.

OPTIONAL{
FILTER(?systemUri != ?_subsystemUri)
BIND(?_subsystemUri as ?subsystemUri)
Expand All @@ -157,6 +158,7 @@ public Query getSummariesQuery() {
.setParameter("type", typeUri)
.setParameter("pName", P_HAS_NAME)
.setParameter("pDescription", P_HAS_DESCRIPTION)
.setParameter("pStatus", STATUS_PROP)
.setParameter("pCreated", P_CREATED)
.setParameter("pModified", P_MODIFIED)
.setParameter("pCreator", P_CREATOR)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static FaultEvent create(){
@OWLDataProperty(iri = Vocabulary.s_p_probability)
private Double probability;

@Transient
private boolean probabilityUpdated = false;

@OWLObjectProperty(iri = Vocabulary.s_p_has_selected_estimation, fetch = FetchType.EAGER)
private URI selectedEstimate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.net.URI;
import java.util.HashSet;
import java.util.Optional;


@SparqlResultSetMappings(
Expand All @@ -22,7 +23,7 @@
public class FaultTreeSummary extends ManagedEntity{

@OWLDataProperty(iri = Vocabulary.s_p_status)
protected Status status;
protected String status;

@OWLObjectProperty(iri = Vocabulary.s_p_is_derived_from)
protected URI rootEvent;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void copyTo(FaultTree faultTree){
faultTree.getSubsystem().setUri(this.getSubsystemUri());
faultTree.getSubsystem().setName(this.getSubsystemName());
}
faultTree.setStatus(this.getStatus());
Optional.ofNullable(this.getStatus()).map(Status::valueOf).ifPresent(faultTree::setStatus);
faultTree.setRequiredFailureRate(this.getRequiredFailureRate());
faultTree.setCalculatedFailureRate(this.getCalculatedFailureRate());
faultTree.setFhaBasedFailureRate(this.getFhaBasedFailureRate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void preRemove(FaultEvent instance) {

@Transactional
public FaultEvent addInputEvent(URI eventUri, FaultEvent inputEvent) {
inputEvent.setProbabilityUpdated(true);
validateNew(inputEvent);
FaultEvent currentEvent = findRequired(eventUri);

Expand All @@ -76,11 +77,13 @@ public FaultEvent addInputEvent(URI eventUri, FaultEvent inputEvent) {
currentEvent.addChildSequenceUri(inputEvent.getUri());
update(currentEvent);

setExternalReference(eventUri, inputEvent);
setExternalReference(inputEvent);
if(inputEvent.getReferences() != null)
inputEvent.setProbability(inputEvent.getReferences().getProbability());
return inputEvent;
}

protected void setExternalReference(URI eventUri, FaultEvent inputEvent){
public void setExternalReference(FaultEvent inputEvent){
if(inputEvent.getSupertypes() == null || inputEvent.getEventType() != FtaEventType.EXTERNAL)
return;

Expand All @@ -93,8 +96,8 @@ protected void setExternalReference(URI eventUri, FaultEvent inputEvent){
inputEvent.setIsReference(true);

if(supertypes.size() > 1)
log.warn("new event added to event <{}> has multiple supertypes [{}]",
eventUri,
log.warn("event \"{}\"<{}> , has multiple supertypes [{}]",
inputEvent.getName(), inputEvent.getUri(),
supertypes.stream().map(e -> String.format("<%s>", e.getUri().toString()))
.collect(Collectors.joining(",")));

Expand All @@ -105,14 +108,22 @@ protected void setExternalReference(URI eventUri, FaultEvent inputEvent){
return;

if(referencedRoots.size() > 1)
log.warn("new event added to event <{}> with supertype <{}> is used in multiple root fault events [{}]",
eventUri, supertype.getUri(),
log.warn("event \"{}\"<{}> with supertype <{}> is used in multiple root fault events [{}]",
inputEvent.getName(), inputEvent.getUri(), supertype.getUri(),
referencedRoots.stream().map(u -> String.format("<%s>", u.toString()))
.collect(Collectors.joining(",")));

inputEvent.setReferences(referencedRoots.get(0));
}

@Transactional
public void updateProbabilityFromReferencedNode(FaultEvent faultEvent, URI faultTreeUri){
if(faultEvent.getReferences() == null || faultEvent.getReferences().getProbability() == null)
return;
faultEventDao.setProbability(faultEvent.getUri(), faultEvent.getReferences().getProbability(), faultTreeUri);
faultEvent.setProbability(faultEvent.getReferences().getProbability());
}

@Transactional(readOnly = true)
public Double propagateProbability(FaultEvent event) {
log.info("> propagateProbability - {}", event);
Expand Down Expand Up @@ -182,6 +193,8 @@ public FaultEvent update(FaultEvent instance) {
managedInstance.setDescription(instance.getDescription());
managedInstance.setGateType(instance.getGateType());
managedInstance.setEventType(instance.getEventType());
if(instance.getProbability() != managedInstance.getProbability())
managedInstance.setProbabilityUpdated(true);
managedInstance.setProbability(instance.getProbability());
managedInstance.setSupertypes(instance.getSupertypes());
managedInstance.setChildrenSequence(instance.getChildrenSequence());
Expand Down Expand Up @@ -220,12 +233,15 @@ protected void postUpdate(@NonNull FaultEvent instance) {
@Override
protected void postRemove(@NonNull FaultEvent instance) {
super.postRemove(instance);
instance.setProbabilityUpdated(true);
setChange(instance);
}

protected void setChange(FaultEvent instance){
URI context = faultEventDao.getContext(instance);
UserReference userReference = securityUtils.getCurrentUserReference();
if(instance.isProbabilityUpdated())
faultTreeDao.updateStatus(context, Status.outOfSync);
faultTreeDao.setChangedByContext(context, new Date(), userReference.getUri());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) {

faultTree = faultTreeRepositoryService.evaluate(faultTree);

Status status = faultTreeRepositoryService.getInferedStatus(faultTree);
faultTreeDao.updateStatus(faultTree.getUri(), status);
faultTreeDao.updateStatus(faultTree.getUri(), Status.ok);

return faultTree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public List<FaultTree> findAllSummaries(){
uri -> systemRepositoryService.findAllSummary(uri)
);
faultTreeSummary.setSystem(system);
setInferStatus(faultTreeSummary);
}
return summaries;
}
Expand Down Expand Up @@ -564,9 +563,15 @@ public FaultTree performCutSetAnalysis(URI faultTreeUri){
@Transactional
public void updateFailureRates(FaultTree faultTree, OperationalDataFilter filter){
updateFHABasedOperationalFailureRates(faultTree, filter);
updateReferencedNodeFailureRates(faultTree);
updateFaultTreeOperationalFailureRates(faultTree, filter);
}

/**
* Updates the FHA based operational failure rate of the Root node
* @param faultTree
* @param filter
*/
@Transactional
public void updateFHABasedOperationalFailureRates(FaultTree faultTree, OperationalDataFilter filter) {
FaultEventType fhaEvent = (FaultEventType)Optional.ofNullable(faultTree.getManifestingEvent())
Expand Down Expand Up @@ -595,6 +600,13 @@ public void updateFHABasedOperationalFailureRates(FaultTree faultTree, Operation
faultTree.getManifestingEvent(), fr);
}

@Transactional
public void updateReferencedNodeFailureRates(FaultTree faultTree){
for(FaultEvent faultEvent : faultTree.getAllEvents()){
faultEventRepositoryService.updateProbabilityFromReferencedNode(faultEvent, faultTree.getUri());
}
}

/**
* 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
13 changes: 2 additions & 11 deletions src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public FaultTree findWithDetails(URI id) {
.map(u -> systemRepositoryService.findAllSummary(u)).orElse( null)
);
ft.setSubsystem(summary.getSubsystem());
if(ft.getSystem() != null)
faultTreeRepositoryService.setInferStatus(ft);

return ft;
}
Expand All @@ -65,15 +63,8 @@ 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)));
for(FaultEvent fe: faultTree.getAllEvents()){
faultEventRepositoryService.setExternalReference(fe);
}
}

Expand Down
Loading