Search in sources :

Example 6 with LectureBlockIdentityStatistics

use of org.olat.modules.lecture.model.LectureBlockIdentityStatistics in project OpenOLAT by OpenOLAT.

the class LectureServiceImpl method groupByIdentity.

@Override
public List<LectureBlockIdentityStatistics> groupByIdentity(List<LectureBlockIdentityStatistics> statistics) {
    Map<Long, LectureBlockIdentityStatistics> groupBy = new HashMap<>();
    for (LectureBlockIdentityStatistics statistic : statistics) {
        if (groupBy.containsKey(statistic.getIdentityKey())) {
            groupBy.get(statistic.getIdentityKey()).aggregate(statistic);
        } else {
            groupBy.put(statistic.getIdentityKey(), statistic.cloneForAggregation());
        }
    }
    boolean countAuthorizedAbsenceAsAttendant = lectureModule.isCountAuthorizedAbsenceAsAttendant();
    List<LectureBlockIdentityStatistics> aggregatedStatistics = new ArrayList<>(groupBy.values());
    for (LectureBlockIdentityStatistics statistic : aggregatedStatistics) {
        lectureBlockRollCallDao.calculateAttendanceRate(statistic, countAuthorizedAbsenceAsAttendant);
    }
    return aggregatedStatistics;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics)

Example 7 with LectureBlockIdentityStatistics

use of org.olat.modules.lecture.model.LectureBlockIdentityStatistics in project OpenOLAT by OpenOLAT.

the class LectureBlockRollCallDAO method getStatistics.

