Search in sources :

Example 1 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge 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 EntryCallEdge

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

the class BehaviorModelCreationStage method createEdge.

/**
 * Creates an edge from an edge representing attribute string and value.
 *
 * @param name
 *            attribute name
 * @param value
 *            attribute value
 *
 * @return EntryCallEdge
 */
private Optional<EntryCallEdge> createEdge(final String name, final Double value) {
    // only create relevant edges
    final double roundedValue = Math.floor(value);
    if (roundedValue > 0.5) {
        final String[] nodeNames = this.splitSignature(AbstractBehaviorModelTable.EDGE_INDICATOR_PATTERN, AbstractBehaviorModelTable.EDGE_DIVIDER_PATTERN, name);
        if (nodeNames.length == 2) {
            final EntryCallNode from = new EntryCallNode(nodeNames[0]);
            final EntryCallNode to = new EntryCallNode(nodeNames[1]);
            // rount
            final EntryCallEdge edge = new EntryCallEdge(from, to, roundedValue);
            return Optional.of(edge);
        }
    }
    return Optional.empty();
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode)

Example 3 with EntryCallEdge

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

the class BehaviorModelVisualizationStage method createEdges.

/**
 * create new edges at visualization backend.
 *
 * @param entryCallEdges
 *            entryCallEdges
 * @param modelId
 *            modelId
 */
private void createEdges(final Collection<EntryCallEdge> entryCallEdges, final long modelId) {
    final ArrayNode edges = this.objectMapper.createArrayNode();
    for (final EntryCallEdge entryCallEdge : entryCallEdges) {
        final ObjectNode json = this.objectMapper.createObjectNode();
        final String sourceSignature = entryCallEdge.getSource().getSignature();
        final String targetSignature = entryCallEdge.getTarget().getSignature();
        json.put("id", 0);
        json.put("start", this.nodeMap.get(sourceSignature));
        json.put("end", this.nodeMap.get(targetSignature));
        json.put("action", String.format("%s->%s", sourceSignature, targetSignature));
        json.put("count", entryCallEdge.getCalls());
        this.postElement(json, this.getEdgeUrl(modelId));
        edges.add(json);
    }
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge 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 5 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge 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)

Aggregations

EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)15 BehaviorModel (org.iobserve.analysis.behavior.models.extended.BehaviorModel)8 EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)8 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Optional (java.util.Optional)2 NodeDifference (org.iobserve.evaluation.data.NodeDifference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)1 ComparisonResult (org.iobserve.evaluation.data.ComparisonResult)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1