use of org.olat.modules.coach.model.GroupStatEntry 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);
}
use of org.olat.modules.coach.model.GroupStatEntry in project openolat by klemens.
the class GroupListController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == tableCtr) {
if (event instanceof TableEvent) {
TableEvent e = (TableEvent) event;
if ("select".equals(e.getActionId())) {
GroupStatEntry groupStatistic = (GroupStatEntry) tableCtr.getTableDataModel().getObject(e.getRowId());
selectGroup(ureq, groupStatistic);
}
}
} else if (source == groupCtrl) {
if (event == Event.CHANGED_EVENT) {
hasChanged = true;
} else if ("next.group".equals(event.getCommand())) {
nextGroup(ureq);
} else if ("previous.group".equals(event.getCommand())) {
previousGroup(ureq);
}
}
super.event(ureq, source, event);
}
use of org.olat.modules.coach.model.GroupStatEntry in project openolat by klemens.
the class CoachingDAO method getGroupsStatisticsStatementForOwner.
private boolean getGroupsStatisticsStatementForOwner(Identity coach, Map<Long, GroupStatEntry> map) {
NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
sb.append("select").append(" fin_statement.bgp_id,").append(" fin_statement.re_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(" sum(fin_statement.score) as avg_score ").append("from ( select ").append(" distinct sg_statement.id as id,").append(" togroup.fk_group_id as bgp_id,").append(" togroup.fk_entry_id as re_id,").append(" sg_statement.passed as passed,").append(" sg_statement.score as score ").append(" from o_repositoryentry sg_re ").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(" inner join o_re_to_group togroup on (togroup.r_defgroup=").appendFalse().append(" and 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_owner.fk_identity_id=:coachKey and sg_re.accesscode >= ").append(RepositoryEntry.ACC_OWNERS).append(") ").appendAs().append(" fin_statement ").append("group by fin_statement.bgp_id, fin_statement.re_id ");
List<?> rawList = dbInstance.getCurrentEntityManager().createNativeQuery(sb.toString()).setParameter("coachKey", coach.getKey()).getResultList();
for (Object rawObject : rawList) {
Object[] rawStats = (Object[]) rawObject;
Long baseGroupKey = ((Number) rawStats[0]).longValue();
Long repoKey = ((Number) rawStats[1]).longValue();
GroupStatEntry entry = map.get(baseGroupKey);
if (entry != null && !entry.getRepoIds().contains(repoKey)) {
int passed = ((Number) rawStats[2]).intValue();
int failed = ((Number) rawStats[3]).intValue();
entry.setCountFailed(failed + entry.getCountFailed());
entry.setCountPassed(passed + entry.getCountPassed());
if (rawStats[4] != null) {
entry.setSumScore(entry.getSumScore() + ((Number) rawStats[4]).floatValue());
}
entry.getRepoIds().add(repoKey);
}
}
return rawList.size() > 0;
}
use of org.olat.modules.coach.model.GroupStatEntry in project openolat by klemens.
the class CoachingDAO method getGroupsStatisticsInfosForCoach.
private boolean getGroupsStatisticsInfosForCoach(Identity coach, Map<Long, GroupStatEntry> map) {
NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
sb.append("select ").append(" togroup.fk_group_id as basegr_id, ").append(" togroup.fk_entry_id as re_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.r_defgroup=").appendFalse().append(" and 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 = '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(" 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 ( ").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(" and sg_re.membersonly=").appendTrue().append(")) ").append(" group by togroup.fk_group_id, togroup.fk_entry_id ");
List<?> rawList = dbInstance.getCurrentEntityManager().createNativeQuery(sb.toString()).setParameter("coachKey", coach.getKey()).getResultList();
for (Object rawObject : rawList) {
Object[] rawStats = (Object[]) rawObject;
Long baseGroupKey = ((Number) rawStats[0]).longValue();
GroupStatEntry entry = map.get(baseGroupKey);
if (entry != null) {
Long repoKey = ((Number) rawStats[1]).longValue();
if (!entry.getRepoIds().contains(repoKey)) {
int initalLaunch = ((Number) rawStats[2]).intValue();
entry.setInitialLaunch(initalLaunch + entry.getInitialLaunch());
entry.setCountCourses(entry.getCountCourses() + 1);
entry.getRepoIds().add(repoKey);
}
}
}
return rawList.size() > 0;
}
use of org.olat.modules.coach.model.GroupStatEntry in project openolat by klemens.
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;
}
Aggregations