Search in sources :

Example 1 with SingleOrNoneCollector

use of org.iobserve.analysis.behavior.SingleOrNoneCollector in project iobserve-analysis by research-iobserve.

the class DynamicBehaviorModelTable 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++) {
            final String value = String.valueOf(this.parameterValueDoubleMapper.mapValue(event.getParameters()[i], event.getValues()[i]));
            newCallInformations.add(new CallInformation(event.getParameters()[i], value));
        }
        // adding if no transition added yet
        if (!this.signatures.containsKey(eventSignature)) {
            this.addSignature(eventSignature);
        }
        final List<AggregatedCallInformation> aggCallInformations = 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<AggregatedCallInformation>());
            if (match.isPresent()) {
                match.get().addCallInformation(newCallInformation);
            } else {
                // add new Callinformation
                final AggregatedCallInformation newAggregatedCallInformation = new AggregatedCallInformation(this.strategy, newCallInformation);
                aggCallInformations.add(newAggregatedCallInformation);
            }
        }
    } catch (final IllegalArgumentException e) {
        DynamicBehaviorModelTable.LOGGER.error("Exception while adding information to behavior table", e);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Pair(org.apache.commons.math3.util.Pair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) IRepresentativeStrategy(org.iobserve.analysis.behavior.models.data.configuration.IRepresentativeStrategy) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) 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) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList)

Example 2 with SingleOrNoneCollector

use of org.iobserve.analysis.behavior.SingleOrNoneCollector 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

ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)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 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)2 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 IRepresentativeStrategy (org.iobserve.analysis.behavior.models.data.configuration.IRepresentativeStrategy)1 Attribute (weka.core.Attribute)1 FastVector (weka.core.FastVector)1