Search in sources :

Example 6 with PayloadAwareEntryCallEvent

use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.

the class GraphEditDistance method eventGroupInsertionCost.

/**
 * calculates the insertion cost of an eventgroup including the insertion cost of the events
 */
private double eventGroupInsertionCost(final EventGroup eventGroup) {
    double distance = GraphEditDistance.eventGroupInsertCost;
    final Queue<PayloadAwareEntryCallEvent> queue = new LinkedList<>(eventGroup.getEvents());
    final List<PayloadAwareEntryCallEvent> equalEvents = new ArrayList<>();
    while (!queue.isEmpty()) {
        final PayloadAwareEntryCallEvent event1 = queue.poll();
        // look for equal events, as they can be duplicated, instead of created
        for (final PayloadAwareEntryCallEvent event2 : queue) {
            if (GraphEditDistance.haveSameValues(event1, event2)) {
                equalEvents.add(event2);
            }
        }
        queue.removeAll(equalEvents);
        distance += equalEvents.size() * GraphEditDistance.WEIGTHING.getDuplicateCost(event1.getParameters());
        distance += GraphEditDistance.WEIGTHING.getInsertCost(event1.getParameters());
    }
    return distance;
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 7 with PayloadAwareEntryCallEvent

use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.

the class UserSessionToModelGeneratorTest method setup.

@Before
public void setup() {
    final String[] parameters1 = { "view A" };
    final String[] values1 = { "" };
    final PayloadAwareEntryCallEvent event1 = TestHelper.createEvent(1, "A", parameters1, values1);
    final String[] parameters2 = { "view B" };
    final String[] values2 = { "" };
    final PayloadAwareEntryCallEvent event2 = TestHelper.createEvent(2, "B", parameters2, values2);
    final String[] parameters3 = { "stay at B" };
    final String[] values3 = { "with value 1" };
    final PayloadAwareEntryCallEvent event3 = TestHelper.createEvent(3, "B", parameters3, values3);
    final String[] parameters4 = { "stay at B" };
    final String[] values4 = { "with value 2" };
    final PayloadAwareEntryCallEvent event4 = TestHelper.createEvent(4, "B", parameters4, values4);
    final String[] parameters5 = { "stay at B with other parameter name" };
    final String[] values5 = { "" };
    final PayloadAwareEntryCallEvent event5 = TestHelper.createEvent(5, "B", parameters5, values5);
    this.session = new UserSession("", "");
    this.session.add(event1);
    this.session.add(event2);
    this.session.add(event3);
    this.session.add(event4);
    this.session.add(event5);
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession) Before(org.junit.Before)

Example 8 with PayloadAwareEntryCallEvent

use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.

the class UserSessionToModelConverter method eventsToModel.

/**
 * Converts a list of events into a behavior model
 *
 * @param events
 *            The list of events
 * @return The behavior model
 */
public static BehaviorModelGED eventsToModel(final List<EntryCallEvent> events) {
    final BehaviorModelGED model = new BehaviorModelGED();
    final Iterator<EntryCallEvent> iterator = events.iterator();
    // start with the node "init"
    BehaviorModelNode currentNode = new BehaviorModelNode("Init");
    model.getNodes().put("Init", currentNode);
    BehaviorModelNode lastNode = currentNode;
    // for all events
    while (iterator.hasNext()) {
        final PayloadAwareEntryCallEvent event = (PayloadAwareEntryCallEvent) iterator.next();
        // current node is an existing node with the same name or if non-existing a new node
        currentNode = model.getNodes().get(event.getOperationSignature());
        if (currentNode == null) {
            currentNode = new BehaviorModelNode(event.getOperationSignature());
        }
        // add node to model
        model.getNodes().put(event.getOperationSignature(), currentNode);
        // add edge to model
        UserSessionToModelConverter.addEdge(event, model, lastNode, currentNode);
        lastNode = currentNode;
    }
    return model;
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED)

Example 9 with PayloadAwareEntryCallEvent

use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.

the class GraphEditDistance method eventGroupDistance.

/**
 * Calculates the distance between two event groups. This includes the distance between the
 * contained events
 */
private double eventGroupDistance(final EventGroup eventGroup1, final EventGroup eventGroup2) {
    double distance = 0;
    // at first all events are unvisited
    final Queue<PayloadAwareEntryCallEvent> unvisitedEvents1 = new LinkedList<>(eventGroup1.getEvents());
    final Queue<PayloadAwareEntryCallEvent> unvisitedEvents2 = new LinkedList<>(eventGroup2.getEvents());
    while (!unvisitedEvents1.isEmpty()) {
        final List<PayloadAwareEntryCallEvent> matches1 = new ArrayList<>();
        final List<PayloadAwareEntryCallEvent> matches2 = new ArrayList<>();
        final PayloadAwareEntryCallEvent event = unvisitedEvents1.poll();
        matches1.add(event);
        // find equal events in same event group
        for (final PayloadAwareEntryCallEvent potentialMatch : unvisitedEvents1) {
            if (GraphEditDistance.haveSameValues(event, potentialMatch)) {
                matches1.add(potentialMatch);
            }
        }
        unvisitedEvents1.removeAll(matches1);
        // find equal events in other event group
        for (final PayloadAwareEntryCallEvent potentialMatch : unvisitedEvents2) {
            if (GraphEditDistance.haveSameValues(event, potentialMatch)) {
                matches2.add(potentialMatch);
            }
        }
        unvisitedEvents2.removeAll(matches2);
        // events have to be created in other eventgroup
        if (matches2.isEmpty()) {
            distance += GraphEditDistance.WEIGTHING.getInsertCost(event.getParameters());
            distance += GraphEditDistance.WEIGTHING.getDuplicateCost(event.getParameters()) * (matches1.size() - 1);
        } else {
            // event occurs in both groups, so it has to be duplicated, till amount is the
            // same
            final int amountDifference = Math.abs(matches1.size() - matches2.size());
            distance += GraphEditDistance.WEIGTHING.getDuplicateCost(event.getParameters()) * amountDifference;
        }
    }
    // maybe some events are left in the second group, which weren't in the first group
    while (!unvisitedEvents2.isEmpty()) {
        final PayloadAwareEntryCallEvent event1 = unvisitedEvents2.poll();
        final List<PayloadAwareEntryCallEvent> equalEvents = new ArrayList<>();
        for (final PayloadAwareEntryCallEvent event2 : unvisitedEvents2) {
            if (GraphEditDistance.haveSameValues(event1, event2)) {
                equalEvents.add(event2);
            }
        }
        unvisitedEvents2.removeAll(equalEvents);
        distance += equalEvents.size() * GraphEditDistance.WEIGTHING.getDuplicateCost(event1.getParameters());
        distance += GraphEditDistance.WEIGTHING.getInsertCost(event1.getParameters());
    }
    return distance;
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 10 with PayloadAwareEntryCallEvent

use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.

the class BehaviorModelTable method addInformation.

@Override
public void addInformation(final PayloadAwareEntryCallEvent event) {
    final String eventSignature = this.getSignatureFromEvent(event);
    final List<CallInformation> newCallInformations = new ArrayList<>();
    try {
        for (int i = 0; i < event.getParameters().length; i++) {
            newCallInformations.add(new CallInformation(event.getParameters()[i], String.valueOf(this.parameterValueDoubleMapper.mapValue(event.getParameters()[i], event.getValues()[i]))));
        }
        final List<AggregatedCallInformation> aggCallInformations = Arrays.asList(this.signatures.get(eventSignature).getSecond());
        for (final CallInformation newCallInformation : newCallInformations) {
            // add new CallInfromation to the aggregation correctly
            final Optional<AggregatedCallInformation> match = aggCallInformations.stream().filter(aggCallInformation -> aggCallInformation.belongsTo(newCallInformation)).collect(new SingleOrNoneCollector<>());
            match.ifPresent(aggCallInformation -> aggCallInformation.addCallInformation(newCallInformation));
        }
    } catch (final IllegalArgumentException e) {
        BehaviorModelTable.LOGGER.error("Illegal argument exception", e);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FastVector(weka.core.FastVector) Pair(org.apache.commons.math3.util.Pair) Instances(weka.core.Instances) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) Instance(weka.core.Instance) List(java.util.List) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Map(java.util.Map) Optional(java.util.Optional) Attribute(weka.core.Attribute) ArrayList(java.util.ArrayList)

Aggregations

PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)11 ArrayList (java.util.ArrayList)6 List (java.util.List)4 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 UserSession (org.iobserve.analysis.session.data.UserSession)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 Pair (org.apache.commons.math3.util.Pair)2 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)2 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)2 BehaviorModelGED (org.iobserve.service.behavior.analysis.model.BehaviorModelGED)2 BehaviorModelNode (org.iobserve.service.behavior.analysis.model.BehaviorModelNode)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2