Search in sources :

Example 6 with CourseStatEntry

use of org.olat.modules.coach.model.CourseStatEntry in project OpenOLAT by OpenOLAT.

the class CoachingDAOTest method getStatistics_emptyStatements_emptyCourseInfos.

/**
 * This is an important test to check if the return values of the statistics
 * are correctly handled because some of them can be null or 0.
 *
 * @throws URISyntaxException
 */
@Test
public void getStatistics_emptyStatements_emptyCourseInfos() throws URISyntaxException {
    URL coachingCourseUrl = CoachingLargeTest.class.getResource("CoachingCourse.zip");
    File coachingCourseFile = new File(coachingCourseUrl.toURI());
    RepositoryEntry re1 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
    RepositoryEntry re2 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
    dbInstance.commitAndCloseSession();
    // members of courses
    Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("Coach-1-" + UUID.randomUUID());
    repositoryService.addRole(coach, re1, GroupRoles.owner.name());
    repositoryService.addRole(coach, re2, GroupRoles.coach.name());
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-1");
    repositoryService.addRole(participant1, re1, GroupRoles.participant.name());
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-2");
    repositoryService.addRole(participant2, re1, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "Coaching-grp-1", "tg", null, null, false, false, re1);
    Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-3");
    businessGroupRelationDao.addRole(participant3, group1, GroupRoles.participant.name());
    Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-4");
    businessGroupRelationDao.addRole(participant4, group1, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // check groups statistics
    List<GroupStatEntry> nativeGroupStats = coachingDAO.getGroupsStatisticsNative(coach);
    Assert.assertNotNull(nativeGroupStats);
    Assert.assertEquals(1, nativeGroupStats.size());
    GroupStatEntry entryGroup1 = getGroupStatEntry(group1, nativeGroupStats);
    Assert.assertNotNull(entryGroup1);
    Assert.assertEquals(2, entryGroup1.getCountDistinctStudents());
    Assert.assertEquals(0, entryGroup1.getInitialLaunch());
    Assert.assertEquals(0, entryGroup1.getCountPassed());
    Assert.assertEquals(0, entryGroup1.getCountFailed());
    Assert.assertEquals(2, entryGroup1.getCountNotAttempted());
    Assert.assertNull(entryGroup1.getAverageScore());
    // courses
    List<CourseStatEntry> nativeCourseStats = coachingDAO.getCoursesStatisticsNative(coach);
    Assert.assertNotNull(nativeCourseStats);
    Assert.assertEquals(1, nativeCourseStats.size());
    // re 1
    CourseStatEntry entryCourse1 = getCourseStatEntry(re1, nativeCourseStats);
    Assert.assertNotNull(entryCourse1);
    Assert.assertEquals(4, entryCourse1.getCountStudents());
    Assert.assertEquals(0, entryCourse1.getInitialLaunch());
    Assert.assertEquals(0, entryCourse1.getCountPassed());
    Assert.assertEquals(0, entryCourse1.getCountFailed());
    Assert.assertEquals(4, entryCourse1.getCountNotAttempted());
    Assert.assertNull(entryCourse1.getAverageScore());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(UserListController.usageIdentifyer, false);
    // user native
    List<StudentStatEntry> nativeUserStats = coachingDAO.getStudentsStatisticsNative(coach, userPropertyHandlers);
    Assert.assertNotNull(nativeUserStats);
    Assert.assertEquals(4, nativeUserStats.size());
    // participants have all the same statistics
    Identity[] participants = new Identity[] { participant1, participant2, participant3, participant4 };
    for (Identity participant : participants) {
        StudentStatEntry entryParticipant = getStudentStatEntry(participant, nativeUserStats);
        Assert.assertNotNull(entryParticipant);
        Assert.assertEquals(0, entryParticipant.getCountPassed());
        Assert.assertEquals(0, entryParticipant.getCountFailed());
        Assert.assertEquals(1, entryParticipant.getCountNotAttempted());
        Assert.assertEquals(0, entryParticipant.getInitialLaunch());
        Assert.assertEquals(1, entryParticipant.getCountRepo());
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry) StudentStatEntry(org.olat.modules.coach.model.StudentStatEntry) CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) Identity(org.olat.core.id.Identity) File(java.io.File) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoachingLargeTest(org.olat.modules.coach.CoachingLargeTest) Test(org.junit.Test)

Example 7 with CourseStatEntry

use of org.olat.modules.coach.model.CourseStatEntry in project openolat by klemens.

the class CoachingDAOTest method getStatistics_empty.

/**
 * This is an important test to check if the return values of the statistics
 * are correctly handled because some of them can be null or 0.
 *
 * @throws URISyntaxException
 */
@Test
public void getStatistics_empty() throws URISyntaxException {
    URL coachingCourseUrl = CoachingLargeTest.class.getResource("CoachingCourse.zip");
    File coachingCourseFile = new File(coachingCourseUrl.toURI());
    RepositoryEntry re1 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
    RepositoryEntry re2 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
    dbInstance.commitAndCloseSession();
    // members of courses
    Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("Coach-1-" + UUID.randomUUID());
    repositoryService.addRole(coach, re1, GroupRoles.owner.name());
    repositoryService.addRole(coach, re2, GroupRoles.coach.name());
    // groups
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Coaching-grp-1", "tg", null, null, false, false, re1);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(group);
    // groups (method doesn't return courses without participant)
    List<GroupStatEntry> nativeGroupStats = coachingDAO.getGroupsStatisticsNative(coach);
    Assert.assertNotNull(nativeGroupStats);
    Assert.assertEquals(0, nativeGroupStats.size());
    // courses (method doesn't return courses without participant)
    List<CourseStatEntry> nativeCourseStats = coachingDAO.getCoursesStatisticsNative(coach);
    Assert.assertNotNull(nativeCourseStats);
    Assert.assertEquals(0, nativeCourseStats.size());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(UserListController.usageIdentifyer, false);
    // user native
    List<StudentStatEntry> nativeUserStats = coachingDAO.getStudentsStatisticsNative(coach, userPropertyHandlers);
    Assert.assertNotNull(nativeUserStats);
    Assert.assertEquals(0, nativeUserStats.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry) StudentStatEntry(org.olat.modules.coach.model.StudentStatEntry) CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) Identity(org.olat.core.id.Identity) File(java.io.File) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoachingLargeTest(org.olat.modules.coach.CoachingLargeTest) Test(org.junit.Test)

Example 8 with CourseStatEntry

use of org.olat.modules.coach.model.CourseStatEntry in project openolat by klemens.

the class CoachingDAOTest method getStatistics_duplicateInGroups.

/**
 * 1 course with 2 groups.
 *
 * @throws URISyntaxException
 */
@Test
public void getStatistics_duplicateInGroups() throws URISyntaxException {
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(UserListController.usageIdentifyer, false);
    URL courseWithForumsUrl = CoachingLargeTest.class.getResource("CoachingCourse.zip");
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString();
    RepositoryEntry re = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(re);
    dbInstance.commitAndCloseSession();
    ICourse course = CourseFactory.loadCourse(re);
    boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
    Assert.assertTrue(enabled);
    // re -> owner,coach, p1, p2
    // -> group 1 p1
    // -> group 2 p2
    // members of courses
    Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("Coach-1-" + UUID.randomUUID());
    repositoryService.addRole(coach, re, GroupRoles.owner.name());
    repositoryService.addRole(coach, re, GroupRoles.coach.name());
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-1");
    repositoryService.addRole(participant1, re, GroupRoles.participant.name());
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-2");
    repositoryService.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // members of 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(coach, "Coaching-grp-1", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(participant1, group1, GroupRoles.participant.name());
    BusinessGroup group2 = businessGroupService.createBusinessGroup(coach, "Coaching-grp-2", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(participant1, group2, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // make statements
    effManager.createUserEfficiencyStatement(new Date(), 6.0f, true, participant1, re.getOlatResource());
    effManager.createUserEfficiencyStatement(new Date(), 2.0f, false, participant2, re.getOlatResource());
    dbInstance.commitAndCloseSession();
    // make user infos
    userCourseInformationsManager.updateUserCourseInformations(course.getCourseEnvironment().getCourseGroupManager().getCourseResource(), participant1);
    dbInstance.commitAndCloseSession();
    // native
    List<CourseStatEntry> nativeStats = coachingDAO.getCoursesStatisticsNative(coach);
    Assert.assertNotNull(nativeStats);
    Assert.assertEquals(1, nativeStats.size());
    CourseStatEntry nativeStat = nativeStats.get(0);
    Assert.assertEquals(2, nativeStat.getCountStudents());
    Assert.assertEquals(1, nativeStat.getCountPassed());
    Assert.assertEquals(1, nativeStat.getCountFailed());
    Assert.assertEquals(1, nativeStat.getInitialLaunch());
    Assert.assertEquals(4.0f, nativeStat.getAverageScore(), 0.0001);
    // user native
    List<StudentStatEntry> nativeUserStats = coachingDAO.getStudentsStatisticsNative(coach, userPropertyHandlers);
    Assert.assertNotNull(nativeUserStats);
    Assert.assertEquals(2, nativeUserStats.size());
    // participant1
    StudentStatEntry entryParticipant1 = getStudentStatEntry(participant1, nativeUserStats);
    Assert.assertNotNull(entryParticipant1);
    Assert.assertEquals(1, entryParticipant1.getCountPassed());
    Assert.assertEquals(0, entryParticipant1.getCountFailed());
    Assert.assertEquals(0, entryParticipant1.getCountNotAttempted());
    Assert.assertEquals(1, entryParticipant1.getInitialLaunch());
    // participant2
    StudentStatEntry entryParticipant2 = getStudentStatEntry(participant2, nativeUserStats);
    Assert.assertNotNull(entryParticipant2);
    Assert.assertEquals(0, entryParticipant2.getCountPassed());
    Assert.assertEquals(1, entryParticipant2.getCountFailed());
    Assert.assertEquals(0, entryParticipant2.getCountNotAttempted());
    Assert.assertEquals(0, entryParticipant2.getInitialLaunch());
    // group native
    List<GroupStatEntry> nativeGroupStats = coachingDAO.getGroupsStatisticsNative(coach);
    Assert.assertNotNull(nativeGroupStats);
    Assert.assertEquals(2, nativeGroupStats.size());
    // group 1
    GroupStatEntry entryGroup1 = getGroupStatEntry(group1, nativeGroupStats);
    Assert.assertNotNull(entryGroup1);
    Assert.assertEquals(1, entryGroup1.getCountCourses());
    Assert.assertEquals(1, entryGroup1.getCountPassed());
    Assert.assertEquals(0, entryGroup1.getCountFailed());
    Assert.assertEquals(0, entryGroup1.getCountNotAttempted());
    Assert.assertEquals(1, entryGroup1.getInitialLaunch());
    Assert.assertEquals(6.0f, entryGroup1.getAverageScore(), 0.0001f);
    // group 2
    GroupStatEntry entryGroup2 = getGroupStatEntry(group1, nativeGroupStats);
    Assert.assertNotNull(entryGroup2);
    Assert.assertEquals(1, entryGroup2.getCountCourses());
    Assert.assertEquals(1, entryGroup2.getCountPassed());
    Assert.assertEquals(0, entryGroup2.getCountFailed());
    Assert.assertEquals(0, entryGroup2.getCountNotAttempted());
    Assert.assertEquals(1, entryGroup2.getInitialLaunch());
    Assert.assertEquals(6.0f, entryGroup2.getAverageScore(), 0.0001f);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) Date(java.util.Date) StudentStatEntry(org.olat.modules.coach.model.StudentStatEntry) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry) CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) Identity(org.olat.core.id.Identity) File(java.io.File) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoachingLargeTest(org.olat.modules.coach.CoachingLargeTest) Test(org.junit.Test)

Example 9 with CourseStatEntry

use of org.olat.modules.coach.model.CourseStatEntry in project openolat by klemens.

the class CoachingDAO method getCoursesStatisticsUserInfosForOwner.

private boolean getCoursesStatisticsUserInfosForOwner(Identity coach, Map<Long, CourseStatEntry> map) {
    NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
    if (dbInstance.isMySQL()) {
        sb.append("select").append("  sg_re.repositoryentry_id as re_id,").append("  count(distinct sg_participant.fk_identity_id) as student_id,").append("  count(distinct pg_initial_launch.id) as pg_id").append(" from o_repositoryentry sg_re ").append(" inner join o_re_to_group owngroup on (owngroup.fk_entry_id = sg_re.repositoryentry_id and owngroup.r_defgroup=").appendTrue().append(")").append(" inner join o_bs_group_member sg_coach on (sg_coach.fk_group_id=owngroup.fk_group_id and sg_coach.g_role = 'owner')").append(" inner join o_re_to_group togroup on (togroup.fk_entry_id = sg_re.repositoryentry_id)").append(" inner join o_bs_group_member sg_participant on (sg_participant.fk_group_id=togroup.fk_group_id and sg_participant.g_role='participant')").append(" left join o_as_user_course_infos pg_initial_launch").append("   on (pg_initial_launch.fk_resource_id = sg_re.fk_olatresource and pg_initial_launch.fk_identity = sg_participant.fk_identity_id)").append(" where sg_coach.fk_identity_id=:coachKey and sg_re.accesscode >= ").append(RepositoryEntry.ACC_OWNERS).append(" group by sg_re.repositoryentry_id");
    } else {
        sb.append("select").append("  sg_re.repositoryentry_id as re_id,").append("  count(distinct sg_participant.fk_identity_id) as student_id,").append("  count(distinct pg_initial_launch.id) as pg_id").append(" from o_repositoryentry sg_re ").append(" inner join o_re_to_group togroup on (togroup.fk_entry_id = sg_re.repositoryentry_id)").append(" inner join o_bs_group_member sg_participant on (sg_participant.fk_group_id=togroup.fk_group_id and sg_participant.g_role='participant')").append(" left join o_as_user_course_infos pg_initial_launch").append("   on (pg_initial_launch.fk_resource_id = sg_re.fk_olatresource and pg_initial_launch.fk_identity = sg_participant.fk_identity_id)").append(" where sg_re.accesscode >= ").append(RepositoryEntry.ACC_OWNERS).append(" and sg_re.fk_olatresource in (").append("  select sg_res.resource_id from o_olatresource sg_res where sg_res.resname = 'CourseModule'").append(" ) and exists (").append("  select owngroup.id from o_re_to_group owngroup inner join o_bs_group_member sg_owner on (sg_owner.fk_group_id=owngroup.fk_group_id)").append("  where owngroup.fk_entry_id = sg_re.repositoryentry_id and owngroup.r_defgroup=").appendTrue().append(" and sg_owner.g_role='owner' and sg_owner.fk_identity_id=:coachKey").append(" )").append(" group by sg_re.repositoryentry_id");
    }
    List<?> rawList = dbInstance.getCurrentEntityManager().createNativeQuery(sb.toString()).setParameter("coachKey", coach.getKey()).getResultList();
    for (Object rawObject : rawList) {
        Object[] rawStats = (Object[]) rawObject;
        Long repoKey = ((Number) rawStats[0]).longValue();
        CourseStatEntry entry = map.get(repoKey);
        if (entry != null) {
            entry.setCountStudents(((Number) rawStats[1]).intValue());
            entry.setInitialLaunch(((Number) rawStats[2]).intValue());
        }
    }
    return rawList.size() > 0;
}
Also used : CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) NativeQueryBuilder(org.olat.core.commons.persistence.NativeQueryBuilder)