public List<LectureBlockIdentityStatistics> getStatistics(LectureStatisticsSearchParameters params, List<UserPropertyHandler> userPropertyHandlers, Identity identity, boolean admin, boolean authorizedAbsenceEnabled, boolean absenceDefaultAuthorized, boolean countAuthorizedAbsenceAsAttendant, boolean calculateAttendanceRate, double requiredAttendanceRateDefault) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select ident.key as participantKey, ident.name as participantName,").append("  call.lecturesAttendedNumber as attendedLectures,").append("  call.lecturesAbsentNumber as absentLectures,").append("  call.absenceAuthorized as absenceAuthorized,").append("  block.key as blockKey,").append("  block.compulsory as compulsory,").append("  block.plannedLecturesNumber as blockPlanned,").append("  block.effectiveLecturesNumber as blockEffective,").append("  block.statusString as status,").append("  block.rollCallStatusString as rollCallStatus,").append("  block.endDate as rollCallEndDate,").append("  re.key as repoKey,").append("  re.displayname as repoDisplayName,").append("  re.externalRef as repoExternalRef,").append("  config.overrideModuleDefault as overrideDef,").append("  config.calculateAttendanceRate as calculateRate,").append(// rate enabled
    "  config.requiredAttendanceRate as repoConfigRate,").append("  summary.firstAdmissionDate as firstAdmissionDate,").append("  summary.requiredAttendanceRate as summaryRate");
    for (UserPropertyHandler handler : userPropertyHandlers) {
        sb.append(", user.").append(handler.getName()).append(" as ").append("p_").append(handler.getName());
    }
    sb.append(" from lectureblock block").append(" inner join block.entry re").append(" inner join block.groups blockToGroup").append(" inner join blockToGroup.group bGroup").append(" inner join bGroup.members membership").append(" inner join membership.identity ident").append(" inner join ident.user user").append(" inner join lectureentryconfig as config on (re.key=config.entry.key)").append(" left join lectureblockrollcall as call on (call.identity.key=membership.identity.key and call.lectureBlock.key=block.key)").append(" left join lectureparticipantsummary as summary on (summary.identity.key=membership.identity.key and summary.entry.key=block.entry.key)").append(" where config.lectureEnabled=true and membership.role='").append(GroupRoles.participant.name()).append("'");
    if (!admin) {
        sb.append(" and (exists (select rel from repoentrytogroup as rel, bgroupmember as membership ").append("     where re.key=rel.entry.key and membership.group.key=rel.group.key and rel.defaultGroup=true and membership.identity.key=:identityKey").append("     and membership.role='").append(GroupRoles.owner.name()).append("'").append("     and re.access >= ").append(RepositoryEntry.ACC_OWNERS).append(" ) or exists (select membership.key from bgroupmember as membership ").append("     where block.teacherGroup.key=membership.group.key and membership.identity.key=:identityKey").append("     and (re.access >= ").append(RepositoryEntry.ACC_USERS).append("     or (re.access = ").append(RepositoryEntry.ACC_OWNERS).append(" and re.membersOnly=true))").append(" ))");
    } else {
        sb.append(" and re.access >= ").append(RepositoryEntry.ACC_OWNERS);
    }
    if (params.getLifecycle() != null) {
        sb.append(" and re.lifecycle.key=:lifecycleKey");
    }
    if (params.getStartDate() != null) {
        sb.append(" and block.startDate>=:startDate");
    }
    if (params.getEndDate() != null) {
        sb.append(" and block.endDate<=:endDate");
    }
    if (params.getBulkIdentifiers() != null && params.getBulkIdentifiers().size() > 0) {
        sb.append(" and (").append("  lower(ident.name) in (:bulkIdentifiers)").append("  or lower(ident.externalId) in (:bulkIdentifiers)").append("  or lower(user.email) in (:bulkIdentifiers)").append("  or lower(user.institutionalEmail) in (:bulkIdentifiers)").append("  or lower(user.institutionalUserIdentifier) in (:bulkIdentifiers)").append(")");
    }
    Map<String, Object> queryParams = new HashMap<>();
    appendUsersStatisticsSearchParams(params, queryParams, userPropertyHandlers, sb);
    TypedQuery<Object[]> rawQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    if (StringHelper.containsNonWhitespace(params.getLogin())) {
        rawQuery.setParameter("login", params.getLogin());
    }
    if (params.getLifecycle() != null) {
        rawQuery.setParameter("lifecycleKey", params.getLifecycle().getKey());
    }
    if (params.getStartDate() != null) {
        rawQuery.setParameter("startDate", params.getStartDate(), TemporalType.TIMESTAMP);
    }
    if (params.getEndDate() != null) {
        rawQuery.setParameter("endDate", params.getEndDate(), TemporalType.TIMESTAMP);
    }
    if (params.getBulkIdentifiers() != null && params.getBulkIdentifiers().size() > 0) {
        rawQuery.setParameter("bulkIdentifiers", params.getBulkIdentifiers());
    }
    for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        rawQuery.setParameter(entry.getKey(), entry.getValue());
    }
    if (!admin) {
        rawQuery.setParameter("identityKey", identity.getKey());
    }
    Date now = new Date();
    List<Object[]> rawObjects = rawQuery.getResultList();
    Map<Membership, LectureBlockIdentityStatistics> stats = new HashMap<>();
    for (Object[] rawObject : rawObjects) {
        // jump roll call key
        int pos = 0;
        Long identityKey = (Long) rawObject[pos++];
        String identityName = (String) rawObject[pos++];
        Long lecturesAttended = PersistenceHelper.extractLong(rawObject, pos++);
        Long lecturesAbsent = PersistenceHelper.extractLong(rawObject, pos++);
        Boolean absenceAuthorized;
        if (authorizedAbsenceEnabled) {
            absenceAuthorized = (Boolean) rawObject[pos++];
        } else {
            absenceAuthorized = null;
            pos++;
        }
        // jump block key
        pos++;
        boolean compulsory = PersistenceHelper.extractBoolean(rawObject, pos++, true);
        Long plannedLecturesNumber = PersistenceHelper.extractLong(rawObject, pos++);
        Long effectiveLecturesNumber = PersistenceHelper.extractLong(rawObject, pos++);
        if (effectiveLecturesNumber == null) {
            effectiveLecturesNumber = plannedLecturesNumber;
        }
        String status = (String) rawObject[pos++];
        String rollCallStatus = (String) rawObject[pos++];
        Date rollCallEndDate = (Date) rawObject[pos++];
        // entry and config
        Long repoKey = PersistenceHelper.extractLong(rawObject, pos++);
        String repoDisplayname = (String) rawObject[pos++];
        String repoExternalRef = (String) rawObject[pos++];
        boolean overrideDefault = PersistenceHelper.extractBoolean(rawObject, pos++, false);
        Boolean repoCalculateRate = (Boolean) rawObject[pos++];
        Double repoRequiredRate = (Double) rawObject[pos++];
        // summary
        Date firstAdmissionDate = (Date) rawObject[pos++];
        Double persoRequiredRate = (Double) rawObject[pos++];
        LectureBlockIdentityStatistics entryStatistics;
        Membership memberKey = new Membership(identityKey, repoKey);
        if (stats.containsKey(memberKey)) {
            entryStatistics = stats.get(memberKey);
        } else {
            // user data
            int numOfProperties = userPropertyHandlers.size();
            String[] identityProps = new String[numOfProperties];
            for (int i = 0; i < numOfProperties; i++) {
                identityProps[i] = (String) rawObject[pos++];
            }
            entryStatistics = createIdentityStatistics(identityKey, identityName, identityProps, repoKey, repoDisplayname, repoExternalRef, overrideDefault, repoCalculateRate, repoRequiredRate, persoRequiredRate, calculateAttendanceRate, requiredAttendanceRateDefault);
            stats.put(memberKey, entryStatistics);
        }
        appendStatistics(entryStatistics, compulsory, status, rollCallEndDate, rollCallStatus, lecturesAttended, lecturesAbsent, absenceAuthorized, absenceDefaultAuthorized, plannedLecturesNumber, effectiveLecturesNumber, firstAdmissionDate, now);
    }
    List<LectureBlockIdentityStatistics> statisticsList = new ArrayList<>(stats.values());
    calculateAttendanceRate(statisticsList, countAuthorizedAbsenceAsAttendant);
    return statisticsList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics) HashMap(java.util.HashMap) Map(java.util.Map) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 8 with LectureBlockIdentityStatistics

