Search in sources :

Example 21 with LectureBlockStatistics

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

the class LectureBlockRollCallDAO method getStatistics.

public List<LectureBlockStatistics> getStatistics(IdentityRef identity, boolean authorizedAbsenceEnabled, boolean absenceDefaultAuthorized, boolean countAuthorizedAbsenceAsAttendant, boolean calculateAttendanceRate, double requiredAttendanceRateDefault) {
    StringBuilder sb = new StringBuilder();
    sb.append("select call.key as callKey, ").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").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 lectureentryconfig as config on (re.key=config.entry.key)").append(" left join lectureparticipantsummary as summary on (summary.identity.key=membership.identity.key and summary.entry.key=block.entry.key)").append(" left join lectureblockrollcall as call on (call.identity.key=membership.identity.key and call.lectureBlock.key=block.key)").append(" where config.lectureEnabled=true and membership.identity.key=:identityKey and membership.role='").append(GroupRoles.participant.name()).append("'");
    // take in account: requiredAttendanceRateDefault, from repo config requiredAttendanceRate
    // take in account: authorized absence
    // take in account: firstAddmissionDate and null
    Date now = new Date();
    List<Object[]> rawObjects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", identity.getKey()).getResultList();
    Map<Long, LectureBlockStatistics> stats = new HashMap<>();
    for (Object[] rawObject : rawObjects) {
        // jump roll call key
        int pos = 1;
        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++];
        Long repoKey = PersistenceHelper.extractLong(rawObject, pos++);
        String repoDisplayname = (String) rawObject[pos++];
        String repoExternalRef = (String) rawObject[pos++];
        Boolean overrideDefault = (Boolean) rawObject[pos++];
        Boolean repoCalculateRate = (Boolean) rawObject[pos++];
        Double repoRequiredRate = (Double) rawObject[pos++];
        Date firstAdmissionDate = (Date) rawObject[pos++];
        Double persoRequiredRate = (Double) rawObject[pos++];
        LectureBlockStatistics entryStatistics;
        if (stats.containsKey(repoKey)) {
            entryStatistics = stats.get(repoKey);
        } else {
            entryStatistics = create(identity.getKey(), repoKey, repoDisplayname, repoExternalRef, overrideDefault, repoCalculateRate, repoRequiredRate, persoRequiredRate, calculateAttendanceRate, requiredAttendanceRateDefault);
            stats.put(repoKey, entryStatistics);
        }
        appendStatistics(entryStatistics, compulsory, status, rollCallEndDate, rollCallStatus, lecturesAttended, lecturesAbsent, absenceAuthorized, absenceDefaultAuthorized, plannedLecturesNumber, effectiveLecturesNumber, firstAdmissionDate, now);
    }
    List<LectureBlockStatistics> statisticsList = new ArrayList<>(stats.values());
    calculateAttendanceRate(statisticsList, countAuthorizedAbsenceAsAttendant);
    return statisticsList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) Date(java.util.Date)

Example 22 with LectureBlockStatistics

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

the class LectureServiceImpl method recalculateSummary.

@Override
public void recalculateSummary(RepositoryEntry entry) {
    List<LectureBlockStatistics> statistics = getParticipantsLecturesStatistics(entry);
    int count = 0;
    for (LectureBlockStatistics statistic : statistics) {
        if (lectureParticipantSummaryDao.updateStatistics(statistic) == 0) {
            Identity identity = dbInstance.getCurrentEntityManager().getReference(IdentityImpl.class, statistic.getIdentityKey());
            lectureParticipantSummaryDao.createSummary(entry, identity, new Date(), statistic);
        }
        if (++count % 20 == 0) {
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 23 with LectureBlockStatistics

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

the class RateWarningCellRenderer method render.

@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator trans) {
    if (cellValue instanceof LectureBlockStatistics) {
        LectureBlockStatistics stats = (LectureBlockStatistics) cellValue;
        if (stats.isCalculateRate() && stats.getTotalPersonalPlannedLectures() > 0 && (stats.getTotalAbsentLectures() > 0 || stats.getTotalAttendedLectures() > 0 || stats.getTotalAuthorizedAbsentLectures() > 0)) {
            double attendanceRate = stats.getAttendanceRate();
            double requiredRate = stats.getRequiredRate();
            if (requiredRate > attendanceRate) {
                String title = translator.translate("rate.error.title");
                target.append("<i class='o_icon o_icon-lg o_icon_error' title='").append(title).append("'> </i>");
            } else if (attendanceRate - requiredRate < 0.05) {
                // less than 5%
                String title = translator.translate("rate.warning.title");
                target.append("<i class='o_icon o_icon-lg o_icon_warning' title='").append(title).append("'> </i>");
            }
        }
    }
}
Also used : LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics)

Example 24 with LectureBlockStatistics

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

the class StudentCoursesController method loadModel.

private List<EfficiencyStatementEntry> loadModel() {
    List<RepositoryEntry> courses = fullAccess ? coachingService.getUserCourses(student) : coachingService.getStudentsCourses(getIdentity(), student);
    List<EfficiencyStatementEntry> statements = coachingService.getEfficencyStatements(student, courses, userPropertyHandlers, getLocale());
    List<CertificateLight> certificates = certificatesManager.getLastCertificates(student);
    ConcurrentMap<IdentityResourceKey, CertificateLight> certificateMap = new ConcurrentHashMap<>();
    for (CertificateLight certificate : certificates) {
        IdentityResourceKey key = new IdentityResourceKey(student.getKey(), certificate.getOlatResourceKey());
        certificateMap.put(key, certificate);
    }
    ConcurrentMap<IdentityRepositoryEntryKey, LectureBlockStatistics> lecturesMap = new ConcurrentHashMap<>();
    if (lectureModule.isEnabled()) {
        List<LectureBlockStatistics> lectureStats = lectureService.getParticipantLecturesStatistics(student);
        for (LectureBlockStatistics lectureStat : lectureStats) {
            IdentityRepositoryEntryKey key = new IdentityRepositoryEntryKey(student.getKey(), lectureStat.getRepoKey());
            lecturesMap.put(key, lectureStat);
        }
    }
    model.setObjects(statements, certificateMap, lecturesMap);
    tableEl.reset();
    tableEl.reloadData();
    return statements;
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) EfficiencyStatementEntry(org.olat.modules.coach.model.EfficiencyStatementEntry) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) CertificateLight(org.olat.course.certificate.CertificateLight) IdentityResourceKey(org.olat.modules.coach.model.IdentityResourceKey) IdentityRepositoryEntryKey(org.olat.modules.coach.model.IdentityRepositoryEntryKey) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

LectureBlockStatistics (org.olat.modules.lecture.model.LectureBlockStatistics)24 Identity (org.olat.core.id.Identity)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 RepositoryEntryLectureConfiguration (org.olat.modules.lecture.RepositoryEntryLectureConfiguration)6 Test (org.junit.Test)4 Group (org.olat.basesecurity.Group)4 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)4 BusinessGroup (org.olat.group.BusinessGroup)4 LectureBlock (org.olat.modules.lecture.LectureBlock)4 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)4 AggregatedLectureBlocksStatistics (org.olat.modules.lecture.model.AggregatedLectureBlocksStatistics)4 HashMap (java.util.HashMap)3 Calendar (java.util.Calendar)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2