Search in sources :

Example 1 with AssessmentMembersStatistics

use of org.olat.modules.assessment.model.AssessmentMembersStatistics in project OpenOLAT by OpenOLAT.

the class AssessmentToolManagerImpl method getNumberOfParticipants.

@Override
public AssessmentMembersStatistics getNumberOfParticipants(Identity coach, SearchAssessedIdentityParams params) {
    RepositoryEntry courseEntry = params.getEntry();
    int loggedIn = 0;
    int numOfOtherUsers = 0;
    int numOfParticipants = 0;
    int participantLoggedIn = 0;
    StringBuilder sc = new StringBuilder();
    sc.append("select infos.identity.key from usercourseinfos as infos ").append(" inner join infos.resource as infosResource on (infosResource.key=:resourceKey)");
    List<Long> allKeys = dbInstance.getCurrentEntityManager().createQuery(sc.toString(), Long.class).setParameter("resourceKey", courseEntry.getOlatResource().getKey()).getResultList();
    if (params.isAdmin()) {
        StringBuilder sb = new StringBuilder();
        sb.append("select participant.identity.key from repoentrytogroup as rel").append("  inner join rel.group as bGroup").append("  inner join bGroup.members as participant on (participant.role='").append(GroupRoles.participant.name()).append("')").append("  where rel.entry.key=:repoEntryKey");
        List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class).setParameter("repoEntryKey", courseEntry.getKey()).getResultList();
        Set<Long> participantKeys = new HashSet<>(keys);
        numOfParticipants = participantKeys.size();
        Set<Long> participantLoggedInKeys = new HashSet<>(allKeys);
        participantLoggedInKeys.retainAll(participantKeys);
        participantLoggedIn = participantLoggedInKeys.size();
        // count the users which login but are not members of the course
        if (params.isNonMembers()) {
            Set<Long> allLoggedInKeys = new HashSet<>(allKeys);
            allLoggedInKeys.removeAll(participantLoggedInKeys);
            loggedIn = allLoggedInKeys.size();
            allLoggedInKeys.removeAll(participantKeys);
            numOfOtherUsers = allLoggedInKeys.size();
        } else {
            loggedIn = participantLoggedIn;
        }
    } else if (params.isBusinessGroupCoach() || params.isRepositoryEntryCoach()) {
        StringBuilder sb = new StringBuilder();
        sb.append("select participant.identity.key from repoentrytogroup as rel").append("  inner join rel.group as bGroup").append("  inner join bGroup.members as coach on (coach.identity.key=:identityKey and coach.role='").append(GroupRoles.coach.name()).append("')").append("  inner join bGroup.members as participant on (participant.role='").append(GroupRoles.participant.name()).append("')").append("  where rel.entry.key=:repoEntryKey");
        List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class).setParameter("identityKey", coach.getKey()).setParameter("repoEntryKey", courseEntry.getKey()).getResultList();
        Set<Long> participantKeys = new HashSet<>(keys);
        numOfParticipants = participantKeys.size();
        Set<Long> participantLoggedInKeys = new HashSet<>(allKeys);
        participantLoggedInKeys.retainAll(participantKeys);
        participantLoggedIn = participantLoggedInKeys.size();
        loggedIn = participantLoggedIn;
    }
    return new AssessmentMembersStatistics(numOfParticipants, participantLoggedIn, numOfOtherUsers, loggedIn);
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) HashSet(java.util.HashSet)

Example 2 with AssessmentMembersStatistics

use of org.olat.modules.assessment.model.AssessmentMembersStatistics in project openolat by klemens.

the class AssessmentToolManagerTest method assessmentTool_coach.

