Search in sources :

Example 31 with CourseStatEntry

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

the class CoachingDAO method getCoursesStatisticsUserInfosForCoach.

private boolean getCoursesStatisticsUserInfosForCoach(Identity coach, Map<Long, CourseStatEntry> map) {
    NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
    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_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 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 32 with CourseStatEntry

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

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;
}
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