Search in sources :

Example 21 with GroupStatEntry

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

the class GroupListController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    ContextEntry ce = entries.get(0);
    OLATResourceable ores = ce.getOLATResourceable();
    if ("BusinessGroup".equals(ores.getResourceableTypeName())) {
        Long groupKey = ores.getResourceableId();
        for (int i = tableCtr.getRowCount(); i-- > 0; ) {
            GroupStatEntry groupStatistic = (GroupStatEntry) tableCtr.getTableDataModel().getObject(i);
            if (groupKey.equals(groupStatistic.getGroupKey())) {
                selectGroup(ureq, groupStatistic);
                groupCtrl.activate(ureq, entries.subList(1, entries.size()), ce.getTransientState());
                break;
            }
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntry(org.olat.core.id.context.ContextEntry) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry)

Example 22 with GroupStatEntry

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

the class GroupListController method nextGroup.

protected void nextGroup(UserRequest ureq) {
    GroupStatEntry currentEntry = groupCtrl.getEntry();
    int nextIndex = tableCtr.getIndexOfSortedObject(currentEntry) + 1;
    if (nextIndex < 0 || nextIndex >= tableCtr.getRowCount()) {
        nextIndex = 0;
    }
    GroupStatEntry nextEntry = (GroupStatEntry) tableCtr.getSortedObjectAt(nextIndex);
    selectGroup(ureq, nextEntry);
}
Also used : GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry)

Example 23 with GroupStatEntry

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

the class CoachingDAO method getGroupsStatisticsNative.

protected List<GroupStatEntry> getGroupsStatisticsNative(Identity coach) {
    Map<Long, GroupStatEntry> map = new HashMap<>();
    boolean hasGroups = getGroups(coach, map);
    if (hasGroups) {
        boolean hasCoachedGroups = getGroupsStatisticsInfosForCoach(coach, map);
        boolean hasOwnedGroups = getGroupsStatisticsInfosForOwner(coach, map);
        for (GroupStatEntry entry : map.values()) {
            entry.getRepoIds().clear();
            entry.setCountStudents(entry.getCountDistinctStudents() * entry.getCountCourses());
        }
        if (hasOwnedGroups) {
            getGroupsStatisticsStatementForOwner(coach, map);
        }
        if (hasCoachedGroups) {
            getGroupsStatisticsStatementForCoach(coach, map);
        }
        for (Iterator<Map.Entry<Long, GroupStatEntry>> it = map.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<Long, GroupStatEntry> entry = it.next();
            GroupStatEntry groupEntry = entry.getValue();
            if (groupEntry.getCountStudents() == 0) {
                it.remove();
            } else {
                groupEntry.setRepoIds(null);
                int attempted = groupEntry.getCountPassed() + groupEntry.getCountFailed();
                groupEntry.setCountNotAttempted(groupEntry.getCountStudents() - attempted);
                if (attempted > 0) {
                    float averageScore = (float) groupEntry.getSumScore() / attempted;
                    groupEntry.setAverageScore(averageScore);
                }
            }
        }
    }
    return new ArrayList<>(map.values());
}
Also used : EfficiencyStatementEntry(org.olat.modules.coach.model.EfficiencyStatementEntry) RepositoryEntry(org.olat.repository.RepositoryEntry) StudentStatEntry(org.olat.modules.coach.model.StudentStatEntry) CourseStatEntry(org.olat.modules.coach.model.CourseStatEntry) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry)

Example 24 with GroupStatEntry

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

the class CoachingDAO method getGroups.

private boolean getGroups(Identity coach, Map<Long, GroupStatEntry> map) {
    NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
    sb.append("select ").append(" infos.group_id as grp_id, ").append(" infos.fk_group_id as bgrp_id, ").append(" infos.groupname as grp_name, ").append(" (select count(sg_participant.fk_identity_id) from o_bs_group_member sg_participant ").append("   where infos.fk_group_id = sg_participant.fk_group_id and sg_participant.g_role='participant' ").append(" ) as num_of_participant ").append(" from o_gp_business infos where infos.fk_group_id in ( select ").append("   distinct togroup.fk_group_id ").append("  from o_re_to_group togroup ").append("  inner join o_bs_group_member sg_coach on (sg_coach.fk_group_id=togroup.fk_group_id and sg_coach.g_role = 'coach') ").append("  inner join o_repositoryentry sg_re on (togroup.fk_entry_id = sg_re.repositoryentry_id) ").append("  inner join o_olatresource sg_res on (sg_res.resource_id = sg_re.fk_olatresource and sg_res.resname = 'CourseModule') ").append("  where sg_coach.fk_identity_id=:coachKey and ( ").append("   sg_re.accesscode>=").append(RepositoryEntry.ACC_USERS).append("   or ").append("   (sg_re.accesscode=").append(RepositoryEntry.ACC_OWNERS).append(" and sg_re.membersonly=").appendTrue().append(")) ").append(" ) or infos.fk_group_id in ( select ").append("	  distinct togroup.fk_group_id ").append("  from o_re_to_group togroup ").append("  inner join o_repositoryentry sg_re on (togroup.fk_entry_id = sg_re.repositoryentry_id) ").append("  inner join o_olatresource sg_res on (sg_res.resource_id = sg_re.fk_olatresource and sg_res.resname = 'CourseModule') ").append("  inner join o_re_to_group owngroup on (owngroup.r_defgroup=").appendTrue().append(" and owngroup.fk_entry_id = sg_re.repositoryentry_id) ").append("  inner join o_bs_group_member sg_owner on (sg_owner.fk_group_id=owngroup.fk_group_id and sg_owner.g_role = 'owner') ").append("  where togroup.r_defgroup=").appendFalse().append(" and sg_owner.fk_identity_id=:coachKey and sg_re.accesscode>=").append(RepositoryEntry.ACC_OWNERS).append(" ) ");
    List<?> rawList = dbInstance.getCurrentEntityManager().createNativeQuery(sb.toString()).setParameter("coachKey", coach.getKey()).getResultList();
    for (Object rawObject : rawList) {
        Object[] rawStat = (Object[]) rawObject;
        Long groupKey = ((Number) rawStat[0]).longValue();
        Long baseGroupKey = ((Number) rawStat[1]).longValue();
        String title = (String) rawStat[2];
        GroupStatEntry entry = new GroupStatEntry(groupKey, title);
        entry.setCountDistinctStudents(((Number) rawStat[3]).intValue());
        map.put(baseGroupKey, entry);
    }
    return rawList.size() > 0;
}
Also used : NativeQueryBuilder(org.olat.core.commons.persistence.NativeQueryBuilder) GroupStatEntry(org.olat.modules.coach.model.GroupStatEntry)

Example 25 with GroupStatEntry

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

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)

Aggregations

GroupStatEntry (org.olat.modules.coach.model.GroupStatEntry)36 Test (org.junit.Test)14 CourseStatEntry (org.olat.modules.coach.model.CourseStatEntry)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 NativeQueryBuilder (org.olat.core.commons.persistence.NativeQueryBuilder)10 Date (java.util.Date)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 Map (java.util.Map)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