use of org.olat.modules.coach.model.CourseStatEntry in project OpenOLAT by OpenOLAT.
the class CoachingDAO method getCoursesStatisticsNative.
protected List<CourseStatEntry> getCoursesStatisticsNative(Identity coach) {
Map<Long, CourseStatEntry> map = new HashMap<>();
boolean hasCourses = getCourses(coach, map);
if (hasCourses) {
getCoursesStatisticsUserInfosForCoach(coach, map);
getCoursesStatisticsUserInfosForOwner(coach, map);
getCoursesStatisticsStatements(coach, map);
for (Iterator<Map.Entry<Long, CourseStatEntry>> it = map.entrySet().iterator(); it.hasNext(); ) {
CourseStatEntry entry = it.next().getValue();
if (entry.getCountStudents() == 0) {
it.remove();
} else {
int notAttempted = entry.getCountStudents() - entry.getCountPassed() - entry.getCountFailed();
entry.setCountNotAttempted(notAttempted);
}
}
}
return new ArrayList<>(map.values());
}
use of org.olat.modules.coach.model.CourseStatEntry in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.coach.model.CourseStatEntry in project OpenOLAT by OpenOLAT.
the class CoachingDAO method getCoursesStatisticsStatements.
private boolean getCoursesStatisticsStatements(Identity coach, Map<Long, CourseStatEntry> map) {
NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
sb.append("select ").append(" fin_statement.course_repo_key, ").append(" count(fin_statement.id), ").append(" sum(case when fin_statement.passed=").appendTrue().append(" then 1 else 0 end) as num_of_passed, ").append(" sum(case when fin_statement.passed=").appendFalse().append(" then 1 else 0 end) as num_of_failed, ").append(" avg(fin_statement.score) ").append("from o_as_eff_statement fin_statement ").append("where fin_statement.id in ( select ").append(" distinct sg_statement.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_coach on (sg_coach.fk_group_id=togroup.fk_group_id and sg_coach.g_role in ('owner','coach')) ").append(" inner join o_bs_group_member sg_participant on (sg_participant.fk_group_id=sg_coach.fk_group_id and sg_participant.g_role='participant') ").append(" inner join o_as_eff_statement sg_statement on (sg_statement.fk_identity = sg_participant.fk_identity_id and sg_statement.fk_resource_id = sg_re.fk_olatresource) ").append(" where sg_coach.fk_identity_id=:coachKey and ( ").append(" (sg_re.accesscode >= ").append(RepositoryEntry.ACC_USERS).append(// BAR
" and sg_coach.g_role = 'coach') ").append(" or ").append(" (sg_re.accesscode >= ").append(RepositoryEntry.ACC_OWNERS).append(// B
" and sg_coach.g_role = 'owner') ").append(" or ").append(" (sg_re.accesscode = ").append(RepositoryEntry.ACC_OWNERS).append(" and sg_re.membersonly=").appendTrue().append(")) ").append(") or fin_statement.id in ( select ").append(" distinct sg_statement.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(" inner join o_as_eff_statement sg_statement on (sg_statement.fk_identity = sg_participant.fk_identity_id and sg_statement.fk_resource_id = sg_re.fk_olatresource) ").append(" where sg_coach.fk_identity_id=:coachKey and sg_re.accesscode >= ").append(RepositoryEntry.ACC_OWNERS).append(") ").append("group by fin_statement.course_repo_key ");
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) {
int passed = ((Number) rawStats[2]).intValue();
int failed = ((Number) rawStats[3]).intValue();
entry.setCountFailed(failed);
entry.setCountPassed(passed);
if (rawStats[4] != null) {
entry.setAverageScore(((Number) rawStats[4]).floatValue());
}
}
}
return rawList.size() > 0;
}
use of org.olat.modules.coach.model.CourseStatEntry 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());
}
}
use of org.olat.modules.coach.model.CourseStatEntry in project openolat by klemens.
the class CoachingDAOTest method getStatistics_notAttempted.
/**
* 3 courses in the same business group
*
* @throws URISyntaxException
*/
@Test
public void getStatistics_notAttempted() 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);
RepositoryEntry re3 = 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, re1, GroupRoles.coach.name());
repositoryService.addRole(coach, re2, GroupRoles.coach.name());
repositoryService.addRole(coach, re3, GroupRoles.coach.name());
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-1");
repositoryService.addRole(participant1, re2, GroupRoles.participant.name());
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("Coaching-Part-2");
repositoryService.addRole(participant2, re1, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// members of 2 groups
BusinessGroup group = businessGroupService.createBusinessGroup(coach, "Coaching-grp-1", "tg", null, null, false, false, re1);
businessGroupService.addResourceTo(group, re2);
businessGroupService.addResourceTo(group, re3);
businessGroupRelationDao.addRole(participant1, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(participant2, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// make statements participant 1
effManager.createUserEfficiencyStatement(new Date(), 6.0f, true, participant1, re1.getOlatResource());
effManager.createUserEfficiencyStatement(new Date(), 4.0f, false, participant1, re2.getOlatResource());
effManager.createUserEfficiencyStatement(new Date(), 2.0f, false, participant1, re3.getOlatResource());
// make statements participant 2
effManager.createUserEfficiencyStatement(new Date(), 6.0f, true, participant2, re1.getOlatResource());
effManager.createUserEfficiencyStatement(new Date(), null, null, participant2, re2.getOlatResource());
dbInstance.commitAndCloseSession();
// make user infos
userCourseInformationsManager.updateUserCourseInformations(re1.getOlatResource(), participant1);
userCourseInformationsManager.updateUserCourseInformations(re2.getOlatResource(), participant1);
userCourseInformationsManager.updateUserCourseInformations(re3.getOlatResource(), participant1);
userCourseInformationsManager.updateUserCourseInformations(re1.getOlatResource(), participant2);
userCourseInformationsManager.updateUserCourseInformations(re2.getOlatResource(), participant2);
dbInstance.commitAndCloseSession();
// check course
List<CourseStatEntry> nativeStats = coachingDAO.getCoursesStatisticsNative(coach);
Assert.assertNotNull(nativeStats);
Assert.assertEquals(3, nativeStats.size());
CourseStatEntry entryRe1 = getCourseStatEntry(re1, nativeStats);
Assert.assertEquals(2, entryRe1.getCountStudents());
Assert.assertEquals(2, entryRe1.getCountPassed());
Assert.assertEquals(0, entryRe1.getCountFailed());
Assert.assertEquals(0, entryRe1.getCountNotAttempted());
Assert.assertEquals(2, entryRe1.getInitialLaunch());
Assert.assertEquals(6.0f, entryRe1.getAverageScore(), 0.0001);
CourseStatEntry entryRe2 = getCourseStatEntry(re2, nativeStats);
Assert.assertEquals(2, entryRe2.getCountStudents());
Assert.assertEquals(0, entryRe2.getCountPassed());
Assert.assertEquals(1, entryRe2.getCountFailed());
Assert.assertEquals(1, entryRe2.getCountNotAttempted());
Assert.assertEquals(2, entryRe2.getInitialLaunch());
Assert.assertEquals(4.0f, entryRe2.getAverageScore(), 0.0001);
CourseStatEntry entryRe3 = getCourseStatEntry(re3, nativeStats);
Assert.assertEquals(2, entryRe3.getCountStudents());
Assert.assertEquals(0, entryRe3.getCountPassed());
Assert.assertEquals(1, entryRe3.getCountFailed());
Assert.assertEquals(1, entryRe3.getCountNotAttempted());
Assert.assertEquals(1, entryRe3.getInitialLaunch());
Assert.assertEquals(2.0f, entryRe3.getAverageScore(), 0.0001);
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(UserListController.usageIdentifyer, false);
// 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(2, entryParticipant1.getCountFailed());
Assert.assertEquals(0, entryParticipant1.getCountNotAttempted());
Assert.assertEquals(3, entryParticipant1.getInitialLaunch());
Assert.assertEquals(3, entryParticipant1.getCountRepo());
// participant2
StudentStatEntry entryParticipant2 = getStudentStatEntry(participant2, nativeUserStats);
Assert.assertNotNull(entryParticipant2);
Assert.assertEquals(1, entryParticipant2.getCountPassed());
Assert.assertEquals(0, entryParticipant2.getCountFailed());
Assert.assertEquals(2, entryParticipant2.getCountNotAttempted());
Assert.assertEquals(2, entryParticipant2.getInitialLaunch());
Assert.assertEquals(3, entryParticipant1.getCountRepo());
// group native
List<GroupStatEntry> nativeGroupStats = coachingDAO.getGroupsStatisticsNative(coach);
Assert.assertNotNull(nativeGroupStats);
Assert.assertEquals(1, nativeGroupStats.size());
// group 1
GroupStatEntry entryGroup1 = getGroupStatEntry(group, nativeGroupStats);
Assert.assertNotNull(entryGroup1);
Assert.assertEquals(6, entryGroup1.getCountStudents());
Assert.assertEquals(2, entryGroup1.getCountDistinctStudents());
Assert.assertEquals(3, entryGroup1.getCountCourses());
Assert.assertEquals(2, entryGroup1.getCountPassed());
Assert.assertEquals(2, entryGroup1.getCountFailed());
Assert.assertEquals(2, entryGroup1.getCountNotAttempted());
Assert.assertEquals(5, entryGroup1.getInitialLaunch());
Assert.assertEquals(4.5f, entryGroup1.getAverageScore(), 0.0001f);
}
Aggregations