@Test
public void assessmentTool_coach() {
    // course
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-author-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "course-assessment-tool", "course long name", null);
    // members as participant and coach
    Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-1");
    Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-2");
    Identity assessedIdentity3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-3");
    Identity assessedIdentity4 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-4");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-coach-1");
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-1", "assessment-tool-bg-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, entry);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-2", "assessment-tool-bg-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, entry);
    businessGroupRelationDao.addRole(assessedIdentity1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity2, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity3, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, group1, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // some datas
    assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 5.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity3, null, entry, subIdent, refEntry, 8.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity4, null, entry, subIdent, refEntry, 9.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(null, UUID.randomUUID().toString(), entry, subIdent, refEntry);
    dbInstance.commitAndCloseSession();
    // coach of group 1 with id 1 and id2
    List<BusinessGroup> coachedGroups = Collections.singletonList(group1);
    AssessmentToolSecurityCallback assessmentCallback = new AssessmentToolSecurityCallback(false, false, false, true, coachedGroups);
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(entry, subIdent, refEntry, assessmentCallback);
    // statistics
    AssessmentStatistics statistics = assessmentToolManager.getStatistics(coach, params);
    Assert.assertEquals(4.0d, statistics.getAverageScore().doubleValue(), 0.0001);
    Assert.assertEquals(1, statistics.getCountFailed());
    Assert.assertEquals(1, statistics.getCountPassed());
    // check assessed identities list
    List<Identity> assessedIdentities = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentities);
    Assert.assertEquals(2, assessedIdentities.size());
    // number of assessed identities
    int numOfAssessedIdentities = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentities);
    // check only the queries
    AssessmentMembersStatistics participantStatistics = assessmentToolManager.getNumberOfParticipants(coach, params);
    Assert.assertNotNull(participantStatistics);
    int numOfInitialLanches = assessmentToolManager.getNumberOfInitialLaunches(coach, params);
    // not launched, only simulated
    Assert.assertEquals(0, numOfInitialLanches);
    List<IdentityShort> assessedShortIdentities = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentities);
    Assert.assertEquals(2, assessedShortIdentities.size());
    List<AssessmentEntry> assessmentEntries = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntries);
    Assert.assertEquals(0, assessmentEntries.size());
    // separate check with more options in the search parameters
    // add by group key
    params.setBusinessGroupKeys(Collections.singletonList(group1.getKey()));
    // assessed groups
    List<AssessedBusinessGroup> assessedGroups = assessmentToolManager.getBusinessGroupStatistics(coach, params);
    Assert.assertNotNull(assessedGroups);
    Assert.assertEquals(1, assessedGroups.size());
    // check assessed identities list
    List<Identity> assessedIdentitiesAlt = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentitiesAlt);
    Assert.assertEquals(2, assessedIdentitiesAlt.size());
    // number of assessed identities
    int numOfAssessedIdentitiesAlt = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentitiesAlt);
    List<IdentityShort> assessedShortIdentitiesAlt = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentitiesAlt);
    Assert.assertEquals(2, assessedShortIdentitiesAlt.size());
    List<AssessmentEntry> assessmentEntriesAlt = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntriesAlt);
    Assert.assertEquals(0, assessmentEntriesAlt.size());
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) BusinessGroup(org.olat.group.BusinessGroup) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) IdentityShort(org.olat.basesecurity.IdentityShort) AssessmentToolSecurityCallback(org.olat.modules.assessment.ui.AssessmentToolSecurityCallback) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) AssessmentStatistics(org.olat.course.assessment.model.AssessmentStatistics) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with AssessmentMembersStatistics

use of org.olat.modules.assessment.model.AssessmentMembersStatistics in project OpenOLAT by OpenOLAT.

the class AssessmentToolManagerTest method assessmentTool_coach.

@Test
public void assessmentTool_coach() {
    // course
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-author-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "course-assessment-tool", "course long name", null);
    // members as participant and coach
    Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-1");
    Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-2");
    Identity assessedIdentity3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-3");
    Identity assessedIdentity4 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-4");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-coach-1");
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-1", "assessment-tool-bg-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, entry);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-2", "assessment-tool-bg-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, entry);
    businessGroupRelationDao.addRole(assessedIdentity1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity2, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity3, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, group1, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // some datas
    assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 5.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity3, null, entry, subIdent, refEntry, 8.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity4, null, entry, subIdent, refEntry, 9.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(null, UUID.randomUUID().toString(), entry, subIdent, refEntry);
    dbInstance.commitAndCloseSession();
    // coach of group 1 with id 1 and id2
    List<BusinessGroup> coachedGroups = Collections.singletonList(group1);
    AssessmentToolSecurityCallback assessmentCallback = new AssessmentToolSecurityCallback(false, false, false, true, coachedGroups);
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(entry, subIdent, refEntry, assessmentCallback);
    // statistics
    AssessmentStatistics statistics = assessmentToolManager.getStatistics(coach, params);
    Assert.assertEquals(4.0d, statistics.getAverageScore().doubleValue(), 0.0001);
    Assert.assertEquals(1, statistics.getCountFailed());
    Assert.assertEquals(1, statistics.getCountPassed());
    // check assessed identities list
    List<Identity> assessedIdentities = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentities);
    Assert.assertEquals(2, assessedIdentities.size());
    // number of assessed identities
    int numOfAssessedIdentities = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentities);
    // check only the queries
    AssessmentMembersStatistics participantStatistics = assessmentToolManager.getNumberOfParticipants(coach, params);
    Assert.assertNotNull(participantStatistics);
    int numOfInitialLanches = assessmentToolManager.getNumberOfInitialLaunches(coach, params);
    // not launched, only simulated
    Assert.assertEquals(0, numOfInitialLanches);
    List<IdentityShort> assessedShortIdentities = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentities);
    Assert.assertEquals(2, assessedShortIdentities.size());
    List<AssessmentEntry> assessmentEntries = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntries);
    Assert.assertEquals(0, assessmentEntries.size());
    // separate check with more options in the search parameters
    // add by group key
    params.setBusinessGroupKeys(Collections.singletonList(group1.getKey()));
    // assessed groups
    List<AssessedBusinessGroup> assessedGroups = assessmentToolManager.getBusinessGroupStatistics(coach, params);
    Assert.assertNotNull(assessedGroups);
    Assert.assertEquals(1, assessedGroups.size());
    // check assessed identities list
    List<Identity> assessedIdentitiesAlt = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentitiesAlt);
    Assert.assertEquals(2, assessedIdentitiesAlt.size());
    // number of assessed identities
    int numOfAssessedIdentitiesAlt = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentitiesAlt);
    List<IdentityShort> assessedShortIdentitiesAlt = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentitiesAlt);
    Assert.assertEquals(2, assessedShortIdentitiesAlt.size());
    List<AssessmentEntry> assessmentEntriesAlt = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntriesAlt);
    Assert.assertEquals(0, assessmentEntriesAlt.size());
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) BusinessGroup(org.olat.group.BusinessGroup) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) IdentityShort(org.olat.basesecurity.IdentityShort) AssessmentToolSecurityCallback(org.olat.modules.assessment.ui.AssessmentToolSecurityCallback) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) AssessmentStatistics(org.olat.course.assessment.model.AssessmentStatistics) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 4 with AssessmentMembersStatistics