use of org.olat.modules.lecture.model.LectureBlockIdentityStatistics in project openolat by klemens.

the class LectureBlockRollCallDAO method getStatistics.

public List<LectureBlockIdentityStatistics> getStatistics(LectureStatisticsSearchParameters params, List<UserPropertyHandler> userPropertyHandlers, Identity identity, boolean admin, boolean authorizedAbsenceEnabled, boolean absenceDefaultAuthorized, boolean countAuthorizedAbsenceAsAttendant, boolean calculateAttendanceRate, double requiredAttendanceRateDefault) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select ident.key as participantKey, ident.name as participantName,").append("  call.lecturesAttendedNumber as attendedLectures,").append("  call.lecturesAbsentNumber as absentLectures,").append("  call.absenceAuthorized as absenceAuthorized,").append("  block.key as blockKey,").append("  block.compulsory as compulsory,").append("  block.plannedLecturesNumber as blockPlanned,").append("  block.effectiveLecturesNumber as blockEffective,").append("  block.statusString as status,").append("  block.rollCallStatusString as rollCallStatus,").append("  block.endDate as rollCallEndDate,").append("  re.key as repoKey,").append("  re.displayname as repoDisplayName,").append("  re.externalRef as repoExternalRef,").append("  config.overrideModuleDefault as overrideDef,").append("  config.calculateAttendanceRate as calculateRate,").append(// rate enabled
    "  config.requiredAttendanceRate as repoConfigRate,").append("  summary.firstAdmissionDate as firstAdmissionDate,").append("  summary.requiredAttendanceRate as summaryRate");
    for (UserPropertyHandler handler : userPropertyHandlers) {
        sb.append(", user.").append(handler.getName()).append(" as ").append("p_").append(handler.getName());
    }
    sb.append(" from lectureblock block").append(" inner join block.entry re").append(" inner join block.groups blockToGroup").append(" inner join blockToGroup.group bGroup").append(" inner join bGroup.members membership").append(" inner join membership.identity ident").append(" inner join ident.user user").append(" inner join lectureentryconfig as config on (re.key=config.entry.key)").append(" left join lectureblockrollcall as call on (call.identity.key=membership.identity.key and call.lectureBlock.key=block.key)").append(" left join lectureparticipantsummary as summary on (summary.identity.key=membership.identity.key and summary.entry.key=block.entry.key)").append(" where config.lectureEnabled=true and membership.role='").append(GroupRoles.participant.name()).append("'");
    if (!admin) {
        sb.append(" and (exists (select rel from repoentrytogroup as rel, bgroupmember as membership ").append("     where re.key=rel.entry.key and membership.group.key=rel.group.key and rel.defaultGroup=true and membership.identity.key=:identityKey").append("     and membership.role='").append(GroupRoles.owner.name()).append("'").append("     and re.access >= ").append(RepositoryEntry.ACC_OWNERS).append(" ) or exists (select membership.key from bgroupmember as membership ").append("     where block.teacherGroup.key=membership.group.key and membership.identity.key=:identityKey").append("     and (re.access >= ").append(RepositoryEntry.ACC_USERS).append("     or (re.access = ").append(RepositoryEntry.ACC_OWNERS).append(" and re.membersOnly=true))").append(" ))");
    } else {
        sb.append(" and re.access >= ").append(RepositoryEntry.ACC_OWNERS);
    }
    if (params.getLifecycle() != null) {
        sb.append(" and re.lifecycle.key=:lifecycleKey");
    }
    if (params.getStartDate() != null) {
        sb.append(" and block.startDate>=:startDate");
    }
    if (params.getEndDate() != null) {
        sb.append(" and block.endDate<=:endDate");
    }
    if (params.getBulkIdentifiers() != null && params.getBulkIdentifiers().size() > 0) {
        sb.append(" and (").append("  lower(ident.name) in (:bulkIdentifiers)").append("  or lower(ident.externalId) in (:bulkIdentifiers)").append("  or lower(user.email) in (:bulkIdentifiers)").append("  or lower(user.institutionalEmail) in (:bulkIdentifiers)").append("  or lower(user.institutionalUserIdentifier) in (:bulkIdentifiers)").append(")");
    }
    Map<String, Object> queryParams = new HashMap<>();
    appendUsersStatisticsSearchParams(params, queryParams, userPropertyHandlers, sb);
    TypedQuery<Object[]> rawQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    if (StringHelper.containsNonWhitespace(params.getLogin())) {
        rawQuery.setParameter("login", params.getLogin());
    }
    if (params.getLifecycle() != null) {
        rawQuery.setParameter("lifecycleKey", params.getLifecycle().getKey());
    }
    if (params.getStartDate() != null) {
        rawQuery.setParameter("startDate", params.getStartDate(), TemporalType.TIMESTAMP);
    }
    if (params.getEndDate() != null) {
        rawQuery.setParameter("endDate", params.getEndDate(), TemporalType.TIMESTAMP);
    }
    if (params.getBulkIdentifiers() != null && params.getBulkIdentifiers().size() > 0) {
        rawQuery.setParameter("bulkIdentifiers", params.getBulkIdentifiers());
    }
    for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        rawQuery.setParameter(entry.getKey(), entry.getValue());
    }
    if (!admin) {
        rawQuery.setParameter("identityKey", identity.getKey());
    }
    Date now = new Date();
    List<Object[]> rawObjects = rawQuery.getResultList();
    Map<Membership, LectureBlockIdentityStatistics> stats = new HashMap<>();
    for (Object[] rawObject : rawObjects) {
        // jump roll call key
        int pos = 0;
        Long identityKey = (Long) rawObject[pos++];
        String identityName = (String) rawObject[pos++];
        Long lecturesAttended = PersistenceHelper.extractLong(rawObject, pos++);
        Long lecturesAbsent = PersistenceHelper.extractLong(rawObject, pos++);
        Boolean absenceAuthorized;
        if (authorizedAbsenceEnabled) {
            absenceAuthorized = (Boolean) rawObject[pos++];
        } else {
            absenceAuthorized = null;
            pos++;
        }
        // jump block key
        pos++;
        boolean compulsory = PersistenceHelper.extractBoolean(rawObject, pos++, true);
        Long plannedLecturesNumber = PersistenceHelper.extractLong(rawObject, pos++);
        Long effectiveLecturesNumber = PersistenceHelper.extractLong(rawObject, pos++);
        if (effectiveLecturesNumber == null) {
            effectiveLecturesNumber = plannedLecturesNumber;
        }
        String status = (String) rawObject[pos++];
        String rollCallStatus = (String) rawObject[pos++];
        Date rollCallEndDate = (Date) rawObject[pos++];
        // entry and config
        Long repoKey = PersistenceHelper.extractLong(rawObject, pos++);
        String repoDisplayname = (String) rawObject[pos++];
        String repoExternalRef = (String) rawObject[pos++];
        boolean overrideDefault = PersistenceHelper.extractBoolean(rawObject, pos++, false);
        Boolean repoCalculateRate = (Boolean) rawObject[pos++];
        Double repoRequiredRate = (Double) rawObject[pos++];
        // summary
        Date firstAdmissionDate = (Date) rawObject[pos++];
        Double persoRequiredRate = (Double) rawObject[pos++];
        LectureBlockIdentityStatistics entryStatistics;
        Membership memberKey = new Membership(identityKey, repoKey);
        if (stats.containsKey(memberKey)) {
            entryStatistics = stats.get(memberKey);
        } else {
            // user data
            int numOfProperties = userPropertyHandlers.size();
            String[] identityProps = new String[numOfProperties];
            for (int i = 0; i < numOfProperties; i++) {
                identityProps[i] = (String) rawObject[pos++];
            }
            entryStatistics = createIdentityStatistics(identityKey, identityName, identityProps, repoKey, repoDisplayname, repoExternalRef, overrideDefault, repoCalculateRate, repoRequiredRate, persoRequiredRate, calculateAttendanceRate, requiredAttendanceRateDefault);
            stats.put(memberKey, entryStatistics);
        }
        appendStatistics(entryStatistics, compulsory, status, rollCallEndDate, rollCallStatus, lecturesAttended, lecturesAbsent, absenceAuthorized, absenceDefaultAuthorized, plannedLecturesNumber, effectiveLecturesNumber, firstAdmissionDate, now);
    }
    List<LectureBlockIdentityStatistics> statisticsList = new ArrayList<>(stats.values());
    calculateAttendanceRate(statisticsList, countAuthorizedAbsenceAsAttendant);
    return statisticsList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics) HashMap(java.util.HashMap) Map(java.util.Map) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 9 with LectureBlockIdentityStatistics

