Search in sources :

Example 1 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class ClusteringPrePostProcessing method getForEachUserGroupAnEntryCallSequenceModel.

/**
 * It creates for each cluster(user group) its own entryCallSequenceModel. For that, each
 * entryCallSequenceModel receives exclusively the user group's assigned user sessions obtained
 * via the clustering. Additionally each entryCallSequenceModel receives the user group's
 * occurrence likelihood within the considered user sessions.
 *
 * @param clusteringResults
 *            hold the assignments of the clustering and the number of clusters
 * @param callSequenceModel
 *            is the input entryCallSequenceModel that holds all user sessions
 * @return for each cluster one entryCallSequenceModel. Each contains exclusively the cluster's
 *         assigned user sessions
 */
public List<EntryCallSequenceModel> getForEachUserGroupAnEntryCallSequenceModel(final ClusteringResults clusteringResults, final EntryCallSequenceModel callSequenceModel) {
    final int numberOfClusters = clusteringResults.getNumberOfClusters();
    final int[] assignments = clusteringResults.getAssignments();
    final List<EntryCallSequenceModel> entryCallSequenceModels = new ArrayList<>(numberOfClusters);
    final double countOfAbsoluteUserSessions = callSequenceModel.getUserSessions().size();
    for (int k = 0; k < numberOfClusters; k++) {
        final List<UserSession> sessions = new ArrayList<>();
        int instanceNumber = 0;
        double countOfAssigendUserSessions = 0;
        for (final int clusterNum : assignments) {
            if (clusterNum == k) {
                sessions.add(callSequenceModel.getUserSessions().get(instanceNumber));
                countOfAssigendUserSessions++;
            }
            instanceNumber++;
        }
        if (sessions.isEmpty()) {
            continue;
        }
        final double relativeFrequencyOfUserGroup = countOfAssigendUserSessions / countOfAbsoluteUserSessions;
        entryCallSequenceModels.add(new EntryCallSequenceModel(sessions, relativeFrequencyOfUserGroup));
    }
    return entryCallSequenceModels;
}
Also used : UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel)

Example 2 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class ClusteringEvaluation method performClustering.

/**
 * Executes the approach's extraction of user groups process and counts the assignments of user
 * sessions of each user group within each cluster to be able to calculate the misclassification
 * rate. Returns the sum of squared error of the clustering
 *
 * @return the sum of squared error of the executed clustering
 * @throws IOException
 */
private double performClustering() throws IOException {
    final UserGroupExtraction userGroupExtraction = new UserGroupExtraction(this.entryCallSequenceModel, 3, ClusteringEvaluation.VARIANCE_VALUE, true);
    userGroupExtraction.extractUserGroups();
    final List<EntryCallSequenceModel> entryCallSequenceModelsOfUserGroups = userGroupExtraction.getEntryCallSequenceModelsOfUserGroups();
    this.listOfClusterAssignmentsCounter = new ArrayList<>();
    for (int i = 0; i < entryCallSequenceModelsOfUserGroups.size(); i++) {
        final ClusterAssignmentsCounter clusterAssignments = new ClusterAssignmentsCounter();
        this.listOfClusterAssignmentsCounter.add(clusterAssignments);
    }
    int index = 0;
    for (final EntryCallSequenceModel entryCallSequence : entryCallSequenceModelsOfUserGroups) {
        for (final UserSession userSession : entryCallSequence.getUserSessions()) {
            if (userSession.getSessionId().equals(ClusteringEvaluation.CUSTOMER_TAG)) {
                this.listOfClusterAssignmentsCounter.get(index).increaseNumberOfUserGroupCustomer();
            } else if (userSession.getSessionId().equals(ClusteringEvaluation.STORE_MANAGER_TAG)) {
                this.listOfClusterAssignmentsCounter.get(index).increaseNumberOfUserGroupStoreManager();
            } else if (userSession.getSessionId().equals(ClusteringEvaluation.STOCK_MANAGER_TAG)) {
                this.listOfClusterAssignmentsCounter.get(index).increaseNumberOfUserGroupStockManager();
            }
        }
        index++;
    }
    return userGroupExtraction.getClusteringResults().getClusteringMetrics().getSumOfSquaredErrors();
}
Also used : UserSession(org.iobserve.analysis.session.data.UserSession) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel)

