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);
}
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());
}
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());
}
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);
}
Aggregations