use of org.olat.modules.assessment.model.AssessmentMembersStatistics in project openolat by klemens.

the class AssessmentToolManagerImpl method getNumberOfParticipants.

@Override
public AssessmentMembersStatistics getNumberOfParticipants(Identity coach, SearchAssessedIdentityParams params) {
    RepositoryEntry courseEntry = params.getEntry();
    int loggedIn = 0;
    int numOfOtherUsers = 0;
    int numOfParticipants = 0;
    int participantLoggedIn = 0;
    StringBuilder sc = new StringBuilder();
    sc.append("select infos.identity.key from usercourseinfos as infos ").append(" inner join infos.resource as infosResource on (infosResource.key=:resourceKey)");
    List<Long> allKeys = dbInstance.getCurrentEntityManager().createQuery(sc.toString(), Long.class).setParameter("resourceKey", courseEntry.getOlatResource().getKey()).getResultList();
    if (params.isAdmin()) {
        StringBuilder sb = new StringBuilder();
        sb.append("select participant.identity.key from repoentrytogroup as rel").append("  inner join rel.group as bGroup").append("  inner join bGroup.members as participant on (participant.role='").append(GroupRoles.participant.name()).append("')").append("  where rel.entry.key=:repoEntryKey");
        List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class).setParameter("repoEntryKey", courseEntry.getKey()).getResultList();
        Set<Long> participantKeys = new HashSet<>(keys);
        numOfParticipants = participantKeys.size();
        Set<Long> participantLoggedInKeys = new HashSet<>(allKeys);
        participantLoggedInKeys.retainAll(participantKeys);
        participantLoggedIn = participantLoggedInKeys.size();
        // count the users which login but are not members of the course
        if (params.isNonMembers()) {
            Set<Long> allLoggedInKeys = new HashSet<>(allKeys);
            allLoggedInKeys.removeAll(participantLoggedInKeys);
            loggedIn = allLoggedInKeys.size();
            allLoggedInKeys.removeAll(participantKeys);
            numOfOtherUsers = allLoggedInKeys.size();
        } else {
            loggedIn = participantLoggedIn;
        }
    } else if (params.isBusinessGroupCoach() || params.isRepositoryEntryCoach()) {
        StringBuilder sb = new StringBuilder();
        sb.append("select participant.identity.key from repoentrytogroup as rel").append("  inner join rel.group as bGroup").append("  inner join bGroup.members as coach on (coach.identity.key=:identityKey and coach.role='").append(GroupRoles.coach.name()).append("')").append("  inner join bGroup.members as participant on (participant.role='").append(GroupRoles.participant.name()).append("')").append("  where rel.entry.key=:repoEntryKey");
        List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class).setParameter("identityKey", coach.getKey()).setParameter("repoEntryKey", courseEntry.getKey()).getResultList();
        Set<Long> participantKeys = new HashSet<>(keys);
        numOfParticipants = participantKeys.size();
        Set<Long> participantLoggedInKeys = new HashSet<>(allKeys);
        participantLoggedInKeys.retainAll(participantKeys);
        participantLoggedIn = participantLoggedInKeys.size();
        loggedIn = participantLoggedIn;
    }
    return new AssessmentMembersStatistics(numOfParticipants, participantLoggedIn, numOfOtherUsers, loggedIn);
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) HashSet(java.util.HashSet)

Aggregations

AssessmentMembersStatistics (org.olat.modules.assessment.model.AssessmentMembersStatistics)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.Test)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 Identity (org.olat.core.id.Identity)2 ICourse (org.olat.course.ICourse)2 AssessedBusinessGroup (org.olat.course.assessment.model.AssessedBusinessGroup)2 AssessmentStatistics (org.olat.course.assessment.model.AssessmentStatistics)2 SearchAssessedIdentityParams (org.olat.course.assessment.model.SearchAssessedIdentityParams)2 BusinessGroup (org.olat.group.BusinessGroup)2 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)2 AssessmentToolSecurityCallback (org.olat.modules.assessment.ui.AssessmentToolSecurityCallback)2