Example 3 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class TestHelper method getUserSessions.

/**
 * Creates new user sessions.
 *
 * @param numberOfUserSessionsToCreate
 *            defines the number of user sessions
 * @return new user sessions
 */
public static List<UserSession> getUserSessions(final int numberOfUserSessionsToCreate) {
    final List<UserSession> userSessions = new ArrayList<>();
    for (int i = 0; i < numberOfUserSessionsToCreate; i++) {
        final UserSession userSession = new UserSession("host", String.valueOf(i));
        userSessions.add(userSession);
    }
    return userSessions;
}
Also used : UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList)

Example 4 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class TBehaviorModelTableGeneration method execute.

@Override
protected void execute(final EntryCallSequenceModel entryCallSequenceModel) {
    final List<UserSession> userSessions = entryCallSequenceModel.getUserSessions();
    for (final UserSession userSession : userSessions) {
        final List<EntryCallEvent> entryCalls = userSession.getEvents();
        EntryCallEvent lastCall = null;
        for (final EntryCallEvent eventCall : entryCalls) {
            if (lastCall != null) {
                this.modelTable.addTransition(lastCall, eventCall);
                this.modelTable.addInformation(eventCall);
            } else {
                /**
                 * only called at first valid event (condition lastCall == null is not needed)
                 */
                this.modelTable.addInformation(eventCall);
            }
            lastCall = eventCall;
        }
    }
}
Also used : EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession)

Example 5 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class BranchWithinLoopReference method getModel.

