use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class UsageModelToBehaviorModelStage method traverseBranch.
private Map<EntryCallNode, Double> traverseBranch(final BehaviorModel behaviorModel, final Optional<Map<EntryCallNode, Double>> optPreviousNodes, final Branch branch) {
// assign new probabilities to the nodes
final Map<BranchTransition, Map<EntryCallNode, Double>> transitionMap = new HashMap<>();
for (final BranchTransition transition : branch.getBranchTransitions_Branch()) {
final Map<EntryCallNode, Double> branchMap = new HashMap<>();
optPreviousNodes.ifPresent(previousNodes -> previousNodes.keySet().stream().forEach(node -> branchMap.put(node, transition.getBranchProbability())));
transitionMap.put(transition, branchMap);
}
// traverse all branches and collect the end nodes
return branch.getBranchTransitions_Branch().stream().map(transition -> this.traverseScenarioBehavior(transition.getBranchedBehaviour_BranchTransition(), behaviorModel, // all
Optional.of(transitionMap.get(transition)))).collect(HashMap::new, Map::putAll, // collect endNodes
Map::putAll);
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class UsageModelToBehaviorModelStage method findLoopStart.
/**
* Find first {@link EntryLevelSystemCall} element of a {@link Loop} body.
*
* @param loop
* loop
* @return first found {@link EntryLevelSystemCall}, if found
*/
private Optional<EntryCallNode> findLoopStart(final AbstractUserAction action) {
if (action instanceof Stop) {
// LoopStart not found
return Optional.empty();
} else if (action instanceof EntryLevelSystemCall) {
// found loop start
final EntryLevelSystemCall entryLevelSystemCall = (EntryLevelSystemCall) action;
final EntryCallNode entryCallNode = this.createEntryCallNode(entryLevelSystemCall);
return Optional.of(entryCallNode);
} else if (action instanceof Loop) {
// search nested scenario
final Loop loop = (Loop) action;
final List<AbstractUserAction> userActions = loop.getBodyBehaviour_Loop().getActions_ScenarioBehaviour();
if (!userActions.isEmpty()) {
return this.findLoopStart(userActions.get(0));
} else {
return Optional.empty();
}
} else if (action instanceof Branch) {
// will always found before
return Optional.empty();
} else {
// next action
return this.findLoopStart(action.getSuccessor());
}
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class UnionModelGenerationStrategy method generateModel.
@Override
public BehaviorModel generateModel(final BehaviorModel[] models) {
final BehaviorModel newModel = new BehaviorModel();
for (final BehaviorModel model : models) {
/**
* We add nodes first so we don't get duplicate nodes from the same model
*/
for (final EntryCallNode node : model.getNodes()) {
final Optional<EntryCallNode> matchingNode = newModel.findNode(node.getSignature());
if (matchingNode.isPresent()) {
Optional<CallInformation> matchingInfo;
for (final CallInformation info : node.getEntryCallInformation()) {
matchingInfo = matchingNode.get().findCallInformation(info.getInformationSignature(), info.getInformationParameter());
if (matchingInfo.isPresent()) {
final int newCount = Math.max(info.getCount(), matchingInfo.get().getCount());
matchingInfo.get().setCount(newCount);
} else {
matchingNode.get().mergeCallInformation(new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount()));
}
}
} else {
// Copy node and add it
final EntryCallNode newNode = new EntryCallNode();
newNode.setSignature(node.getSignature());
for (final CallInformation info : node.getEntryCallInformation()) {
final CallInformation newInfo = new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount());
newNode.mergeCallInformation(newInfo);
}
newModel.addNode(newNode, false);
}
}
for (final EntryCallEdge edge : model.getEdges()) {
final Optional<EntryCallEdge> matchingEdge = newModel.findEdge(edge.getSource().getSignature(), edge.getTarget().getSignature());
if (matchingEdge.isPresent()) {
matchingEdge.get().setCalls(Math.max(matchingEdge.get().getCalls(), edge.getCalls()));
} else {
newModel.addEdge(new EntryCallEdge(edge.getSource(), edge.getTarget(), edge.getCalls()), false);
}
}
}
return newModel;
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class JPetStoreParameterMetric method getDistance.
@Override
public double getDistance(final BehaviorModel a, final BehaviorModel b) {
// If a node is not shared by the other behavior model, it will be compared to
// this empty dummy node
final EntryCallNode dummyNode = new EntryCallNode();
double distance = 0;
double comparisons = 0;
EntryCallNode matchingNode;
for (final EntryCallNode nodeA : a.getNodes()) {
matchingNode = b.findNode(nodeA.getSignature()).orElse(dummyNode);
distance += this.getNodeDistance(nodeA, matchingNode);
comparisons++;
}
// for which we cannot find matches with the dummy node.
for (final EntryCallNode nodeB : b.getNodes()) {
matchingNode = b.findNode(nodeB.getSignature()).orElse(null);
if (matchingNode == null) {
// We already compared it in the first loop if it's not null
distance += this.getNodeDistance(nodeB, dummyNode);
comparisons++;
}
}
return comparisons > 0 ? distance / comparisons : 0;
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class BehaviorModelVisualizationStage method createNodes.
/**
* Create new nodes at visualisation backend.
*
* @param entryCallNodes
* entryCallNodes
*/
private void createNodes(final Collection<EntryCallNode> entryCallNodes, final long modelId) {
final ArrayNode nodes = this.objectMapper.createArrayNode();
for (final EntryCallNode entryCallNode : entryCallNodes) {
final ObjectNode json = this.objectMapper.createObjectNode();
json.put("id", 0);
json.put("name", this.signatureStrategy.getSignature(entryCallNode));
final ObjectNode extras = this.objectMapper.createObjectNode();
for (final CallInformation callInformation : entryCallNode.getEntryCallInformation()) {
extras.put(callInformation.getInformationSignature(), callInformation.getInformationParameter());
}
json.put("extra", extras);
// TODO visualizations doesn't accept lists.
// TODO is this a requirement request?
nodes.add(json);
final JsonNode node = this.postElement(json, this.getNodeUrl(modelId));
this.nodeMap.put(entryCallNode.getSignature(), node);
}
}
Aggregations