use of org.olat.course.run.scoring.ScoreEvaluation in project openolat by klemens.
the class PassedRuleSPI method filter.
@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String nodeIdent = r.getLeftOperand();
String status = r.getRightOperand();
ICourse course = CourseFactory.loadCourse(entry);
CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
if (courseNode == null) {
identities.clear();
log.error("Passed rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
return;
}
Map<Long, Boolean> passeds;
if (courseNode instanceof STCourseNode) {
passeds = new HashMap<>();
STCourseNode structureNode = (STCourseNode) courseNode;
if (structureNode.hasPassedConfigured()) {
for (Identity identity : identities) {
UserCourseEnvironment uce = AssessmentHelper.createAndInitUserCourseEnvironment(identity, course);
ScoreEvaluation scoreEval = structureNode.getUserScoreEvaluation(uce);
Boolean passed = scoreEval.getPassed();
if (passed != null) {
passeds.put(identity.getKey(), passed);
}
}
}
} else {
passeds = helperDao.getPassed(entry, courseNode, identities);
}
if ("passed".equals(status)) {
for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
Boolean passed = passeds.get(identityIt.next().getKey());
if (passed == null || !passed.booleanValue()) {
identityIt.remove();
}
}
} else if ("failed".equals(status)) {
for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
Boolean passed = passeds.get(identityIt.next().getKey());
if (passed != null && passed.booleanValue()) {
identityIt.remove();
}
}
}
}
}
use of org.olat.course.run.scoring.ScoreEvaluation in project openolat by klemens.
the class ConvertToGTACourseNode method convertAssessmentDatas.
private void convertAssessmentDatas(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
CourseEnvironment courseEnv = course.getCourseEnvironment();
CoursePropertyManager propertyMgr = courseEnv.getCoursePropertyManager();
Map<Long, AssessmentEntry> datas = new HashMap<>();
List<AssessmentEntry> properties = courseEnv.getAssessmentManager().getAssessmentEntries(sourceNode);
for (AssessmentEntry property : properties) {
Identity identity = property.getIdentity();
datas.put(identity.getKey(), property);
}
properties = null;
DBFactory.getInstance().getCurrentEntityManager().clear();
AssessmentManager assessmentMgr = courseEnv.getAssessmentManager();
for (AssessmentEntry assessmentData : datas.values()) {
Identity assessedIdentity = securityManager.loadIdentityByKey(assessmentData.getIdentity().getKey());
if (assessmentData.getPassed() != null || assessmentData.getScore() != null) {
UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
Float score = assessmentData.getScore() == null ? null : assessmentData.getScore().floatValue();
ScoreEvaluation scoreEval = new ScoreEvaluation(score, assessmentData.getPassed());
assessmentMgr.saveScoreEvaluation(gtaNode, null, assessedIdentity, scoreEval, userCourseEnv, false, Role.auto);
// set graded
Task task = gtaManager.getTask(assessedIdentity, taskList);
if (task == null) {
gtaManager.createTask(null, taskList, TaskProcess.graded, null, assessedIdentity, gtaNode);
} else {
gtaManager.updateTask(task, TaskProcess.graded, gtaNode, Role.auto);
}
}
if (assessmentData.getAttempts() != null) {
assessmentMgr.saveNodeAttempts(gtaNode, null, assessedIdentity, assessmentData.getAttempts().intValue(), Role.auto);
}
if (StringHelper.containsNonWhitespace(assessmentData.getCoachComment())) {
assessmentMgr.saveNodeCoachComment(gtaNode, assessedIdentity, assessmentData.getCoachComment());
}
if (StringHelper.containsNonWhitespace(assessmentData.getComment())) {
assessmentMgr.saveNodeComment(gtaNode, null, assessedIdentity, assessmentData.getComment());
}
}
DBFactory.getInstance().getCurrentEntityManager().clear();
// copy log entries
List<Property> logEntries = propertyMgr.listCourseNodeProperties(sourceNode, null, null, UserNodeAuditManager.LOG_IDENTIFYER);
for (Property logEntry : logEntries) {
String logText = logEntry.getTextValue();
Identity identity = securityManager.loadIdentityByKey(logEntry.getIdentity().getKey());
Property targetProp = propertyMgr.findCourseNodeProperty(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER);
if (targetProp == null) {
targetProp = propertyMgr.createCourseNodePropertyInstance(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER, null, null, null, logText);
} else {
targetProp.setTextValue(logText);
}
propertyMgr.saveProperty(targetProp);
}
}
use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.
the class ReminderRuleEngineTest method score.
@Test
public void score() {
// create a course with 3 members and generate some datas
Identity tutor = JunitTestHelper.createAndPersistIdentityAsRndUser("score-tutor-1");
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-2");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-3");
RepositoryEntry re = JunitTestHelper.deployDemoCourse(id1);
repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(id2, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
dbInstance.commit();
String nodeIdent = assessmentData(tutor, id1, new ScoreEvaluation(1.0f, false), re);
assessmentData(tutor, id2, new ScoreEvaluation(5.0f, true), re);
assessmentData(tutor, id3, new ScoreEvaluation(10.0f, true), re);
List<Identity> identities = new ArrayList<>();
identities.add(id1);
identities.add(id2);
identities.add(id3);
{
// check score > 0.5
List<ReminderRule> rules = getScoreRules(">", 0.5f, nodeIdent);
List<Identity> all = new ArrayList<>(identities);
ruleEngine.filterByRules(re, all, rules);
Assert.assertEquals(3, all.size());
}
{
// check score > 20.0
List<ReminderRule> rules = getScoreRules(">", 20.0f, nodeIdent);
List<Identity> all = new ArrayList<>(identities);
ruleEngine.filterByRules(re, all, rules);
Assert.assertEquals(0, all.size());
}
}
use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.
the class ScormAPIMapper method calculateScorePassed.
private void calculateScorePassed(String olatSahsId, Properties scoProperties, boolean finish) {
// do a sum-of-scores over all sco scores
// <OLATEE-27>
float score = -1f;
// </OLATEE-27>
for (Iterator<Object> it_score = scoProperties.values().iterator(); it_score.hasNext(); ) {
// <OLATEE-27>
if (score < 0f) {
score = 0f;
}
// </OLATEE-27>
String aScore = (String) it_score.next();
float ascore = Float.parseFloat(aScore);
score += ascore;
}
float cutval = scormNode.getCutValueConfiguration().floatValue();
boolean passed = (score >= cutval);
// if advanceScore option is set update the score only if it is higher
// <OLATEE-27>
ModuleConfiguration config = scormNode.getModuleConfiguration();
if (config.getBooleanSafe(ScormEditController.CONFIG_ADVANCESCORE, true)) {
if (score > (currentScore != null ? currentScore : -1f)) {
// </OLATEE-27>
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
if (increment) {
attemptsIncremented = true;
}
} else if (!config.getBooleanSafe(ScormEditController.CONFIG_ATTEMPTSDEPENDONSCORE, false)) {
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = scormNode.getUserScoreEvaluation(userCourseEnv);
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
if (increment) {
attemptsIncremented = true;
}
}
} else {
// <OLATEE-27>
if (score < 0f) {
score = 0f;
}
// </OLATEE-27>
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, false, Role.user);
if (increment) {
attemptsIncremented = true;
}
}
if (log.isDebug()) {
String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId + " occured, total sum = " + score + ", cutvalue =" + cutval + ", passed: " + passed + ", all scores now = " + scoProperties.toString();
log.debug(msg, null);
}
}
use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.
the class ScormAPIMapper method calculatePassed.
private void calculatePassed(String olatSahsId, Properties lessonStatusProp, boolean finish) {
int found = 0;
boolean passedScos = true;
for (Iterator<Object> it_status = lessonStatusProp.values().iterator(); it_status.hasNext(); ) {
String status = (String) it_status.next();
passedScos &= "passed".equals(status);
found++;
}
boolean passed = (found == scormAdapter.getNumOfSCOs()) && passedScos;
// if advanceScore option is set update the score only if it is higher
// <OLATEE-27>
ModuleConfiguration config = scormNode.getModuleConfiguration();
if (config.getBooleanSafe(ScormEditController.CONFIG_ADVANCESCORE, true)) {
if (currentPassed == null || !currentPassed.booleanValue()) {
// </OLATEE-27>
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = new ScoreEvaluation(new Float(0.0f), Boolean.valueOf(passed));
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
if (increment) {
attemptsIncremented = true;
}
} else if (!config.getBooleanSafe(ScormEditController.CONFIG_ATTEMPTSDEPENDONSCORE, false)) {
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = scormNode.getUserScoreEvaluation(userCourseEnv);
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
if (increment) {
attemptsIncremented = true;
}
}
} else {
boolean increment = !attemptsIncremented && finish;
ScoreEvaluation sceval = new ScoreEvaluation(new Float(0.0f), Boolean.valueOf(passed));
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, false, Role.user);
if (increment) {
attemptsIncremented = true;
}
}
if (log.isDebug()) {
String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId + " occured, passed: " + passed + ", all lesson status now = " + lessonStatusProp.toString();
log.debug(msg, null);
}
}
Aggregations