/**
 * It creates a reference usage model that contains branches within loops. Accordingly, user
 * sessions whose call sequences differ from each other are iterated in a row. Thereby, at each
 * iteration of a branched call sequences the probabilities have to be equal because otherwise
 * it would not be an iteration (RQ-1.8)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModel
 *            repository model builder
 * @param correspondenceModel
 *            correspondence model
 *
 * @return reference usage model and corresponding user sessions
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final CorrespondenceModel correspondenceModel) throws IOException {
    // The number of model element parameters are created randomly. The number of user sessions
    // must be created accordingly to the number of branch transitions, because it must be
    // ensured that at each iteration of an branch the branch transition probabilities are
    // equal. This can be achieved by the same number of user sessions representing the branch
    // transition at each iteration
    final int numberOfLoops = TestHelper.getRandomInteger(3, 3);
    final int numberOfConcurrentUsers = (int) Math.pow(2, numberOfLoops) * 5;
    final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements testElements = new ReferenceElements();
    // In the following the reference usage model is created
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
    final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    final AbstractUserAction lastAction = start;
    // The loop element is created that contains the iterated branch
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    final ScenarioBehaviour loopScenarioBehaviour = loop.getBodyBehaviour_Loop();
    UsageModelFactory.connect(lastAction, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(numberOfLoops));
    // Set number of loops
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    final Start loopStart = UsageModelFactory.createAddStartAction("", loopScenarioBehaviour);
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loopScenarioBehaviour);
    // The branch that is contained within the loop element is created
    final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", loopScenarioBehaviour);
    UsageModelFactory.connect(loopStart, branch);
    // The branch transition 1 is created
    final BranchTransition branchTransition1 = BranchWithinLoopReference.createBranchTransition(2, repositoryLookupModel, branch, correspondenceModel);
    // The branch transition 2 is created
    final BranchTransition branchTransition2 = BranchWithinLoopReference.createBranchTransition(3, repositoryLookupModel, branch, correspondenceModel);
    final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
    if (operationSignature != null) {
        final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
        UsageModelFactory.addUserAction(loopScenarioBehaviour, entryLevelSystemCall);
        UsageModelFactory.connect(branch, entryLevelSystemCall);
        UsageModelFactory.connect(entryLevelSystemCall, loopStop);
    }
    // User sessions according to the reference usage model are created. Thereby, it must be
    // ensured that each iteration of the branch the branch probabilities stay the same because
    // the branch is iterated. This can be achieved by an equal number of user sessions for each
    // branch transition at each iteration of the branch
    int countOfCallEvent3 = 0;
    int countOfCallEvent4 = 0;
    int entryTime = 1;
    int exitTime = 2;
    boolean branchDecision = false;
    // At each iteration the user sessions are distributed equally between the branch
    // transitions to ensure that the probabilities of the branch transitions stay equally
    final Map<Integer, List<List<UserSession>>> userSessionGroups = new HashMap<>();
    final List<List<UserSession>> startList = new ArrayList<>();
    startList.add(entryCallSequenceModel.getUserSessions());
    userSessionGroups.put(0, startList);
    // The loop that contains the branch
    for (int j = 0; j < numberOfLoops; j++) {
        countOfCallEvent3 = 0;
        countOfCallEvent4 = 0;
        final List<List<UserSession>> newUserSessionGroups = new ArrayList<>();
        // Ensures that the user sessions distribution stays equally
        for (int k = 0; k < userSessionGroups.get(j).size(); k++) {
            for (int i = 0; i < 2; i++) {
                final List<UserSession> userSessions = new ArrayList<>();
                newUserSessionGroups.add(userSessions);
            }
            final int indexGroupCallEvent3 = newUserSessionGroups.size() - 2;
            final int indexGroupCallEvent4 = newUserSessionGroups.size() - 1;
            for (int i = 0; i < userSessionGroups.get(j).get(k).size(); i++) {
                if (newUserSessionGroups.get(indexGroupCallEvent3).size() > newUserSessionGroups.get(indexGroupCallEvent4).size()) {
                    branchDecision = false;
                } else {
                    branchDecision = true;
                }
                // The branch within the loop
                if (branchDecision) {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 2, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent3);
                    countOfCallEvent3++;
                    entryTime += 2;
                    exitTime += 2;
                } else {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 3, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent4);
                    countOfCallEvent4++;
                    entryTime += 2;
                    exitTime += 2;
                }
                final EntryCallEvent entryCallEvent5 = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4], ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], String.valueOf(i), "hostname");
                userSessionGroups.get(j).get(k).get(i).add(entryCallEvent5, true);
                entryTime -= 2;
                exitTime -= 2;
            }
        }
        userSessionGroups.put(j + 1, newUserSessionGroups);
        entryTime += 2;
        exitTime += 2;
    }
    // Sets the likelihoods of branch transitions
    final double likelihoodOfCallEvent3 = (double) countOfCallEvent3 / (double) numberOfConcurrentUsers;
    final double likelihoodOfCallEvent4 = (double) countOfCallEvent4 / (double) numberOfConcurrentUsers;
    branchTransition1.setBranchProbability(likelihoodOfCallEvent3);
    branchTransition2.setBranchProbability(likelihoodOfCallEvent4);
    // Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
    // as the reference elements. Our approach is now executed with the EntryCallSequenceModel
    // and the resulting usage model can be matched against the reference usage model
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    testElements.setEntryCallSequenceModel(entryCallSequenceModel);
    testElements.setUsageModel(usageModel);
    return testElements;
}
Also used : Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UserSession(org.iobserve.analysis.session.data.UserSession) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements) ArrayList(java.util.ArrayList) List(java.util.List) Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Aggregations

UserSession (org.iobserve.analysis.session.data.UserSession)39 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)16 ArrayList (java.util.ArrayList)14 UserSessionCollectionModel (org.iobserve.analysis.data.UserSessionCollectionModel)8 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)5 HashMap (java.util.HashMap)3 List (java.util.List)3 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)3 Random (java.util.Random)2 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)2 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)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 HashSet (java.util.HashSet)1