use of org.olat.modules.lecture.model.LectureBlockIdentityStatistics in project openolat by klemens.

the class LectureServiceImpl method groupByIdentity.

@Override
public List<LectureBlockIdentityStatistics> groupByIdentity(List<LectureBlockIdentityStatistics> statistics) {
    Map<Long, LectureBlockIdentityStatistics> groupBy = new HashMap<>();
    for (LectureBlockIdentityStatistics statistic : statistics) {
        if (groupBy.containsKey(statistic.getIdentityKey())) {
            groupBy.get(statistic.getIdentityKey()).aggregate(statistic);
        } else {
            groupBy.put(statistic.getIdentityKey(), statistic.cloneForAggregation());
        }
    }
    boolean countAuthorizedAbsenceAsAttendant = lectureModule.isCountAuthorizedAbsenceAsAttendant();
    List<LectureBlockIdentityStatistics> aggregatedStatistics = new ArrayList<>(groupBy.values());
    for (LectureBlockIdentityStatistics statistic : aggregatedStatistics) {
        lectureBlockRollCallDao.calculateAttendanceRate(statistic, countAuthorizedAbsenceAsAttendant);
    }
    return aggregatedStatistics;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics)

Example 10 with LectureBlockIdentityStatistics

use of org.olat.modules.lecture.model.LectureBlockIdentityStatistics in project openolat by klemens.

the class LecturesListController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == tableEl) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            String cmd = se.getCommand();
            if ("open.course".equals(cmd)) {
                LectureBlockIdentityStatistics row = tableModel.getObject(se.getIndex());
                doOpenCourseLectures(ureq, row);
            }
        }
    } else if (source == exportButton) {
        doExportStatistics(ureq);
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics)

Aggregations

LectureBlockIdentityStatistics (org.olat.modules.lecture.model.LectureBlockIdentityStatistics)12 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 Date (java.util.Date)2 Map (java.util.Map)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 LectureStatisticsSearchParameters (org.olat.modules.lecture.model.LectureStatisticsSearchParameters)2 LectureRepositoryAdminController (org.olat.modules.lecture.ui.LectureRepositoryAdminController)2