use of org.olat.modules.assessment.AssessmentEntry in project OpenOLAT by OpenOLAT.
the class AssessmentEntryDAOTest method loadAssessmentEntryByGroup.
@Test
public void loadAssessmentEntryByGroup() {
// a simulated course with 2 groups
Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-16");
Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-17");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "assessment-bg-1", "assessment-bg-1-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, entry);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "assessment-bg-2", "assessment-bg-2-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group2, entry);
businessGroupRelationDao.addRole(assessedIdentity1, group1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(assessedIdentity2, group1, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// some assessment entries
String subIdent = UUID.randomUUID().toString();
AssessmentEntry nodeAssessmentId1 = assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry);
AssessmentEntry nodeAssessmentId2 = assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
AssessmentEntry nodeAssessmentId3 = assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, null, entry, 3.0f, Boolean.FALSE, null, null);
AssessmentEntry nodeAssessmentId4 = assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, refEntry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
dbInstance.commitAndCloseSession();
// load the assessment entries of entry
List<AssessmentEntry> assessmentEntries = assessmentEntryDao.loadAssessmentEntryByGroup(group1.getBaseGroup(), entry, subIdent);
Assert.assertNotNull(assessmentEntries);
Assert.assertEquals(2, assessmentEntries.size());
Assert.assertTrue(assessmentEntries.contains(nodeAssessmentId1));
Assert.assertTrue(assessmentEntries.contains(nodeAssessmentId2));
Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId3));
Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId4));
}
use of org.olat.modules.assessment.AssessmentEntry in project OpenOLAT by OpenOLAT.
the class HighScoreManager method sortRankByScore.
/**
* Sort rank by score, then by id and last alphabetically,
* determine rank of each member dependent on score,
* decide whether there is a second table or not
*/
public HighScoreRankingResults sortRankByScore(List<AssessmentEntry> assessEntries, List<HighScoreTableEntry> allMembers, List<HighScoreTableEntry> ownIdMembers, List<List<HighScoreTableEntry>> allPodium, List<Integer> ownIdIndices, int tableSize, Identity ownIdentity) {
HighScoreTableEntry ownTableEntry = null;
for (AssessmentEntry assessmentEntry : assessEntries) {
float score = assessmentEntry.getScore() == null ? 0f : assessmentEntry.getScore().floatValue();
HighScoreTableEntry tableEntry = new HighScoreTableEntry(score, userManager.getUserDisplayName(assessmentEntry.getIdentity()), assessmentEntry.getIdentity());
if (tableEntry.getIdentity().equals(ownIdentity)) {
ownTableEntry = tableEntry;
}
allMembers.add(tableEntry);
}
assessEntries.clear();
// 3 step comparator, sorts by score then own Identity comes first, last alphabetically
Collections.sort(allMembers, new HighscoreComparator(ownIdentity));
float buffer = -1;
int index = 0;
// int rank = 1;
double[] allScores = new double[allMembers.size()];
for (int j = 0; j < allMembers.size(); j++) {
HighScoreTableEntry member = allMembers.get(j);
if (member.getScore() < buffer) {
index++;
// rank = j + 1;
}
// first three position are put in separate lists, exclude zero scorers
if (index < 3 && member.getScore() > 0) {
allPodium.get(index).add(member);
}
// finding position rank for own id
if (member.getIdentity().equals(ownIdentity)) {
ownIdIndices.add(j);
}
// setting rank for each member
member.setRank(index + 1);
buffer = member.getScore();
// adding scores for histogram
allScores[j] = buffer;
}
// only getting member with own id for 2nd table
ownIdMembers.addAll(allMembers.stream().skip(tableSize).filter(a -> a.getIdentity().equals(ownIdentity)).collect(Collectors.toList()));
if (ownIdMembers.size() > 0) {
log.audit("2nd Highscore Table established");
}
return new HighScoreRankingResults(allScores, ownTableEntry);
}
use of org.olat.modules.assessment.AssessmentEntry in project OpenOLAT by OpenOLAT.
the class HighScoreRunController method setupContent.
private void setupContent(UserRequest ureq, UserCourseEnvironment userCourseEnv, CourseNode courseNode) {
// initialize ModuleConfiguration
ModuleConfiguration config = courseNode.getModuleConfiguration();
viewHighscore = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_HIGHSCORE);
// do not build form if high-score is not set
if (!viewHighscore) {
return;
}
Date start = config.getBooleanEntry(HighScoreEditController.CONFIG_KEY_DATESTART) != null ? (Date) config.get(HighScoreEditController.CONFIG_KEY_DATESTART) : null;
// display only if start time has been met
if (start != null && start.after(new Date())) {
viewHighscore = false;
return;
}
// guests will never see the highscore
if (ureq != null && ureq.getUserSession().getRoles().isGuestOnly()) {
viewHighscore = false;
return;
}
ownIdentity = userCourseEnv.getIdentityEnvironment().getIdentity();
AssessmentManager assessmentManager = userCourseEnv.getCourseEnvironment().getAssessmentManager();
AssessmentEntry ownEntry = assessmentManager.getAssessmentEntry(courseNode, ownIdentity);
// check user visibility
if (ownEntry != null && ownEntry.getUserVisibility() != null && !ownEntry.getUserVisibility().booleanValue()) {
viewHighscore = false;
return;
}
boolean adminORcoach = userCourseEnv.isAdmin() || userCourseEnv.isCoach();
// coaches or admin may see highscore, user only if already scored
if (!adminORcoach && (ownEntry == null || (ownEntry != null && ownEntry.getScore() == null))) {
viewHighscore = false;
return;
}
// ban zero scorer from viewing the highscore on STCourseNode
if (!adminORcoach && isSTCourseNode && ownEntry != null && ownEntry.getScore().equals(new BigDecimal(0))) {
viewHighscore = false;
return;
}
List<AssessmentEntry> assessEntries = assessmentManager.getAssessmentEntriesWithStatus(courseNode, null, isSTCourseNode);
// display only if has content
if (assessEntries == null || assessEntries.isEmpty()) {
viewHighscore = false;
return;
}
viewTable = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_LISTING);
viewHistogram = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_HISTOGRAM);
viewPosition = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_POSITION);
viewPodium = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_PODIUM);
anonymous = config.getBooleanSafe(HighScoreEditController.CONFIG_KEY_ANONYMIZE);
int bestOnly = config.getBooleanEntry(HighScoreEditController.CONFIG_KEY_BESTONLY) != null ? (int) config.get(HighScoreEditController.CONFIG_KEY_BESTONLY) : 0;
tableSize = bestOnly != 0 ? (int) config.get(HighScoreEditController.CONFIG_KEY_NUMUSER) : assessEntries.size();
initLists();
// get borders
lowerBorder = (Float) config.get(MSCourseNode.CONFIG_KEY_SCORE_MIN);
upperBorder = (Float) config.get(MSCourseNode.CONFIG_KEY_SCORE_MAX);
// compute ranking and order
highscoreDataModel = highScoreManager.sortRankByScore(assessEntries, allMembers, ownIdMembers, allPodium, ownIdIndices, tableSize, ownIdentity);
allScores = highscoreDataModel.getScores();
// init showConfig from user Prefs
doLoadShowConfig(ureq);
initForm(ureq);
}
use of org.olat.modules.assessment.AssessmentEntry in project OpenOLAT by OpenOLAT.
the class GTANotifications method createAssessmentItem.
private void createAssessmentItem(Task task, Identity assessedIdentity, boolean coach) {
if (task == null || task.getGraduationDate() == null)
return;
if (task.getGraduationDate().after(compareDate)) {
RepositoryEntry courseEntry = courseEnv.getCourseGroupManager().getCourseEntry();
AssessmentEntry assessment = courseNodeAssessmentDao.loadAssessmentEntry(assessedIdentity, courseEntry, gtaNode.getIdent());
boolean resultsVisible = assessment != null && (assessment.getUserVisibility() == null || assessment.getUserVisibility().booleanValue());
if (resultsVisible) {
String score = null;
String status = null;
if (gtaNode.hasScoreConfigured() && assessment.getScore() != null) {
score = AssessmentHelper.getRoundedScore(assessment.getScore());
}
if (gtaNode.hasPassedConfigured() && assessment.getPassed() != null) {
status = assessment.getPassed().booleanValue() ? translator.translate("notifications.assessment.passed.true") : translator.translate("notifications.assessment.passed.false");
}
Date graduationDate = task.getGraduationDate();
String[] params = new String[] { getTaskName(task), courseEntry.getDisplayname(), score, status };
if (score != null && status != null) {
if (assessment.getPassed().booleanValue()) {
appendSubscriptionItem("notifications.assessment.score.passed", params, assessedIdentity, graduationDate, coach);
} else {
appendSubscriptionItem("notifications.assessment.score.notpassed", params, assessedIdentity, graduationDate, coach);
}
} else if (score != null) {
appendSubscriptionItem("notifications.assessment.score", params, assessedIdentity, graduationDate, coach);
} else if (status != null) {
appendSubscriptionItem("notifications.assessment.passed", params, assessedIdentity, graduationDate, coach);
}
ICourse course = CourseFactory.loadCourse(courseEnv.getCourseGroupManager().getCourseEntry());
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
List<File> docs = gtaNode.getIndividualAssessmentDocuments(assessedUserCourseEnv);
for (File doc : docs) {
String[] docParams = new String[] { getTaskName(task), courseEntry.getDisplayname(), doc.getName() };
appendSubscriptionItemForFile("notifications.assessment.doc", docParams, assessedIdentity, "[assessment:0]", doc, graduationDate, coach);
}
}
}
}
use of org.olat.modules.assessment.AssessmentEntry in project OpenOLAT by OpenOLAT.
the class AssessmentServiceImpl method getOrCreateAssessmentEntry.
@Override
public AssessmentEntry getOrCreateAssessmentEntry(Identity assessedIdentity, String anonymousIdentifier, RepositoryEntry entry, String subIdent, RepositoryEntry referenceEntry) {
AssessmentEntry assessmentEntry = assessmentEntryDao.loadAssessmentEntry(assessedIdentity, anonymousIdentifier, entry, subIdent);
if (assessmentEntry == null) {
assessmentEntry = assessmentEntryDao.createAssessmentEntry(assessedIdentity, anonymousIdentifier, entry, subIdent, referenceEntry);
dbInstance.commit();
}
return assessmentEntry;
}
Aggregations