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();
}
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations