Search in sources :

Example 1 with BehaviorModel

use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.

the class BehaviorModelCreationStage method createBehaviorModel.

/**
 * create a BehaviorModel from Instance.
 *
 * @param instances
 *            instances containing the attribute names
 * @param instance
 *            instance containing the attributes
 * @return behavior model if relevant
 */
private Optional<BehaviorModel> createBehaviorModel(final Instances instances, final Instance instance) {
    final int size = instance.numAttributes();
    final BehaviorModel behaviorModel = new BehaviorModel();
    for (int i = 0; i < size; i++) {
        final Attribute attribute = instances.attribute(i);
        final String attributeName = attribute.name();
        final Double attributeValue = instance.value(attribute);
        if (this.matchEdge(attributeName)) {
            final Optional<EntryCallEdge> edge = this.createEdge(attributeName, attributeValue);
            if (edge.isPresent()) {
                behaviorModel.addEdge(edge.get(), true);
            }
        } else if (this.matchNode(attributeName)) {
            final Optional<EntryCallNode> node = this.createNode(attributeName, attributeValue);
            if (node.isPresent()) {
                behaviorModel.addNode(node.get(), true);
            }
        }
    }
    if (behaviorModel.getEdges().isEmpty() && behaviorModel.getNodes().isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(behaviorModel);
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) Optional(java.util.Optional) Attribute(weka.core.Attribute) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 2 with BehaviorModel

use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.

the class IntersectionModelGenerationStrategy method intersect.

private BehaviorModel intersect(final BehaviorModel a, final BehaviorModel b) {
    final BehaviorModel result = new BehaviorModel();
    Optional<EntryCallEdge> matchingEdge;
    for (final EntryCallEdge edgeA : a.getEdges()) {
        matchingEdge = b.findEdge(edgeA.getSource().getSignature(), edgeA.getTarget().getSignature());
        if (matchingEdge.isPresent()) {
            final EntryCallNode newSource = this.intersectNode(edgeA.getSource(), matchingEdge.get().getSource());
            final EntryCallNode newTarget = this.intersectNode(edgeA.getTarget(), matchingEdge.get().getTarget());
            final int edgeCount = (int) Math.min(edgeA.getCalls(), matchingEdge.get().getCalls());
            final EntryCallEdge newEdge = new EntryCallEdge(newSource, newTarget, edgeCount);
            result.addEdge(newEdge, false);
        }
    }
    return result;
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 3 with BehaviorModel

use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.

the class SessionToBehaviorModelTransformation method convert.

/**
 * Convert a user session into a behavior model.
 *
 * @param session
 *            user session
 * @return returns a behavior model
 */
public BehaviorModel convert(final UserSession session) {
    final BehaviorModel model = new BehaviorModel();
    model.setName(this.prefix);
    final List<EntryCallEvent> entryCalls = session.getEvents();
    final Iterator<EntryCallEvent> iterator = entryCalls.iterator();
    // Assume list has at least one element
    if (iterator.hasNext()) {
        EntryCallNode lastNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
        EntryCallNode currentNode;
        while (iterator.hasNext()) {
            currentNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
            model.addNode(currentNode, true);
            model.addEdge(new EntryCallEdge(lastNode, currentNode), false);
            lastNode = currentNode;
        }
        return model;
    } else {
        SessionToBehaviorModelTransformation.LOGGER.error("Empty user session creates empty model");
        return model;
    }
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 4 with BehaviorModel

use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.

the class ModelComparisonStageTest method createTestModel.

private BehaviorModel createTestModel() {
    final BehaviorModel model = new BehaviorModel();
    model.addNode(this.nodeAtest, false);
    model.addNode(this.nodeBtest, false);
    model.addNode(this.nodeDtest, false);
    final EntryCallEdge edgeAB = new EntryCallEdge(this.nodeAtest, this.nodeBtest);
    edgeAB.addCalls(4);
    model.addEdge(edgeAB, false);
    final EntryCallEdge edgeBA = new EntryCallEdge(this.nodeBtest, this.nodeAtest);
    edgeBA.addCalls(3);
    model.addEdge(edgeBA, false);
    final EntryCallEdge edgeBD = new EntryCallEdge(this.nodeBtest, this.nodeDtest);
    edgeBA.addCalls(1);
    model.addEdge(edgeBD, false);
    return model;
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 5 with BehaviorModel

use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.

the class BehaviorModelJSONReader method execute.

@Override
protected void execute() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    /**
     * Have to read the model by hand
     */
    final JsonNode tree = mapper.readTree(this.inputFile);
    if (!(tree instanceof ObjectNode)) {
        throw new IOException("Wrong format while reading model.");
    }
    final ObjectNode modelNode = (ObjectNode) tree;
    final BehaviorModel model = new BehaviorModel();
    /**
     * Read name.
     */
    final JsonNode name = modelNode.get("name");
    if (name.isTextual()) {
        model.setName(name.textValue());
    }
    // Read nodes
    final JsonNode nodesNode = modelNode.get("nodes");
    if (nodesNode.isArray()) {
        final ArrayNode nodesArray = (ArrayNode) nodesNode;
        final Iterator<JsonNode> nodesIter = nodesArray.elements();
        while (nodesIter.hasNext()) {
            final EntryCallNode newECNode = new EntryCallNode();
            final ObjectNode node = (ObjectNode) nodesIter.next();
            newECNode.setSignature(node.get("signature").textValue());
            final ArrayNode callInfos = (ArrayNode) node.get("entryCallInformation");
            final Iterator<JsonNode> callInfoIter = callInfos.elements();
            while (callInfoIter.hasNext()) {
                final ObjectNode ciNode = (ObjectNode) callInfoIter.next();
                final CallInformation info = new CallInformation(ciNode.get("informationSignature").textValue(), ciNode.get("informationCode").textValue(), ciNode.get("count").asInt());
                newECNode.mergeCallInformation(info);
            }
            model.addNode(newECNode, false);
        }
    }
    final ArrayNode edgesNode = (ArrayNode) modelNode.findValue("edges");
    final Iterator<JsonNode> edgesIter = edgesNode.elements();
    while (edgesIter.hasNext()) {
        final ObjectNode edge = (ObjectNode) edgesIter.next();
        final ObjectNode source = (ObjectNode) edge.get("source");
        final ObjectNode target = (ObjectNode) edge.get("target");
        final EntryCallNode sourceECNode = model.findNode(source.get("signature").textValue()).get();
        final EntryCallNode targetECNode = model.findNode(target.get("signature").textValue()).get();
        final EntryCallEdge newECEdge = new EntryCallEdge(sourceECNode, targetECNode, edge.get("calls").asInt());
        model.addEdge(newECEdge, false);
    }
    this.outputPort.send(model);
    this.workCompleted();
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

BehaviorModel (org.iobserve.analysis.behavior.models.extended.BehaviorModel)13 EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)9 EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)6 List (java.util.List)3 Optional (java.util.Optional)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)2 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)2 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)2 Branch (org.palladiosimulator.pcm.usagemodel.Branch)2 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)2 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)2 Loop (org.palladiosimulator.pcm.usagemodel.Loop)2 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)2 Start (org.palladiosimulator.pcm.usagemodel.Start)2 Stop (org.palladiosimulator.pcm.usagemodel.Stop)2 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)2 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)2 AbstractConsumerStage (teetime.framework.AbstractConsumerStage)2