Search in sources :

Example 1 with LectureBlockStatistics

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

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 2 with LectureBlockStatistics

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

the class ParticipantLecturesOverviewController 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();
            LectureBlockStatistics row = tableModel.getObject(se.getIndex());
            if ("details".equals(cmd)) {
                doSelect(ureq, row);
            } else if ("open.course".equals(cmd)) {
                doOpenCourse(ureq, row);
            }
        }
    } else if (logButton == source) {
        doExportLog(ureq);
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics)

Example 3 with LectureBlockStatistics

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

the class ParticipantListRepositoryController method loadModel.

private void loadModel() {
    List<Identity> participants;
    if (admin) {
        participants = lectureService.getParticipants(entry);
    } else {
        participants = lectureService.getParticipants(entry, getIdentity());
    }
    List<LectureBlockStatistics> statistics = lectureService.getParticipantsLecturesStatistics(entry);
    Map<Long, LectureBlockStatistics> identityToStatisticsMap = statistics.stream().collect(Collectors.toMap(s -> s.getIdentityKey(), s -> s));
    List<ParticipantRow> rows = new ArrayList<>(participants.size());
    for (Identity participant : participants) {
        LectureBlockStatistics stats = identityToStatisticsMap.get(participant.getKey());
        rows.add(new ParticipantRow(participant, stats, userPropertyHandlers, getLocale()));
    }
    tableModel.setObjects(rows);
    tableEl.reset(false, false, true);
}
Also used : FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) PercentCellRenderer(org.olat.modules.lecture.ui.component.PercentCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) Autowired(org.springframework.beans.factory.annotation.Autowired) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) LectureStatisticsCellRenderer(org.olat.modules.lecture.ui.component.LectureStatisticsCellRenderer) ParticipantInfosRenderer(org.olat.modules.lecture.ui.component.ParticipantInfosRenderer) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) UserConstants(org.olat.core.id.UserConstants) Map(java.util.Map) SortKey(org.olat.core.commons.persistence.SortKey) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) BaseSecurityModule(org.olat.basesecurity.BaseSecurityModule) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) FlexiTableDataModelFactory(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModelFactory) LectureModule(org.olat.modules.lecture.LectureModule) RateWarningCellRenderer(org.olat.modules.lecture.ui.component.RateWarningCellRenderer) WindowControl(org.olat.core.gui.control.WindowControl) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) ParticipantsCols(org.olat.modules.lecture.ui.ParticipantListDataModel.ParticipantsCols) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) ControllerCreator(org.olat.core.gui.control.creator.ControllerCreator) UserManager(org.olat.user.UserManager) BaseFullWebappPopupLayoutFactory(org.olat.core.commons.fullWebApp.popup.BaseFullWebappPopupLayoutFactory) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) LectureService(org.olat.modules.lecture.LectureService) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) List(java.util.List) Identity(org.olat.core.id.Identity) LongCellRenderer(org.olat.modules.lecture.ui.component.LongCellRenderer) FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Roles(org.olat.core.id.Roles) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics)

Example 4 with LectureBlockStatistics

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

the class LectureBlockRollCallDAO method aggregatedStatistics.

public AggregatedLectureBlocksStatistics aggregatedStatistics(List<? extends LectureBlockStatistics> statisticsList, boolean countAuthorizedAbsenceAsAttendant) {
    long totalPersonalPlannedLectures = 0;
    long totalAttendedLectures = 0;
    long totalAuthorizedAbsentLectures = 0;
    long totalAbsentLectures = 0;
    long attendedForRate = 0;
    long absentForRate = 0;
    for (LectureBlockStatistics statistics : statisticsList) {
        totalPersonalPlannedLectures += statistics.getTotalPersonalPlannedLectures();
        totalAuthorizedAbsentLectures += statistics.getTotalAuthorizedAbsentLectures();
        totalAttendedLectures += statistics.getTotalAttendedLectures();
        totalAbsentLectures += statistics.getTotalAbsentLectures();
        attendedForRate += statistics.getTotalAttendedLectures();
        absentForRate += statistics.getTotalAbsentLectures();
        if (countAuthorizedAbsenceAsAttendant) {
            attendedForRate += statistics.getTotalAuthorizedAbsentLectures();
        } else {
            absentForRate += statistics.getTotalAuthorizedAbsentLectures();
        }
    }
    long totalLectures = attendedForRate + absentForRate;
    double rate;
    if (totalLectures == 0 || attendedForRate == 0) {
        rate = 0.0d;
    } else {
        rate = (double) attendedForRate / (double) totalLectures;
    }
    double currentRate;
    if (attendedForRate == 0) {
        currentRate = 0.0d;
    } else {
        currentRate = attendedForRate / ((double) attendedForRate + (double) absentForRate);
    }
    return new AggregatedLectureBlocksStatistics(totalPersonalPlannedLectures, totalAttendedLectures, totalAuthorizedAbsentLectures, totalAbsentLectures, rate, currentRate);
}
Also used : AggregatedLectureBlocksStatistics(org.olat.modules.lecture.model.AggregatedLectureBlocksStatistics) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics)

Example 5 with LectureBlockStatistics

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

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)

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