use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.
the class JPetStoreParameterMetric method getNodeDistance.
private double getNodeDistance(final EntryCallNode nodeA, final EntryCallNode nodeB) {
final CallInformation[] ciA = nodeA.getEntryCallInformation();
final CallInformation[] ciB = nodeB.getEntryCallInformation();
// Distance is none if both have no call info
if (ciA.length == 0 && ciB.length == 0) {
return 0;
}
int distance = 0;
// Find out call info type (always homogenous for the same node type). Note that
// one of these arrays has to contain at least one item due to previous
// condition.
final CallInformation sample = ciA.length > 0 ? ciA[0] : ciB[0];
final boolean comparingItems = sample.getInformationSignature().equals("itemId");
final boolean comparingProducts = sample.getInformationSignature().equals("productId");
final boolean comparingCategories = sample.getInformationSignature().equals("categoryId");
// Return if unknown information signature
if (!(comparingItems || comparingProducts || comparingCategories)) {
return 0;
}
// Match equal call info (all types)
for (int a = 0; a < ciA.length; a++) {
for (int b = 0; b < ciB.length; b++) {
if (ciA[a].hasSameParameters(ciB[b])) {
this.matchCounts(a, b, ciA, ciB);
break;
}
}
}
// Match call info of same product (items only)
if (comparingItems) {
for (int a = 0; a < ciA.length; a++) {
for (int b = 0; b < ciB.length; b++) {
// Skip trying to match this if either have been matched completely
if (ciA[a].getCount() == 0 || ciB[b].getCount() == 0) {
continue;
}
if (this.hasSameProduct(ciA[a], ciB[b])) {
this.matchCounts(a, b, ciA, ciB);
distance += 1;
break;
}
}
}
}
// Match call info of same category (items and products only)
if (comparingItems || comparingProducts) {
for (int a = 0; a < ciA.length; a++) {
for (int b = 0; b < ciB.length; b++) {
// Skip trying to match this if either have been matched completely
if (ciA[a].getCount() == 0 || ciB[b].getCount() == 0) {
continue;
}
if (this.hasSameCategory(ciA[a], ciB[b])) {
this.matchCounts(a, b, ciA, ciB);
// Add distance of 1 when comparing products, distance of 2 for items
distance += comparingItems ? 2 : 1;
break;
}
}
}
}
// Find remaining non-matched call infos and match them, adding 1, 2 or 3
// distance for
// each match when comparing categories, products or items respectively, and 4
// distance for any remaining call infos in either node when
// the other one is empty
final int distanceFactor = 3 - (comparingProducts ? 1 : 0) - (comparingCategories ? 2 : 0);
int remainingA = 0;
int remainingB = 0;
for (final CallInformation c : ciA) {
remainingA += c.getCount();
}
for (final CallInformation c : ciB) {
remainingB += c.getCount();
}
final int remainingDiff = Math.abs(remainingA - remainingB);
// Distance for every matchable element
distance += Math.min(remainingA, remainingB) * distanceFactor;
// Distance for every unmatchable element
distance += remainingDiff * 4;
return distance;
}
use of org.iobserve.analysis.behavior.models.extended.CallInformation 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);
}
}
use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.
the class BehaviorModelTable method toInstances.
/**
* create an Instances object for clustering.
*
* @return instance
*/
public Instances toInstances() {
final FastVector fastVector = new FastVector();
// add transitions
for (int i = 0; i < this.signatures.size(); i++) {
for (int j = 0; j < this.signatures.size(); j++) {
if (this.transitions[i][j] > AbstractBehaviorModelTable.TRANSITION_THRESHOLD) {
final Attribute attribute = new Attribute(AbstractBehaviorModelTable.EDGE_INDICATOR + this.inverseSignatures[i] + AbstractBehaviorModelTable.EDGE_DIVIDER + this.inverseSignatures[j]);
fastVector.addElement(attribute);
} else {
continue;
}
}
}
// add informations
this.signatures.values().stream().forEach(pair -> Arrays.stream(pair.getSecond()).forEach(callInformation -> fastVector.addElement(new Attribute(AbstractBehaviorModelTable.INFORMATION_INDICATOR + this.inverseSignatures[pair.getFirst()] + AbstractBehaviorModelTable.INFORMATION_DIVIDER + callInformation.getSignature()))));
// TODO name
final Instances instances = new Instances("Test", fastVector, 0);
final Instance instance = this.toInstance();
instances.add(instance);
return instances;
}
use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.
the class BehaviorModelCreationStage method createNode.
/**
* Creates an node from a node representing attribute string and value.
*
* @param name
* attribute name
* @param value
* attribute value
*
* @return EntryCallNode
*/
private Optional<EntryCallNode> createNode(final String name, final Double value) {
final String[] signatures = this.splitSignature(AbstractBehaviorModelTable.INFORMATION_INDICATOR_PATTERN, AbstractBehaviorModelTable.INFORMATION_DIVIDER_PATTERN, name);
if (signatures.length == 2) {
final EntryCallNode node = new EntryCallNode(signatures[0]);
final CallInformation callInformation = new CallInformation(signatures[1], value.toString());
node.mergeCallInformation(callInformation);
return Optional.of(node);
} else {
return Optional.empty();
}
}
use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.
the class IntersectionModelGenerationStrategy method intersectNode.
private EntryCallNode intersectNode(final EntryCallNode a, final EntryCallNode b) {
final EntryCallNode result = new EntryCallNode();
result.setSignature(a.getSignature());
Optional<CallInformation> matchingInfo;
for (final CallInformation infoA : a.getEntryCallInformation()) {
matchingInfo = b.findCallInformation(infoA.getInformationSignature(), infoA.getInformationParameter());
if (matchingInfo.isPresent()) {
final int newCalls = Math.min(infoA.getCount(), matchingInfo.get().getCount());
final CallInformation newInfo = new CallInformation(infoA.getInformationSignature(), infoA.getInformationParameter(), newCalls);
result.mergeCallInformation(newInfo);
}
}
return result;
}
Aggregations