Example 10 with CourseStatEntry

use of org.olat.modules.coach.model.CourseStatEntry in project openolat by klemens.

the class CoachingDAO method getCourses.

private boolean getCourses(IdentityRef coach, Map<Long, CourseStatEntry> map) {
    NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
    sb.append("select v.key, v.displayname").append(" from repositoryentry v").append(" inner join v.olatResource as res").append(" inner join v.groups as relGroup").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as coach on coach.role in ('").append(GroupRoles.coach.name()).append("','").append(GroupRoles.owner.name()).append("')").append(" where coach.identity.key=:coachKey and res.resName='CourseModule'").append(" and ((v.access=1 and v.membersOnly=true) ").append(" or (v.access >= ").append(RepositoryEntry.ACC_USERS).append(" and coach.role='").append(GroupRoles.coach.name()).append("')").append(" or (v.access >= ").append(RepositoryEntry.ACC_OWNERS).append(" and coach.role='").append(GroupRoles.owner.name()).append("'))");
    List<Object[]> rawList = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("coachKey", coach.getKey()).getResultList();
    for (Object[] rawStat : rawList) {
        CourseStatEntry entry = new CourseStatEntry();
        entry.setRepoKey(((Number) rawStat[0]).longValue());
        entry.setRepoDisplayName((String) rawStat[1]);
        map.put(entry.getRepoKey(), entry);
    }
    return rawList.size() > 0;
}
Also used : CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) NativeQueryBuilder(org.olat.core.commons.persistence.NativeQueryBuilder)

Aggregations

CourseStatEntry (org.olat.modules.coach.model.CourseStatEntry)32 Test (org.junit.Test)14 GroupStatEntry (org.olat.modules.coach.model.GroupStatEntry)14 StudentStatEntry (org.olat.modules.coach.model.StudentStatEntry)14 RepositoryEntry (org.olat.repository.RepositoryEntry)14 File (java.io.File)12 URL (java.net.URL)12 Identity (org.olat.core.id.Identity)12 BusinessGroup (org.olat.group.BusinessGroup)12 CoachingLargeTest (org.olat.modules.coach.CoachingLargeTest)12 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)12 Date (java.util.Date)8 NativeQueryBuilder (org.olat.core.commons.persistence.NativeQueryBuilder)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 ContextEntry (org.olat.core.id.context.ContextEntry)2 ICourse (org.olat.course.ICourse)2 EfficiencyStatementEntry (org.olat.modules.coach.model.EfficiencyStatementEntry)2